libpniio
attribute.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 
24 #pragma once
25 
26 #include <pni/core/types.hpp>
27 
28 #include "../algorithms/create_attribute.hpp"
29 #include "../algorithms/get_type.hpp"
30 #include "../algorithms/get_name.hpp"
31 #include "../algorithms/get_shape.hpp"
32 #include "../algorithms/get_size.hpp"
33 #include "../nxobject.hpp"
34 #include "node.hpp"
35 #include "dimensions.hpp"
36 #include "io_node.hpp"
37 
38 
39 namespace pni{
40 namespace io{
41 namespace nx{
42 namespace xml{
43 
48  struct attribute : public io_node
49  {
68  template<
69  typename GTYPE,
70  typename FTYPE,
71  typename ATYPE,
72  typename LTYPE
73  >
76  const node &attr_node)
77  {
78  //create the attribute object
79  return create_attribute(parent,type_id(attr_node),
80  name(attr_node),
81  shape(attr_node));
82  }
83 
84  //-----------------------------------------------------------------
95  template<
96  typename GTYPE,
97  typename FTYPE,
98  typename ATYPE,
99  typename LTYPE
100  >
102  {
103  node attr_node;
104 
105  //write name and type attributes
106  attr_node.put("<xmlattr>.name",get_name(attr));
107  attr_node.put("<xmlattr>.type",pni::core::str_from_type_id(get_type(attr)));
108 
109  //if the attribute has more than one element we have to add its
110  //shape - otherwise the attribute is scalar
111  if(get_size(attr)>1)
112  {
113  auto shape = get_shape<pni::core::shape_t>(attr);
114  attr_node.add_child("dimensions",
116  }
117 
118  return attr_node;
119  }
120 
121 
122  };
123 
124 //end of namespace
125 }
126 }
127 }
128 }
size_t get_size(const OTYPE< IMPID > &o)
get number of elements
Definition: get_size.hpp:61
pni::core::string get_name(const node &n)
get name of a node
Definition: node.cpp:138
static pni::core::type_id_t type_id(const node &io_node)
get type id
Definition: io_node.cpp:72
Definition: cbf_reader.hpp:41
boost::property_tree::ptree node
alias for ptree
Definition: node.hpp:39
static nxobject< GTYPE, FTYPE, ATYPE, LTYPE > object_from_xml(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &parent, const node &attr_node)
create attribute from XML description
Definition: attribute.hpp:75
nxobject< GTYPE, FTYPE, ATYPE, LTYPE > create_attribute(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &parent, const pni::core::string &name, const STYPE &shape, bool overwrite=false)
create multidimensional attribute
Definition: create_attribute.hpp:215
static node object_to_xml(const nxobject< GTYPE, FTYPE, ATYPE, LTYPE > &attr)
write attribute to XML
Definition: attribute.hpp:101
static node object_to_xml(const pni::core::shape_t &s)
create dimension node
Definition: dimensions.cpp:105
static pni::core::string name(const node &io_node)
return object name
Definition: io_node.cpp:54
read and write attributes
Definition: attribute.hpp:48
pni::core::type_id_t get_type(const OTYPE< IMPID > &o)
get type
Definition: get_type.hpp:55
boost::variant< GTYPE, FTYPE, ATYPE, LTYPE > nxobject
Definition: nxobject.hpp: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