echelon  0.8.0
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_TYPE_HPP
7 #define ECHELON_TYPE_HPP
8 
9 #include <echelon/hdf5/type.hpp>
10 
11 #include <string>
12 #include <vector>
13 #include <utility>
14 
15 namespace echelon
16 {
17 class type_layout;
18 
21 class type
22 {
23 public:
27 
30  type() = default;
31 
32  explicit type(native_handle_type native_handle_);
33 
36  static type char_();
37 
40  static type short_();
41 
44  static type int_();
45 
48  static type long_();
49 
52  static type long_long();
53 
56  static type uchar();
57 
60  static type ushort();
61 
64  static type uint();
65 
68  static type ulong();
69 
72  static type ulong_long();
73 
76  static type float_();
77 
80  static type double_();
81 
84  static type string();
85 
88  static type object_reference();
89 
96  static type compound_type(const type_layout& layout);
97 
98  std::size_t size() const;
99 
106  type clone() const;
107 
110  const native_handle_type& native_handle() const;
111 
114  explicit operator bool() const;
115 private:
116  hdf5::type type_handle_;
117 };
118 
138 bool operator==(const type& lhs, const type& rhs);
139 
155 bool operator!=(const type& lhs, const type& rhs);
156 
160 {
161 public:
165  struct element
166  {
173  element(std::string name, const type& type, std::size_t offset)
174  : name(std::move(name)), type_(type.clone()), offset(offset)
175  {
176  }
177 
180  std::string name;
181 
185 
188  std::size_t offset;
189  };
190 
196  explicit type_layout(std::size_t size_) : size_(size_)
197  {
198  }
199 
206  void add_element(std::string name, const type& element_type, std::size_t offset)
207  {
208  elements_.emplace_back(name, element_type, offset);
209  }
210 
213  typedef std::vector<element>::const_iterator iterator;
214 
218  iterator begin() const
219  {
220  using std::begin;
221 
222  return begin(elements_);
223  }
224 
228  iterator end() const
229  {
230  using std::end;
231 
232  return end(elements_);
233  }
234 
237  std::size_t size() const
238  {
239  return size_;
240  }
241 
242 private:
243  std::vector<element> elements_;
244  std::size_t size_;
245 };
246 }
247 
248 #endif
echelon&#39;s core namespace
Definition: attribute.cpp:10
type()=default
Initializes the handle with its null state.
static type short_()
Returns a handle to the primitive type &#39;short&#39;.
Definition: type.cpp:16
void add_element(std::string name, const type &element_type, std::size_t offset)
Adds a new member to the compound type.
Definition: type.hpp:206
static type long_long()
Returns a handle to the primitive type &#39;long long&#39;.
Definition: type.cpp:31
iterator begin() const
Definition: type.hpp:218
static type char_()
Returns a handle to the primitive type &#39;char&#39;.
Definition: type.cpp:11
std::size_t size() const
Definition: type.hpp:237
type_layout(std::size_t size_)
Constructs an empty layout for a compound type with a given total size.
Definition: type.hpp:196
A handle to an HDF5 type.
Definition: type.hpp:21
static type double_()
Returns a handle to the primitive type &#39;double&#39;.
Definition: type.cpp:66
bool operator==(const type &lhs, const type &rhs)
Tests two types for equality.
Definition: type.cpp:117
static type int_()
Returns a handle to the primitive type &#39;int&#39;.
Definition: type.cpp:21
std::string name
name of the member
Definition: type.hpp:180
element(std::string name, const type &type, std::size_t offset)
Constructs a new element.
Definition: type.hpp:173
static type object_reference()
Returns a handle to the primitive type &#39;object reference&#39;.
Definition: type.cpp:76
static type uchar()
Returns a handle to the primitive type &#39;unsigned char&#39;.
Definition: type.cpp:36
static type ulong_long()
Returns a handle to the primitive type &#39;unsigned long long&#39;.
Definition: type.cpp:56
static type float_()
Returns a handle to the primitive type &#39;float&#39;.
Definition: type.cpp:61
static type string()
Returns a handle to the primitive type &#39;string&#39;.
Definition: type.cpp:71
Tuple containing a name, a type and an offset, which are used to describe a single element of a compo...
Definition: type.hpp:165
A handle to an HDF5 type.
Definition: hdf5/type.hpp:23
static type uint()
Returns a handle to the primitive type &#39;unsigned int&#39;.
Definition: type.cpp:46
iterator end() const
Definition: type.hpp:228
static type ushort()
Returns a handle to the primitive type &#39;unsigned short&#39;.
Definition: type.cpp:41
static type compound_type(const type_layout &layout)
Creates a new compound type using a given layout.
Definition: type.cpp:81
bool operator!=(const type &lhs, const type &rhs)
Tests two types for inequality.
Definition: type.cpp:122
Description of a compound type&#39;s internal structure.
Definition: type.hpp:159
static type long_()
Returns a handle to the primitive type &#39;long&#39;.
Definition: type.cpp:26
std::size_t offset
offset of the member within the compound type in bytes
Definition: type.hpp:188
static type ulong()
Returns a handle to the primitive type &#39;unsigned long&#39;.
Definition: type.cpp:51
type type_
type of the member
Definition: type.hpp:184
type clone() const
Clones the type.
Definition: type.cpp:102
std::vector< element >::const_iterator iterator
Definition: type.hpp:213
const native_handle_type & native_handle() const
The underlying HDF5 low-level handle.
Definition: type.cpp:107