libpniio
as_attribute.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_attribute_visitor : public boost::static_visitor<ATYPE>
50  {
51  public:
53  using group_type = GTYPE;
55  using field_type = FTYPE;
57  using attribute_type = ATYPE;
59  using link_type = LTYPE;
60 
63 
64  //-----------------------------------------------------------------
77  {
78  using namespace pni::core;
79  throw type_error(EXCEPTION_RECORD,
80  "Object is not an instance of nxattribute "
81  "but of s nxgroup!");
82  return result_type();
83  }
84 
85  //-----------------------------------------------------------------
98  {
99  using namespace pni::core;
100  throw type_error(EXCEPTION_RECORD,
101  "Object is not an instance of nxattribute "
102  "but of nxfield!");
103  return result_type();
104  }
105 
106  //-----------------------------------------------------------------
115  {
116  return a;
117  }
118 
119  //----------------------------------------------------------------
131  {
132  using namespace pni::core;
133  throw type_error(EXCEPTION_RECORD,
134  "Object is a link and not an instance of "
135  "nxattribute!");
136 
137  return result_type();
138  }
139  };
140 
149 
155  template<
165  typename GTYPE,
166  typename FTYPE,
167  typename ATYPE,
168  typename LTYPE
169  >
171  {
173  return boost::apply_visitor(visitor_type(),o);
174  }
175 
176 //end of namespace
177 }
178 }
179 }
result_type operator()(const attribute_type &a) const
process attribute instances
Definition: as_attribute.hpp:114
GTYPE group_type
Nexus group type.
Definition: as_attribute.hpp:53
result_type operator()(const field_type &) const
process field instances
Definition: as_attribute.hpp:97
result_type operator()(const link_type &) const
process link instances
Definition: as_attribute.hpp:130
LTYPE link_type
Nexus link type.
Definition: as_attribute.hpp:59
Definition: cbf_reader.hpp:41
ATYPE as_attribute(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &o)
as attribute wrapper
Definition: as_attribute.hpp:170
FTYPE field_type
Nexus field type.
Definition: as_attribute.hpp:55
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
attribute_type result_type
result type
Definition: as_attribute.hpp:62
ATYPE attribute_type
Nexus attribute type.
Definition: as_attribute.hpp:57
as attribute visitor
Definition: as_attribute.hpp:49
result_type operator()(const group_type &) const
process group instances
Definition: as_attribute.hpp:76