libpniio
get_shape.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 #include "../nxobject_traits.hpp"
27 
28 namespace pni{
29 namespace io{
30 namespace nx{
31 
41 
47  template<
60  typename CTYPE,
61  template<nximp_code> class OTYPE,
62  nximp_code IMPID
63  >
64  CTYPE get_shape(const OTYPE<IMPID> &object)
65  {
66  typedef OTYPE<IMPID> object_type;
67  typedef typename nxobject_trait<IMPID>::field_type field_type;
68  typedef typename nxobject_trait<IMPID>::attribute_type attribute_type;
69  typedef std::is_same<object_type,field_type> field_check_type;
70  typedef std::is_same<object_type,attribute_type> attribute_check_type;
71  static_assert(field_check_type::value || attribute_check_type::value,
72  "OBJECT MUST BE A FIELD OR ATTRIBUTE TYPE!");
73 
74  return object.template shape<CTYPE>();
75  }
76 
77  //------------------------------------------------------------------------
94  template<
95  typename CTYPE,
96  typename GTYPE,
97  typename FTYPE,
98  typename ATYPE,
99  typename LTYPE
100  >
101  class get_shape_visitor : public boost::static_visitor<CTYPE>
102  {
103  public:
105  using result_type = CTYPE;
107  using group_type = GTYPE;
109  using field_type = FTYPE;
111  using attribute_type = ATYPE;
113  using link_type = LTYPE;
114 
115  //-----------------------------------------------------------------
125  {
126  using namespace pni::core;
127  throw type_error(EXCEPTION_RECORD,
128  "A group does not have a shape!");
129  return CTYPE();
130  }
131 
132  //-----------------------------------------------------------------
145  {
146  return f.template shape<CTYPE>();
147  }
148 
149  //-----------------------------------------------------------------
162  {
163  return a.template shape<CTYPE>();
164  }
165 
166  //-----------------------------------------------------------------
175  {
176  using namespace pni::core;
177  throw type_error(EXCEPTION_RECORD,
178  "A link does not have a shape!");
179  return CTYPE();
180  }
181  };
182 
192 
198  template<
211  typename CTYPE,
212  typename GTYPE,
213  typename FTYPE,
214  typename ATYPE,
215  typename LTYPE
216  >
218  {
220 
221  return boost::apply_visitor(visitor_type(),o);
222  }
223 
224 //end of namespace
225 }
226 }
227 }
ATYPE attribute_type
Nexus attribute type.
Definition: get_shape.hpp:111
GTYPE group_type
Nexus group type.
Definition: get_shape.hpp:107
result_type operator()(const attribute_type &a) const
process attribute instances
Definition: get_shape.hpp:161
result_type operator()(const field_type &f) const
process field instances
Definition: get_shape.hpp:144
result_type operator()(const link_type &) const
process nxlink instances
Definition: get_shape.hpp:174
nexus object traits
Definition: nxobject_traits.hpp:44
FTYPE field_type
Nexus field type.
Definition: get_shape.hpp:109
Definition: cbf_reader.hpp:41
nximp_code
implementation codes
Definition: nximp_code.hpp:40
CTYPE get_shape(const OTYPE< IMPID > &object)
get shape
Definition: get_shape.hpp:64
result_type operator()(const group_type &) const
process group instances
Definition: get_shape.hpp:124
CTYPE result_type
result type
Definition: get_shape.hpp:105
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
LTYPE link_type
Nexus link type.
Definition: get_shape.hpp:113
get shape visitor
Definition: get_shape.hpp:101