libSplash
basetypes_array.hpp
1 
24 #ifndef BASETYPES_ARRAY_HPP
25 #define BASETYPES_ARRAY_HPP
26 
27 #include <stdint.h>
28 #include <string>
29 
30 #include "splash/CollectionType.hpp"
31 
32 namespace splash
33 {
34 
35 #define TYPE_ARRAY(_name, _h5_type, _real_type, _size) \
36  class ColType##_name##Array : public CollectionType \
37  { \
38  public: \
39  \
40  ColType##_name##Array() \
41  { \
42  const hsize_t dim[] = {_size}; \
43  this->type = H5Tarray_create(_h5_type, 1, dim); \
44  } \
45  \
46  ~ColType##_name##Array() \
47  { H5Tclose(this->type); } \
48  \
49  size_t getSize() const \
50  { return sizeof (_real_type) * _size; } \
51  \
52  static CollectionType* genType(hid_t datatype_id) \
53  { \
54  bool found = false; \
55  H5T_class_t h5_class = H5Tget_class(datatype_id); \
56  if(h5_class == H5T_ARRAY) \
57  { \
58  hid_t base = H5Tget_super(datatype_id); \
59  if(H5Tequal(base, _h5_type) == 1) \
60  { \
61  if(H5Tget_array_ndims(datatype_id) == 1) \
62  { \
63  hsize_t adims_out[1]; \
64  H5Tget_array_dims(datatype_id, adims_out); \
65  if(adims_out[0] == _size) \
66  found = true; \
67  } \
68  } \
69  H5Tclose(base); \
70  } \
71  if(found) \
72  return new ColType##_name##Array; \
73  else \
74  return NULL; \
75  } \
76  \
77  std::string toString() const \
78  { \
79  return #_name"Array"; \
80  } \
81  };
82 
83 TYPE_ARRAY(Float2, H5T_NATIVE_FLOAT, float, 2);
84 TYPE_ARRAY(Float3, H5T_NATIVE_FLOAT, float, 3);
85 TYPE_ARRAY(Float4, H5T_NATIVE_FLOAT, float, 4);
86 
87 TYPE_ARRAY(Double2, H5T_NATIVE_DOUBLE, double, 2);
88 TYPE_ARRAY(Double3, H5T_NATIVE_DOUBLE, double, 3);
89 TYPE_ARRAY(Double4, H5T_NATIVE_DOUBLE, double, 4);
90 
91 TYPE_ARRAY(Int2, H5T_NATIVE_INT, int, 2);
92 TYPE_ARRAY(Int3, H5T_NATIVE_INT, int, 3);
93 TYPE_ARRAY(Int4, H5T_NATIVE_INT, int, 4);
94 }
95 
96 #endif /* BASETYPES_ARRAY_HPP */