libpniio
is_class.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2014 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: May 29, 2014
20 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
21 //
22 #pragma once
23 
24 #include <pni/core/types.hpp>
25 #include <pni/core/error.hpp>
26 #include "../nxobject.hpp"
27 #include "../nxobject_traits.hpp"
28 #include "get_class.hpp"
29 
30 namespace pni{
31 namespace io{
32 namespace nx{
33 
54  template<
55  template<nximp_code> class OTYPE,
56  nximp_code IMPID
57  >
58  bool is_class(const OTYPE<IMPID> &object,const pni::core::string &type)
59  {
60  using group_type = typename nxobject_trait<IMPID>::group_type;
61 
62  static_assert(std::is_same<group_type,OTYPE<IMPID>>::value,
63  "The object must be a group type!");
64 
65  return get_class(object)==type;
66  }
67 
79  template<
80  typename GTYPE,
81  typename FTYPE,
82  typename ATYPE,
83  typename LTYPE
84  >
85  class is_class_visitor : public boost::static_visitor<bool>
86  {
87  private:
88  pni::core::string _class;
89  public:
91  using result_type = bool;
93  using group_type = GTYPE;
95  using field_type = FTYPE;
97  using attribute_type = ATYPE;
99  using link_type = LTYPE;
100 
101  //-----------------------------------------------------------------
107  is_class_visitor(const pni::core::string &s):_class(s) {}
108 
109  //-----------------------------------------------------------------
123  {
124  return is_class(g,_class);
125  }
126 
127  //-----------------------------------------------------------------
136  {
137  using namespace pni::core;
138  throw type_error(EXCEPTION_RECORD,
139  "Fields do not have a class!");
140  return false;
141  }
142 
143  //----------------------------------------------------------------
152  {
153  using namespace pni::core;
154  throw type_error(EXCEPTION_RECORD,
155  "Attributes do not have a class!");
156  return false;
157  }
158 
159  //----------------------------------------------------------------
168  {
169  using namespace pni::core;
170  throw type_error(EXCEPTION_RECORD,
171  "Links do not have a class!");
172  return false;
173  }
174  };
175 
198  template<
199  typename GTYPE,
200  typename FTYPE,
201  typename ATYPE,
202  typename LTYPE
203  >
205  const pni::core::string &c)
206  {
207  using visitor_type = is_class_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
208  return boost::apply_visitor(visitor_type(c),o);
209  }
210 
211 //end of namespace
212 }
213 }
214 }
result_type operator()(const group_type &g) const
process groups
Definition: is_class.hpp:122
ATYPE attribute_type
Nexus attribute type.
Definition: is_class.hpp:97
nexus object traits
Definition: nxobject_traits.hpp:44
is_class_visitor(const pni::core::string &s)
constructor
Definition: is_class.hpp:107
is class visitor
Definition: is_class.hpp:85
bool result_type
result type
Definition: is_class.hpp:91
Definition: cbf_reader.hpp:41
result_type operator()(const field_type &) const
process fields
Definition: is_class.hpp:135
result_type operator()(const link_type &) const
process links
Definition: is_class.hpp:167
pni::core::string _class
class type
Definition: is_class.hpp:88
nximp_code
implementation codes
Definition: nximp_code.hpp:40
FTYPE field_type
Nexus field type.
Definition: is_class.hpp:95
GTYPE group_type
Nexus group type.
Definition: is_class.hpp:93
pni::core::string get_class(const OTYPE< IMPID > &group)
get the class of a group
Definition: get_class.hpp:56
result_type operator()(const attribute_type &) const
process attributes
Definition: is_class.hpp:151
LTYPE link_type
NeXus link type.
Definition: is_class.hpp:99
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
bool is_class(const OTYPE< IMPID > &object, const pni::core::string &type)
checks group type
Definition: is_class.hpp:58