libpniio
io_node.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 
27 #include "node.hpp"
28 #include "data_node.hpp"
29 #include "../../parsers.hpp"
30 #include "../../formatters.hpp"
31 
32 namespace pni{
33 namespace io{
34 namespace nx{
35 namespace xml{
36 
43  struct io_node
44  {
45  //--------------------------------------------------------------------
59  static size_t size(const node &io_node);
60 
61  //--------------------------------------------------------------------
74  static size_t rank(const node &io_node);
75 
76  //--------------------------------------------------------------------
87  static pni::core::string name(const node &io_node);
88 
89  //--------------------------------------------------------------------
97  static pni::core::shape_t shape(const node &io_node);
98 
99  //--------------------------------------------------------------------
111  static pni::core::type_id_t type_id(const node &io_node);
112 
113  //--------------------------------------------------------------------
128  template<typename T>
129  static T data_from_xml(const node &io_node)
130  {
132 
133  return p(data_node::read(io_node));
134  }
135 
136  //--------------------------------------------------------------------
146  template<typename T>
147  static void data_to_xml(node &io_node,const T &value)
148  {
149  typedef formatter<T> formatter_type;
150  formatter_type f;
151  io_node.put_value(f(value));
152  }
153 
154  };
155 
156 //end of namespace
157 }
158 }
159 }
160 }
161 
parser for primitive types
Definition: parsers/parser.hpp:62
scalar formatter
Definition: formatter.hpp:55
static pni::core::type_id_t type_id(const node &io_node)
get type id
Definition: io_node.cpp:72
static T data_from_xml(const node &io_node)
get data from XML
Definition: io_node.hpp:129
Definition: cbf_reader.hpp:41
static size_t size(const node &io_node)
return object size
Definition: io_node.cpp:34
boost::property_tree::ptree node
alias for ptree
Definition: node.hpp:39
static void data_to_xml(node &io_node, const T &value)
write data to XML
Definition: io_node.hpp:147
static pni::core::string read(const node &n)
read data from node
Definition: data_node.cpp:34
static pni::core::string name(const node &io_node)
return object name
Definition: io_node.cpp:54
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
general IO objects
Definition: io_node.hpp:43