libpniio
as_link.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2016 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: Mar 7, 2016
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_link_visitor : public boost::static_visitor<LTYPE>
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  //-----------------------------------------------------------------
76  {
77  using namespace pni::core;
78  throw type_error(EXCEPTION_RECORD,
79  "Object is not an instance of nxlink "
80  "but of nxgroup!");
81  return result_type();
82  }
83 
84  //-----------------------------------------------------------------
97  {
98  using namespace pni::core;
99  throw type_error(EXCEPTION_RECORD,
100  "Object is not an instance of nxattribute "
101  "but of nxfield!");
102  return result_type();
103  }
104 
105  //-----------------------------------------------------------------
114  {
115  using namespace pni::core;
116  throw type_error(EXCEPTION_RECORD,
117  "Object is an attribute and not an instance of "
118  "nxlink!");
119 
120  return result_type();
121  }
122 
123  //----------------------------------------------------------------
133  {
134  return l;
135  }
136  };
137 
146 
152  template<
163  typename GTYPE,
164  typename FTYPE,
165  typename ATYPE,
166  typename LTYPE
167  >
169  {
170  using visitor_type = as_link_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
171  return boost::apply_visitor(visitor_type(),o);
172  }
173 
174 //end of namespace
175 }
176 }
177 }
Definition: cbf_reader.hpp:41
LTYPE as_link(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &o)
as link wrapper
Definition: as_link.hpp:168
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44