libSplash
ColTypeBool.hpp
1 
24 #ifndef COLTYPEBOOL_H
25 #define COLTYPEBOOL_H
26 
27 #include "splash/CollectionType.hpp"
28 
29 #include <string>
30 #include <cstring>
31 
32 namespace splash
33 {
34 
36 {
37 public:
38 
39  ColTypeBool()
40  {
41  // 8 bit (very) short int, see
42  // http://www.hdfgroup.org/HDF5/doc/RM/PredefDTypes.html
43  // this is a h5py compatible implementation for bool, see:
44  // http://docs.h5py.org/en/latest/faq.html
45  this->type = H5Tenum_create(H5T_NATIVE_INT8);
46  const char *names[2] = {"TRUE", "FALSE"};
47  const int64_t val[2] = {1, 0};
48  H5Tenum_insert(this->type, names[0], &val[0]);
49  H5Tenum_insert(this->type, names[1], &val[1]);
50  }
51 
52  ~ColTypeBool()
53  {
54  H5Tclose(this->type);
55  }
56 
57  size_t getSize() const
58  {
59  return sizeof (bool);
60  }
61 
62  static CollectionType* genType(hid_t datatype_id)
63  {
64  bool found = false;
65  H5T_class_t h5_class = H5Tget_class(datatype_id);
66  if(h5_class == H5T_ENUM)
67  {
68  if(H5Tget_nmembers(datatype_id) == 2)
69  {
70  char* m0 = H5Tget_member_name(datatype_id,0);
71  char* m1 = H5Tget_member_name(datatype_id,1);
72  if(strcmp("TRUE" , m0) == 0 && strcmp("FALSE", m1) == 0)
73  found = true;
74  free(m1);
75  free(m0);
76  }
77  }
78 
79  if(found)
80  return new ColTypeBool;
81  else
82  return NULL;
83  }
84 
85  std::string toString() const
86  {
87  return "Bool";
88  }
89 };
90 
91 }
92 
93 #endif /* COLTYPEBOOL_H */
std::string toString() const
Definition: ColTypeBool.hpp:85
size_t getSize() const
Definition: ColTypeBool.hpp:57