libpniio
grow.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 5, 2013
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 
29 namespace pni{
30 namespace io{
31 namespace nx{
32 
48  template<
49  template<nximp_code> class OTYPE,
50  nximp_code IMPID
51  >
52  void grow(OTYPE<IMPID> &o,size_t dimension=0,size_t extend=1)
53  {
54  using field_type = typename nxobject_trait<IMPID>::field_type;
55 
56  static_assert(std::is_same<field_type,OTYPE<IMPID>>::value,
57  "Growing requires a field type!");
58 
59  o.grow(dimension,extend);
60  }
61 
62  //------------------------------------------------------------------------
72  template<
73  typename GTYPE,
74  typename FTYPE,
75  typename ATYPE,
76  typename LTYPE
77  >
78  class grow_visitor : public boost::static_visitor<void>
79  {
80  private:
82  size_t _dim;
84  size_t _extent;
85  public:
87  using result_type = void;
89  using group_type = GTYPE;
91  using field_type = FTYPE;
93  using attribute_type = ATYPE;
95  using link_type = LTYPE;
96 
97  //-----------------------------------------------------------------
104  grow_visitor(size_t d,size_t e):
105  _dim(d),
106  _extent(e)
107  {}
108 
109  //-----------------------------------------------------------------
119  {
120  using namespace pni::core;
121  throw type_error(EXCEPTION_RECORD,
122  "One cannot grow a group object!");
123  }
124 
125  //-----------------------------------------------------------------
139  {
140  f.grow(_dim,_extent);
141  }
142 
143  //-----------------------------------------------------------------
153  {
154  using namespace pni::core;
155  throw type_error(EXCEPTION_RECORD,
156  "An attribute cannot be grown!");
157  }
158 
159  //-----------------------------------------------------------------
166  {
167  using namespace pni::core;
168  throw type_error(EXCEPTION_RECORD,
169  "A link cannot be grown!");
170  }
171  };
172 
173  //------------------------------------------------------------------------
178 
184  template<
201  typename GTYPE,
202  typename FTYPE,
203  typename ATYPE,
204  typename LTYPE
205  >
206  void grow(nxobject<GTYPE,FTYPE,ATYPE,LTYPE> &o,size_t d=0,size_t e=1)
207  {
208  using visitor_type = grow_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
209  return boost::apply_visitor(visitor_type(d,e),o);
210  }
211 
212 //end of namespace
213 }
214 }
215 }
ATYPE attribute_type
Nexus attribute type.
Definition: grow.hpp:93
nexus object traits
Definition: nxobject_traits.hpp:44
GTYPE group_type
Nexus group type.
Definition: grow.hpp:89
grow visitor
Definition: grow.hpp:78
size_t _dim
the index of the dimension along which to grow
Definition: grow.hpp:82
result_type operator()(field_type &f) const
process field instances
Definition: grow.hpp:138
Definition: cbf_reader.hpp:41
result_type operator()(const attribute_type &) const
process attribute instances
Definition: grow.hpp:152
nximp_code
implementation codes
Definition: nximp_code.hpp:40
result_type operator()(const group_type &) const
process group instances
Definition: grow.hpp:118
LTYPE link_type
NeXus link type.
Definition: grow.hpp:95
FTYPE field_type
Nexus field type.
Definition: grow.hpp:91
result_type operator()(const link_type &) const
process link instances
Definition: grow.hpp:165
grow_visitor(size_t d, size_t e)
constructor
Definition: grow.hpp:104
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
void result_type
result type
Definition: grow.hpp:87
void grow(OTYPE< IMPID > &o, size_t dimension=0, size_t extend=1)
grow a field
Definition: grow.hpp:52
size_t _extent
the number of elements to grow along the desired dimension
Definition: grow.hpp:84