libpniio
get_rank.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 
47  template<
48  template<nximp_code> class OTYPE,
49  nximp_code IMPID
50  >
51  size_t get_rank(const OTYPE<IMPID> &o)
52  {
53  typedef nxobject_trait<IMPID> trait_type;
54  typedef typename trait_type::field_type field_type;
55  typedef typename trait_type::attribute_type attribute_type;
56 
57  static_assert(std::is_same<field_type,OTYPE<IMPID>>::value ||
58  std::is_same<attribute_type,OTYPE<IMPID>>::value,
59  "THE RANK CAN ONLY BE OBTAINED FROM FIELDS AND"
60  " ATTRIBUTE!");
61 
62  return o.rank();
63  }
64 
65  //------------------------------------------------------------------------
75  template<
76  typename GTYPE,
77  typename FTYPE,
78  typename ATYPE,
79  typename LTYPE
80  >
81  class get_rank_visitor : public boost::static_visitor<size_t>
82  {
83  public:
85  using result_type = size_t;
87  using group_type = GTYPE;
89  using field_type = FTYPE;
91  using attribute_type = ATYPE;
93  using link_type = LTYPE;
94 
95  //-----------------------------------------------------------------
106  {
107  using namespace pni::core;
108  throw type_error(EXCEPTION_RECORD,
109  "Groups do not have a shape!");
110  return size_t(0);
111  }
112 
113  //-----------------------------------------------------------------
126  {
127  return get_rank(f);
128  }
129 
130  //-----------------------------------------------------------------
143  {
144  return a.rank();
145  }
146 
147  //-----------------------------------------------------------------
156  {
157  using namespace pni::core;
158  throw type_error(EXCEPTION_RECORD,"Links do not have a rank!");
159  return size_t(0);
160  }
161  };
162 
163  //------------------------------------------------------------------------
171 
177  template<
191  typename GTYPE,
192  typename FTYPE,
193  typename ATYPE,
194  typename LTYPE
195  >
197  {
198  using visitor_type = get_rank_visitor<GTYPE,FTYPE,ATYPE,LTYPE>;
199  return boost::apply_visitor(visitor_type(),o);
200  }
201 
202 //end of namespace
203 }
204 }
205 }
GTYPE group_type
Nexus group type.
Definition: get_rank.hpp:87
get rank visitor
Definition: get_rank.hpp:81
Definition: cbf_reader.hpp:41
result_type operator()(const link_type &) const
process nxlink instances
Definition: get_rank.hpp:155
LTYPE link_type
NeXus link type.
Definition: get_rank.hpp:93
nximp_code
implementation codes
Definition: nximp_code.hpp:40
result_type operator()(const field_type &f) const
process field instances
Definition: get_rank.hpp:125
size_t get_rank(const OTYPE< IMPID > &o)
get rank
Definition: get_rank.hpp:51
result_type operator()(const group_type &) const
process group instances
Definition: get_rank.hpp:105
FTYPE field_type
Nexus field type.
Definition: get_rank.hpp:89
ATYPE attribute_type
Nexus attribute type.
Definition: get_rank.hpp:91
size_t result_type
result type
Definition: get_rank.hpp:85
result_type operator()(const attribute_type &a) const
process attribute instances
Definition: get_rank.hpp:142
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp:44