libpniio
as_field.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_field_visitor : public boost::static_visitor<FTYPE>
50  {
51  public:
53  using field_type = FTYPE;
55  using group_type = GTYPE;
57  using attribute_type = ATYPE;
59  using link_type = LTYPE;
62 
63  //-----------------------------------------------------------------
75  {
76  using namespace pni::core;
77  throw type_error(EXCEPTION_RECORD,
78  "Object is not an instance of nxfield, "
79  "but of nxgroup!");
80  return field_type();
81  }
82 
83  //-----------------------------------------------------------------
93  {
94  return f;
95  }
96 
97  //-----------------------------------------------------------------
109  {
110  using namespace pni::core;
111  throw type_error(EXCEPTION_RECORD,
112  "Object is not an instance of nxfield, "
113  "but of nxattribute!");
114  return field_type();
115  }
116 
117  //----------------------------------------------------------------
129  {
130  using namespace pni::core;
131  throw type_error(EXCEPTION_RECORD,
132  "Object is not an instance of nxfield but of "
133  "link!");
134  return result_type();
135  }
136  };
137 
145 
151  template<
161  typename GTYPE,
162  typename FTYPE,
163  typename ATYPE,
164  typename LTYPE
165  >
167  {
168  using visitor_type = as_field_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
169  return boost::apply_visitor(visitor_type(),o);
170  }
171 
172 //end of namespace
173 }
174 }
175 }
result_type operator()(const link_type &) const
process link instances
Definition: as_field.hpp:128
result_type operator()(const attribute_type &) const
process attribute instances
Definition: as_field.hpp:108
GTYPE group_type
group type
Definition: as_field.hpp:55
LTYPE link_type
link type
Definition: as_field.hpp:59
Definition: cbf_reader.hpp:41
FTYPE field_type
field type
Definition: as_field.hpp:53
FTYPE as_field(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &o)
as field wrapper
Definition: as_field.hpp:166
ATYPE attribute_type
attribute type
Definition: as_field.hpp:57
field_type result_type
result type of the visitor
Definition: as_field.hpp:61
result_type operator()(const field_type &f) const
process field instances
Definition: as_field.hpp:92
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
result_type operator()(const group_type &) const
process group instances
Definition: as_field.hpp:74
as field visitor
Definition: as_field.hpp:49