libSplash
ColTypeDim.hpp
1 
24 #ifndef COLTYPEDIM_H
25 #define COLTYPEDIM_H
26 
27 #include "splash/CollectionType.hpp"
28 #include "splash/Dimensions.hpp"
29 
30 #include <cstdlib>
31 #include <string>
32 #include <cstring>
33 
34 namespace splash
35 {
36 
37  class ColTypeDim : public CollectionType
38  {
39  public:
40 
41  ColTypeDim()
42  {
43  this->type = H5Tcreate(H5T_COMPOUND, getSize());
44  H5Tinsert(this->type, "x", 0, H5T_NATIVE_HSIZE);
45  H5Tinsert(this->type, "y", sizeof(hsize_t), H5T_NATIVE_HSIZE);
46  H5Tinsert(this->type, "z", sizeof(hsize_t) * 2, H5T_NATIVE_HSIZE);
47  }
48 
49  ~ColTypeDim()
50  {
51  H5Tclose(this->type);
52  }
53 
54  size_t getSize() const
55  {
56  return getSize_();
57  }
58 
59  std::string toString() const
60  {
61  return "Dim";
62  }
63 
64  static CollectionType* genType(hid_t datatype_id)
65  {
66  bool found = false;
67  H5T_class_t h5_class = H5Tget_class(datatype_id);
68  if(h5_class == H5T_COMPOUND)
69  {
70  if(H5Tget_nmembers(datatype_id) == 3)
71  {
72  if(H5Tget_size(datatype_id) == getSize_())
73  {
74  char* m0 = H5Tget_member_name(datatype_id, 0);
75  char* m1 = H5Tget_member_name(datatype_id, 1);
76  char* m2 = H5Tget_member_name(datatype_id, 2);
77  if(strcmp("x", m0) == 0 && strcmp("y", m1) == 0 && strcmp("z", m2) == 0)
78  found = true;
79 
80  free(m2);
81  free(m1);
82  free(m0);
83  }
84  }
85  }
86  if(found)
87  return new ColTypeDim;
88  else
89  return NULL;
90  }
91 
92  private:
93  static size_t getSize_()
94  {
95  return sizeof(hsize_t) * 3;
96  }
97 
98  };
99 }
100 
101 #endif /* COLTYPEDIM_H */
size_t getSize() const
Definition: ColTypeDim.hpp:54
std::string toString() const
Definition: ColTypeDim.hpp:59