libpniio
as_group.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2013 DESY, Eugen Wintersberger <eugen.wintersberger@desy.de>
3 //
4 // This file is part of libpniio.
5 //
6 // libpniio is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // libpniio is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with libpniio. If not, see <http://www.gnu.org/licenses/>.
18 // ===========================================================================
19 // Created on: Jul 3, 2013
20 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
21 //
22 #pragma once
23 
24 #include <pni/core/error.hpp>
25 #include "../nxobject.hpp"
26 
27 namespace pni{
28 namespace io{
29 namespace nx{
30 
31 
43  template<
44  typename GTYPE,
45  typename FTYPE,
46  typename ATYPE,
47  typename LTYPE
48  >
49  class as_group_visitor : public boost::static_visitor<GTYPE>
50  {
51  public:
53  using group_type = GTYPE;
55  using field_type = FTYPE;
57  using attribute_type = ATYPE;
59  using link_type = LTYPE;
62 
63  //-----------------------------------------------------------------
73  {
74  return g;
75  }
76 
77  //-----------------------------------------------------------------
89  {
90  using namespace pni::core;
91  throw type_error(EXCEPTION_RECORD,
92  "Object is not an instance of nxgruop "
93  "but of nxfield!");
94  return result_type();
95  }
96 
97  //-----------------------------------------------------------------
109  {
110  using namespace pni::core;
111  throw type_error(EXCEPTION_RECORD,
112  "Object is not an instance of nxgroup "
113  "but of nxattribute!");
114  return result_type();
115  }
116 
117  //----------------------------------------------------------------
129  {
130  using namespace pni::core;
131  throw type_error(EXCEPTION_RECORD,
132  "Object is not an instance of nxgroup but of "
133  "link!");
134  return result_type();
135  }
136  };
137 
146 
152  template<
162  typename GTYPE,
163  typename FTYPE,
164  typename ATYPE,
165  typename LTYPE
166  >
168  {
169  using visitor_type = as_group_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
170  return boost::apply_visitor(visitor_type(),o);
171  }
172 
173 //end of namespace
174 }
175 }
176 }
result_type operator()(const field_type &) const
process field instances
Definition: as_group.hpp:88
ATYPE attribute_type
Nexus attribute type.
Definition: as_group.hpp:57
result_type operator()(const attribute_type &) const
process attribute instances
Definition: as_group.hpp:108
FTYPE field_type
Nexus field type.
Definition: as_group.hpp:55
Definition: cbf_reader.hpp:41
result_type operator()(const link_type &) const
process link instances
Definition: as_group.hpp:128
GTYPE group_type
Nexus group type.
Definition: as_group.hpp:53
result_type operator()(const group_type &g) const
process group instances
Definition: as_group.hpp:72
GTYPE as_group(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &o)
as group wrapper
Definition: as_group.hpp:167
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
group_type result_type
result type
Definition: as_group.hpp:61
as group visitor
Definition: as_group.hpp:49
LTYPE link_type
link type
Definition: as_group.hpp:59