echelon  0.8.0
hdf5/type.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_HDF5_TYPE_HPP
7 #define ECHELON_HDF5_TYPE_HPP
8 
9 #include <echelon/hdf5/precursor/type.hpp>
10 
11 #include <string>
12 #include <vector>
13 #include <utility>
14 
15 namespace echelon
16 {
17 namespace hdf5
18 {
19 class type_layout;
20 
23 class type
24 {
25 public:
28  using native_handle_type = hdf5::precursor::type;
29 
32  type() = default;
33 
34  explicit type(native_handle_type type_wrapper_);
35 
38  static type char_();
39 
42  static type short_();
43 
46  static type int_();
47 
50  static type long_();
51 
54  static type long_long();
55 
58  static type uchar();
59 
62  static type ushort();
63 
66  static type uint();
67 
70  static type ulong();
71 
74  static type ulong_long();
75 
78  static type float_();
79 
82  static type double_();
83 
86  static type string();
87 
90  static type object_reference();
91 
98  static type compound_type(const type_layout& layout);
99 
100  std::size_t size() const;
101 
108  type clone() const;
109 
112  const native_handle_type& native_handle() const;
113 
116  explicit operator bool() const;
117 private:
118  hdf5::precursor::type type_wrapper_;
119 };
120 
140 bool operator==(const type& lhs, const type& rhs);
141 
157 bool operator!=(const type& lhs, const type& rhs);
158 
162 {
163 public:
167  struct element
168  {
175  element(std::string name, const type& type, std::size_t offset)
176  : name(std::move(name)), type_(type.clone()), offset(offset)
177  {
178  }
179 
182  std::string name;
183 
187 
190  std::size_t offset;
191  };
192 
198  explicit type_layout(std::size_t size_) : size_(size_)
199  {
200  }
201 
208  void add_element(std::string name, const type& element_type, std::size_t offset)
209  {
210  elements_.emplace_back(name, element_type, offset);
211  }
212 
215  typedef std::vector<element>::const_iterator iterator;
216 
220  iterator begin() const
221  {
222  using std::begin;
223 
224  return begin(elements_);
225  }
226 
230  iterator end() const
231  {
232  using std::end;
233 
234  return end(elements_);
235  }
236 
239  std::size_t size() const
240  {
241  return size_;
242  }
243 
244 private:
245  std::vector<element> elements_;
246  std::size_t size_;
247 };
248 }
249 }
250 
251 #endif
echelon&#39;s core namespace
Definition: attribute.cpp:10
hdf5::precursor::type native_handle_type
Type of the underlying HDF5 low-level handle.
Definition: hdf5/type.hpp:28
type clone() const
Clones the type.
Definition: hdf5/type.cpp:103
static type short_()
Returns a handle to the primitive type &#39;short&#39;.
Definition: hdf5/type.cpp:17
Description of a compound type&#39;s internal structure.
Definition: hdf5/type.hpp:161
static type float_()
Returns a handle to the primitive type &#39;float&#39;.
Definition: hdf5/type.cpp:62
static type object_reference()
Returns a handle to the primitive type &#39;object reference&#39;.
Definition: hdf5/type.cpp:77
static type long_long()
Returns a handle to the primitive type &#39;long long&#39;.
Definition: hdf5/type.cpp:32
static type uchar()
Returns a handle to the primitive type &#39;unsigned char&#39;.
Definition: hdf5/type.cpp:37
static type string()
Returns a handle to the primitive type &#39;string&#39;.
Definition: hdf5/type.cpp:72
std::size_t offset
offset of the member within the compound type in bytes
Definition: hdf5/type.hpp:190
iterator begin() const
Definition: hdf5/type.hpp:220
std::size_t size() const
Definition: hdf5/type.hpp:239
static type double_()
Returns a handle to the primitive type &#39;double&#39;.
Definition: hdf5/type.cpp:67
static type int_()
Returns a handle to the primitive type &#39;int&#39;.
Definition: hdf5/type.cpp:22
static type ulong_long()
Returns a handle to the primitive type &#39;unsigned long long&#39;.
Definition: hdf5/type.cpp:57
std::string name
name of the member
Definition: hdf5/type.hpp:182
iterator end() const
Definition: hdf5/type.hpp:230
std::vector< element >::const_iterator iterator
Definition: hdf5/type.hpp:215
const native_handle_type & native_handle() const
The underlying HDF5 low-level handle.
Definition: hdf5/type.cpp:108
Tuple containing a name, a type and an offset, which are used to describe a single element of a compo...
Definition: hdf5/type.hpp:167
static type ushort()
Returns a handle to the primitive type &#39;unsigned short&#39;.
Definition: hdf5/type.cpp:42
type_layout(std::size_t size_)
Constructs an empty layout for a compound type with a given total size.
Definition: hdf5/type.hpp:198
A handle to an HDF5 type.
Definition: hdf5/type.hpp:23
static type long_()
Returns a handle to the primitive type &#39;long&#39;.
Definition: hdf5/type.cpp:27
element(std::string name, const type &type, std::size_t offset)
Constructs a new element.
Definition: hdf5/type.hpp:175
static type uint()
Returns a handle to the primitive type &#39;unsigned int&#39;.
Definition: hdf5/type.cpp:47
static type char_()
Returns a handle to the primitive type &#39;char&#39;.
Definition: hdf5/type.cpp:12
static type ulong()
Returns a handle to the primitive type &#39;unsigned long&#39;.
Definition: hdf5/type.cpp:52
type()=default
Initializes the handle with its null state.
void add_element(std::string name, const type &element_type, std::size_t offset)
Adds a new member to the compound type.
Definition: hdf5/type.hpp:208
type type_
type of the member
Definition: hdf5/type.hpp:186
static type compound_type(const type_layout &layout)
Creates a new compound type using a given layout.
Definition: hdf5/type.cpp:82