libpniio
array_utils.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 28, 2014
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 #pragma once
24 
25 #include <pni/core/types.hpp>
26 #include <pni/core/error.hpp>
27 #include <pni/core/type_erasures.hpp>
28 
29 #include "node.hpp"
30 #include "io_node.hpp"
31 
32 namespace pni{
33 namespace io{
34 namespace nx{
35 namespace xml{
36 
49  template<typename ATYPE> ATYPE make_array(const node &data)
50  {
51  typedef typename ATYPE::storage_type storage_type;
52  pni::core::shape_t shape;
53 
54  //determine the shape of the array
55  if(io_node::rank(data)==0)
56  shape = pni::core::shape_t{1};
57  else
58  shape = io_node::shape(data);
59 
60  //read the daata
61  auto buffer = io_node::data_from_xml<storage_type>(data);
62 
63  return ATYPE::create(std::move(shape),std::move(buffer));
64  }
65 
66  //------------------------------------------------------------------------
79  template<> pni::core::array make_array(const node &data);
80 
81 
82 
83 //end of namespace
84 }
85 }
86 }
87 }
Definition: cbf_reader.hpp:41
boost::property_tree::ptree node
alias for ptree
Definition: node.hpp:39
ATYPE make_array(const node &data)
generate an array
Definition: array_utils.hpp:49
static size_t rank(const node &io_node)
return object rank
Definition: io_node.cpp:44
static pni::core::shape_t shape(const node &io_node)
return object shape
Definition: io_node.cpp:61