libpniio
dimensions.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 //
20 // Created on: Nov 27, 2014
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 #pragma once
24 
25 #include "node.hpp"
26 
27 namespace pni{
28 namespace io{
29 namespace nx{
30 namespace xml{
40  typedef std::pair<size_t,size_t> index_value_type;
41 
42  //------------------------------------------------------------------------
57  bool operator<(const index_value_type &lhs,
58  const index_value_type &rhs);
59 
60  //------------------------------------------------------------------------
68  class dimensions
69  {
70 
71  private:
72 
74  typedef std::vector<index_value_type> iv_vector;
75 
76  //----------------------------------------------------------------
87  static node index_value_to_node(size_t index,size_t value);
88 
89  //-----------------------------------------------------------------
99  static index_value_type index_value_from_node(const node &dim_node);
100 
101  public:
102  //-----------------------------------------------------------------
112  static size_t rank(const node &dim);
113 
114  //-----------------------------------------------------------------
126  static size_t size(const node &dim);
127 
128 
129  //-----------------------------------------------------------------
139  static pni::core::shape_t object_from_xml(const node &dims);
140 
141  //-----------------------------------------------------------------
154  template<typename DTYPE>
155  static DTYPE object_from_xml(const node &dims)
156  {
157  pni::core::shape_t s = object_from_xml(dims);
158  return DTYPE(s.begin(),s.end());
159  }
160 
161  //-----------------------------------------------------------------
171  static node object_to_xml(const pni::core::shape_t &s);
172 
173  //-----------------------------------------------------------------
184  template<typename DTYPE>
185  static node object_to_xml(const DTYPE &dim)
186  {
187  pni::core::shape_t s(dim.begin(),dim.end());
188  return object_to_xml(s);
189  }
190 
191  };
192 
193 
194 //end of namespace
195 }
196 }
197 }
198 }
std::vector< index_value_type > iv_vector
vector type to hold index-value pairs
Definition: dimensions.hpp:74
static size_t size(const node &dim)
get size of an object
Definition: dimensions.cpp:70
static node object_to_xml(const DTYPE &dim)
create dimension node
Definition: dimensions.hpp:185
static size_t rank(const node &dim)
get number of dimensions
Definition: dimensions.cpp:63
reading and writing dimensions
Definition: dimensions.hpp:68
static index_value_type index_value_from_node(const node &dim_node)
read dim information
Definition: dimensions.cpp:52
static DTYPE object_from_xml(const node &dims)
return shape
Definition: dimensions.hpp:155
static node index_value_to_node(size_t index, size_t value)
generate dim node
Definition: dimensions.cpp:42
static pni::core::shape_t object_from_xml(const node &dims)
return shape
Definition: dimensions.cpp:80
Definition: cbf_reader.hpp:41
boost::property_tree::ptree node
alias for ptree
Definition: node.hpp:39
bool operator<(const index_value_type &lhs, const index_value_type &rhs)
comparison operator for index_value_type
Definition: dimensions.cpp:36
static node object_to_xml(const pni::core::shape_t &s)
create dimension node
Definition: dimensions.cpp:105
std::pair< size_t, size_t > index_value_type
index-value type
Definition: dimensions.hpp:40