echelon  0.8.0
attribute_repository.hpp
1 // Copyright (c) 2012-2014 Christopher Hinz
2 //
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef ECHELON_ATTRIBUTE_REPOSITORY_HPP
7 #define ECHELON_ATTRIBUTE_REPOSITORY_HPP
8 
9 #include <echelon/type.hpp>
10 #include <echelon/attribute.hpp>
11 
12 #include <memory>
13 #include <map>
14 #include <string>
15 #include <utility>
16 
17 namespace echelon
18 {
19 
26 template <typename Parent>
28 {
29 public:
30  explicit attribute_repository(typename Parent::native_handle_type handle_)
31  : native_parent_(std::move(handle_))
32  {
33  }
34 
42  attribute create(const std::string& name, const type& datatype)
43  {
44  return attribute(native_parent_.attributes().create(name, datatype.native_handle()));
45  }
46 
56  template <typename T>
57  attribute create(const std::string& name)
58  {
59  return attribute(native_parent_.attributes().template create<T>(name));
60  }
61 
72  template <typename T>
73  attribute create(const std::string& name, const T& value)
74  {
75  return attribute(native_parent_.attributes().create(name, value));
76  }
77 
84  attribute operator[](const std::string& name) const
85  {
86  return attribute(native_parent_.attributes()[name]);
87  }
88 
95  bool exists(const std::string& name) const
96  {
97  return native_parent_.attributes().exists(name);
98  }
99 
122  attribute require(const std::string& name, const type& datatype)
123  {
124  return attribute(native_parent_.attributes().require(name, datatype.native_handle()));
125  }
126 
151  template <typename T>
152  attribute require(const std::string& name)
153  {
154  return attribute(native_parent_.attributes().template require<T>(name));
155  }
156 
183  template <typename T>
184  attribute require(const std::string& name, const T& value)
185  {
186  return attribute(native_parent_.attributes().require(name, value));
187  }
188 
189 private:
190  typename Parent::native_handle_type native_parent_;
191 };
192 }
193 
194 #endif
echelon&#39;s core namespace
Definition: attribute.cpp:10
Attribute manager, which should be embedded into a parent object, which supports attributes.
Definition: attribute_repository.hpp:27
attribute create(const std::string &name, const type &datatype)
Creates a new attribute.
Definition: attribute_repository.hpp:42
A handle to an HDF5 type.
Definition: type.hpp:21
attribute create(const std::string &name)
Creates a new attribute.
Definition: attribute_repository.hpp:57
attribute require(const std::string &name, const T &value)
Returns the requested attribute, if it already exists, otherwise a new attribute is created...
Definition: attribute_repository.hpp:184
attribute require(const std::string &name, const type &datatype)
Returns the requested attribute, if it already exists, otherwise a new attribute is created...
Definition: attribute_repository.hpp:122
bool exists(const std::string &name) const
Tests, if an attribute exists.
Definition: attribute_repository.hpp:95
A handle to an echelon attribute.
Definition: attribute.hpp:21
attribute create(const std::string &name, const T &value)
Creates a new attribute and initializes it with a given value.
Definition: attribute_repository.hpp:73
attribute require(const std::string &name)
Returns the requested attribute, if it already exists, otherwise the attribute is created...
Definition: attribute_repository.hpp:152
attribute operator[](const std::string &name) const
Accessor function for this attribute repository.
Definition: attribute_repository.hpp:84
const native_handle_type & native_handle() const
The underlying HDF5 low-level handle.
Definition: type.cpp:107