libpniio
iterators.hpp
Go to the documentation of this file.
1 //
2 // (c) Copyright 2014 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: Sep 12, 2014
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 
32  //------------------------------------------------------------------------
42  template<
43  template<nximp_code> class OTYPE,
44  nximp_code IMPID
45  >
46  auto begin(const OTYPE<IMPID> &group) -> decltype(group.begin())
47  {
48  using group_type = typename nxobject_trait<IMPID>::group_type;
49  static_assert(std::is_same<group_type,OTYPE<IMPID>>::value,
50  "Object must be a group type!");
51 
52  return group.begin();
53  }
54 
55  //------------------------------------------------------------------------
65  template<
66  template<nximp_code> class OTYPE,
67  nximp_code IMPID
68  >
69  auto end(const OTYPE<IMPID> &group) -> decltype(group.end())
70  {
71  using group_type = typename nxobject_trait<IMPID>::group_type;
72  static_assert(std::is_same<group_type,OTYPE<IMPID>>::value,
73  "Object must be a group type!");
74 
75  return group.end();
76  }
77 
78  //------------------------------------------------------------------------
92  template<
93  typename GTYPE,
94  typename FTYPE,
95  typename ATYPE,
96  typename LTYPE
97  >
98  class begin_visitor : public boost::static_visitor<typename GTYPE::iterator>
99  {
100  public:
102  using result_type = typename GTYPE::iterator;
104  using group_type = GTYPE;
106  using field_type = FTYPE;
108  using attribute_type = ATYPE;
110  using link_type = LTYPE;
111 
112  //-----------------------------------------------------------------
117  {
118  return begin(g);
119  }
120 
121  //-----------------------------------------------------------------
133  {
134  using namespace pni::core;
135  throw type_error(EXCEPTION_RECORD,
136  "Fields do not have children!");
137  }
138 
139  //-----------------------------------------------------------------
150  {
151  using namespace pni::core;
152  throw type_error(EXCEPTION_RECORD,
153  "Attributes do not have children!");
154 
155  }
156 
157  //-----------------------------------------------------------------
166  {
167  using namespace pni::core;
168  throw type_error(EXCEPTION_RECORD,
169  "links do not have children!");
170 
171  }
172  };
173 
174  //========================================================================
192  template<
193  typename GTYPE,
194  typename FTYPE,
195  typename ATYPE,
196  typename LTYPE
197  >
198  typename GTYPE::iterator
200  {
201  using visitor_type = begin_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
202  return boost::apply_visitor(visitor_type(),o);
203  }
204 
205 
206  //------------------------------------------------------------------------
220  template<
221  typename GTYPE,
222  typename FTYPE,
223  typename ATYPE,
224  typename LTYPE
225  >
226  class end_visitor : public boost::static_visitor<typename GTYPE::iterator>
227  {
228  public:
230  using result_type = typename GTYPE::iterator;
232  using group_type = GTYPE;
234  using field_type = FTYPE;
236  using attribute_type = ATYPE;
238  using link_type = LTYPE;
239 
240  //-----------------------------------------------------------------
245  {
246  return end(g);
247  }
248 
249  //-----------------------------------------------------------------
259  {
260  using namespace pni::core;
261  throw type_error(EXCEPTION_RECORD,
262  "Fields do not have children!");
263  }
264 
265  //-----------------------------------------------------------------
274  {
275  using namespace pni::core;
276  throw type_error(EXCEPTION_RECORD,
277  "Attributes do not have children!");
278 
279  }
280 
281  //-----------------------------------------------------------------
288  {
289  using namespace pni::core;
290  throw type_error(EXCEPTION_RECORD,
291  "Links do not have children!");
292 
293  }
294  };
295 
313  template<
314  typename GTYPE,
315  typename FTYPE,
316  typename ATYPE,
317  typename LTYPE
318  >
319  typename GTYPE::iterator
321  {
322  using visitor_type = end_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
323  return boost::apply_visitor(visitor_type(),o);
324  }
325 //end of namespace
326 }
327 }
328 }
329 
330 
331 
332 
FTYPE field_type
Nexus field type.
Definition: iterators.hpp:234
ATYPE attribute_type
Nexus attribute type.
Definition: iterators.hpp:108
GTYPE group_type
Nexus group type.
Definition: iterators.hpp:232
result_type operator()(const field_type &) const
process fields
Definition: iterators.hpp:258
GTYPE group_type
Nexus group type.
Definition: iterators.hpp:104
result_type operator()(const link_type &) const
process links
Definition: iterators.hpp:165
result_type operator()(const group_type &g) const
process groups
Definition: iterators.hpp:244
ATYPE attribute_type
Nexus attribute type.
Definition: iterators.hpp:236
nexus object traits
Definition: nxobject_traits.hpp:44
FTYPE field_type
Nexus field type.
Definition: iterators.hpp:106
result_type operator()(const group_type &g) const
process groups
Definition: iterators.hpp:116
Definition: cbf_reader.hpp:41
auto begin(const OTYPE< IMPID > &group) -> decltype(group.begin())
get iterator to first element
Definition: iterators.hpp:46
LTYPE link_type
NeXus link type.
Definition: iterators.hpp:110
nximp_code
implementation codes
Definition: nximp_code.hpp:40
typename GTYPE::iterator result_type
result type
Definition: iterators.hpp:230
result_type operator()(const attribute_type &) const
process attributes
Definition: iterators.hpp:273
auto end(const OTYPE< IMPID > &group) -> decltype(group.end())
get iterator to last element
Definition: iterators.hpp:69
result_type operator()(const attribute_type &) const
process attributes
Definition: iterators.hpp:149
result_type operator()(const link_type &) const
process links
Definition: iterators.hpp:287
result_type operator()(const field_type &) const
process fields
Definition: iterators.hpp:132
typename GTYPE::iterator result_type
result type
Definition: iterators.hpp:102
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44
get iterator to last element
Definition: iterators.hpp:226
LTYPE link_type
NeXus link type.
Definition: iterators.hpp:238
get iterator to first element
Definition: iterators.hpp:98