libpniio
get_class.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 //
20 // Created on: Jul 1, 2013
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 #pragma once
24 
25 #include <pni/core/types.hpp>
26 #include <pni/core/error.hpp>
27 #include "../nximp_code.hpp"
28 #include "../nxobject.hpp"
29 #include "../nxobject_traits.hpp"
30 
31 namespace pni{
32 namespace io{
33 namespace nx{
34 
52  template<
53  template<nximp_code> class OTYPE,
54  nximp_code IMPID
55  >
56  pni::core::string get_class(const OTYPE<IMPID> &group)
57  {
58  typedef nxobject_trait<IMPID> trait_type;
59  typedef typename trait_type::field_type field_type;
60  typedef typename trait_type::attribute_type attribute_type;
61  typedef OTYPE<IMPID> arg_type;
62 
63  static_assert(!(std::is_same<arg_type,field_type>::value ||
64  std::is_same<arg_type,attribute_type>::value),
65  "get_class CAN ONLY BE USED WITH GROUP TYPES");
66 
67  pni::core::string group_class;
68  if(group.attributes.exists("NX_class"))
69  group.attributes["NX_class"].read(group_class);
70 
71  return group_class;
72  }
73 
74 
75 
76  //------------------------------------------------------------------------
88  template<
89  typename GTYPE,
90  typename FTYPE,
91  typename ATYPE,
92  typename LTYPE
93  >
94  class get_class_visitor : public boost::static_visitor<pni::core::string>
95  {
96  public:
98  using result_type = pni::core::string;
100  using group_type = GTYPE;
102  using field_type = FTYPE;
104  using attribute_type = ATYPE;
106  using link_type = LTYPE;
107 
127  {
128  return get_class(g);
129  }
130 
131  //-----------------------------------------------------------------
144  {
145  using namespace pni::core;
146  throw type_error(EXCEPTION_RECORD,
147  "Fields do not have a class!");
148  return result_type();
149  }
150 
151  //-----------------------------------------------------------------
165  {
166  using namespace pni::core;
167  throw type_error(EXCEPTION_RECORD,
168  "Attributes do not have a class!");
169  return result_type();
170  }
171 
172  //----------------------------------------------------------------
183  {
184  using namespace pni::core;
185  throw type_error(EXCEPTION_RECORD,
186  "Links do not have a type!");
187  return result_type();
188  }
189  };
190 
211  template<
212  typename GTYPE,
213  typename FTYPE,
214  typename ATYPE,
215  typename LTYPE
216  >
217  pni::core::string get_class(const nxobject<GTYPE,FTYPE,ATYPE,LTYPE> &o)
218  {
219  using visitor_type = get_class_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
220  return boost::apply_visitor(visitor_type(),o);
221  }
222 
223 //end of namespace
224 }
225 }
226 }
result_type operator()(const field_type &) const
process fields
Definition: get_class.hpp:143
LTYPE link_type
NeXus link type.
Definition: get_class.hpp:106
pni::core::string result_type
result type
Definition: get_class.hpp:98
ATYPE attribute_type
Nexus attribute type.
Definition: get_class.hpp:104
Definition: cbf_reader.hpp:41
result_type operator()(const attribute_type &) const
process attributes
Definition: get_class.hpp:164
nximp_code
implementation codes
Definition: nximp_code.hpp:40
result_type operator()(const link_type &) const
process links
Definition: get_class.hpp:182
pni::core::string get_class(const OTYPE< IMPID > &group)
get the class of a group
Definition: get_class.hpp:56
result_type operator()(const group_type &g) const
process groups
Definition: get_class.hpp:126
get class visitor
Definition: get_class.hpp:94
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
FTYPE field_type
Nexus field type.
Definition: get_class.hpp:102
GTYPE group_type
Nexus group type.
Definition: get_class.hpp:100