libpniio
nxattribute_manager.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: Jul 8, 2014
21 // Author: Eugen Wintersberger <eugen.wintersberger@desy.de>
22 //
23 #pragma once
24 
25 #include <pni/core/utilities.hpp>
26 #include "nxattribute.hpp"
27 #include "../exceptions.hpp"
28 
29 namespace pni{
30 namespace io{
31 namespace nx{
32 
41  template<typename OTYPE>
43  {
44  public:
48  typedef typename OTYPE::attribute_type attribute_type;
50  typedef attribute_type value_type;
52  typedef pni::core::container_iterator<const manager_type> iterator;
54  typedef typename OTYPE::imp_type imp_type;
55  private:
57  typedef typename OTYPE::type_type type_imp;
59  imp_type &_imp;
60  public:
66  nxattribute_manager(imp_type &imp):_imp(imp) {}
67 
68  //----------------------------------------------------------------
86  template<
87  typename T,
88  typename CTYPE
89  >
90  attribute_type create(const pni::core::string &n,
91  const CTYPE &s,bool ov=false) const
92  {
93  pni::core::type_id_t tid = pni::core::type_id_map<T>::type_id;
94 
95  return attribute_type(_imp.attr(n,
96  tid,
97  type_imp::to_index_vector(s),
98  ov));
99  }
100 
101  //-----------------------------------------------------------------
118  template<typename T>
119  attribute_type create(const pni::core::string &n,
120  bool ov=false) const
121  {
122  return create<T>(n,pni::core::shape_t{1},ov);
123  }
124 
125  //-----------------------------------------------------------------
141  attribute_type operator[](const pni::core::string &n) const
142  {
143  return attribute_type(_imp.attr(n));
144  }
145 
146  //-----------------------------------------------------------------
162  attribute_type operator[](size_t i) const
163  {
164  return attribute_type(_imp.attr(i));
165  }
166 
167  //-----------------------------------------------------------------
179  void remove(const pni::core::string &n) const
180  {
181  _imp.del_attr(n);
182  }
183 
184  //-----------------------------------------------------------------
197  bool exists(const pni::core::string &n) const
198  {
199  return _imp.has_attr(n);
200  }
201 
202  //-----------------------------------------------------------------
213  size_t size() const { return _imp.nattr(); }
214 
215  //-----------------------------------------------------------------
224  iterator begin() const { return iterator(this); }
225 
226  //-----------------------------------------------------------------
235  iterator end() const { return iterator(this,size()); }
236  };
237 
238 
239 //end of namespace
240 }
241 }
242 }
attribute manager template
Definition: nxattribute_manager.hpp:42
attribute_type operator[](size_t i) const
open an attribute by index
Definition: nxattribute_manager.hpp:162
nxattribute_manager< OTYPE > manager_type
self-reference to this manager type
Definition: nxattribute_manager.hpp:46
attribute_type operator[](const pni::core::string &n) const
open an existing attribute by name
Definition: nxattribute_manager.hpp:141
nxattribute_manager(imp_type &imp)
constructor
Definition: nxattribute_manager.hpp:66
bool exists(const pni::core::string &n) const
checks for attribute existance
Definition: nxattribute_manager.hpp:197
attribute_type value_type
alias to the attribute type
Definition: nxattribute_manager.hpp:50
pni::core::type_id_t type_id(const h5datatype &o)
get type code
Definition: h5datatype.cpp:240
attribute_type create(const pni::core::string &n, bool ov=false) const
create scalar attribute
Definition: nxattribute_manager.hpp:119
Definition: cbf_reader.hpp:41
size_t size() const
get number of attributes
Definition: nxattribute_manager.hpp:213
OTYPE::attribute_type attribute_type
the attribute type
Definition: nxattribute_manager.hpp:48
iterator begin() const
iterator to frist attribute
Definition: nxattribute_manager.hpp:224
pni::core::container_iterator< const manager_type > iterator
iterator type
Definition: nxattribute_manager.hpp:52
imp_type & _imp
reference to the implementation of the parent
Definition: nxattribute_manager.hpp:59
OTYPE::type_type type_imp
implementation of the type traits
Definition: nxattribute_manager.hpp:57
attribute_type create(const pni::core::string &n, const CTYPE &s, bool ov=false) const
create an array attribute
Definition: nxattribute_manager.hpp:90
iterator end() const
iterator to last attribute
Definition: nxattribute_manager.hpp:235
OTYPE::imp_type imp_type
implementation type for the parent object of the manager
Definition: nxattribute_manager.hpp:54