My Project  1.10.11
H5DataType.h
1 // C++ informative line for the emacs editor: -*- C++ -*-
2 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3  * Copyright by The HDF Group. *
4  * All rights reserved. *
5  * *
6  * This file is part of HDF5. The full HDF5 copyright notice, including *
7  * terms governing use, modification, and redistribution, is contained in *
8  * the COPYING file, which can be found at the root of the source code *
9  * distribution tree, or in https://www.hdfgroup.org/licenses. *
10  * If you do not have access to either file, you may request a copy from *
11  * help@hdfgroup.org. *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 #ifndef H5DataType_H
15 #define H5DataType_H
16 
17 namespace H5 {
18 
26 // Inheritance: DataType -> H5Object -> H5Location -> IdComponent
27 class H5_DLLCPP DataType : public H5Object {
28  public:
29  // Creates a datatype given its class and size
30  DataType(const H5T_class_t type_class, size_t size);
31 
32  // Copy constructor - same as the original DataType.
33  DataType(const DataType &original);
34 
35  // Creates a copy of a predefined type
36  DataType(const PredType &pred_type);
37 
38  // Constructors to open a generic named datatype at a given location.
39  DataType(const H5Location &loc, const char *name);
40  DataType(const H5Location &loc, const H5std_string &name);
41 
42  // Creates a datatype by way of dereference.
43  DataType(const H5Location &loc, const void *ref, H5R_type_t ref_type = H5R_OBJECT,
44  const PropList &plist = PropList::DEFAULT);
45  // DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT, const
46  // PropList& plist = PropList::DEFAULT);
47 
48  // Closes this datatype.
49  virtual void close();
50 
51  // Copies an existing datatype to this datatype object.
52  void copy(const DataType &like_type);
53 
54  // Copies the datatype of dset to this datatype object.
55  void copy(const DataSet &dset);
56 
57  // Returns a DataType instance by decoding the binary object
58  // description of this datatype.
59  virtual DataType *decode() const;
60 
61  // Creates a binary object description of this datatype.
62  void encode();
63 
64  // Returns the datatype class identifier.
65  H5T_class_t getClass() const;
66 
67  // Commits a transient datatype to a file; this datatype becomes
68  // a named datatype which can be accessed from the location.
69  void commit(const H5Location &loc, const char *name);
70  void commit(const H5Location &loc, const H5std_string &name);
71 
72  // These two overloaded functions are kept for backward compatibility
73  // only; they missed the const - removed from 1.8.18 and 1.10.1
74  // void commit(H5Location& loc, const char* name);
75  // void commit(H5Location& loc, const H5std_string& name);
76 
77  // Determines whether this datatype is a named datatype or
78  // a transient datatype.
79  bool committed() const;
80 
81  // Finds a conversion function that can handle the conversion
82  // this datatype to the given datatype, dest.
83  H5T_conv_t find(const DataType &dest, H5T_cdata_t **pcdata) const;
84 
85  // Converts data from between specified datatypes.
86  void convert(const DataType &dest, size_t nelmts, void *buf, void *background,
87  const PropList &plist = PropList::DEFAULT) const;
88 
89  // Assignment operator
90  DataType &operator=(const DataType &rhs);
91 
92  // Determines whether two datatypes are the same.
93  bool operator==(const DataType &compared_type) const;
94 
95  // Determines whether two datatypes are not the same.
96  bool operator!=(const DataType &compared_type) const;
97 
98  // Locks a datatype.
99  void lock() const;
100 
101  // Returns the size of a datatype.
102  size_t getSize() const;
103 
104  // Returns the base datatype from which a datatype is derived.
105  // Note: not quite right for specific types yet???
106  DataType getSuper() const;
107 
108  // Registers a conversion function.
109  void registerFunc(H5T_pers_t pers, const char *name, const DataType &dest, H5T_conv_t func) const;
110  void registerFunc(H5T_pers_t pers, const H5std_string &name, const DataType &dest, H5T_conv_t func) const;
111 
112  // Removes a conversion function from all conversion paths.
113  void unregister(H5T_pers_t pers, const char *name, const DataType &dest, H5T_conv_t func) const;
114  void unregister(H5T_pers_t pers, const H5std_string &name, const DataType &dest, H5T_conv_t func) const;
115 
116  // Tags an opaque datatype.
117  void setTag(const char *tag) const;
118  void setTag(const H5std_string &tag) const;
119 
120  // Gets the tag associated with an opaque datatype.
121  H5std_string getTag() const;
122 
123  // Checks whether this datatype contains (or is) a certain type class.
124  bool detectClass(H5T_class_t cls) const;
125  static bool detectClass(const PredType &pred_type, H5T_class_t cls);
126 
127  // Checks whether this datatype is a variable-length string.
128  bool isVariableStr() const;
129 
130  // Returns a copy of the creation property list of a datatype.
131  PropList getCreatePlist() const;
132 
134  virtual H5std_string
135  fromClass() const
136  {
137  return ("DataType");
138  }
139 
140  // Creates a copy of an existing DataType using its id
141  DataType(const hid_t type_id);
142 
143  // Default constructor
144  DataType();
145 
146  // Determines whether this datatype has a binary object description.
147  bool hasBinaryDesc() const;
148 
149  // Gets the datatype id.
150  virtual hid_t getId() const;
151 
152  // Destructor: properly terminates access to this datatype.
153  virtual ~DataType();
154 
155  protected:
156 #ifndef DOXYGEN_SHOULD_SKIP_THIS
157  hid_t id; // HDF5 datatype id
158 
159  // Returns an id of a type by decoding the binary object
160  // description of this datatype.
161  hid_t p_decode() const;
162 
163  // Sets the datatype id.
164  virtual void p_setId(const hid_t new_id);
165 
166  // Opens a datatype and returns the id.
167  hid_t p_opentype(const H5Location &loc, const char *dtype_name) const;
168 
169 #endif // DOXYGEN_SHOULD_SKIP_THIS
170 
171  private:
172  // Buffer for binary object description of this datatype, allocated
173  // in DataType::encode and used in DataType::decode
174  unsigned char *encoded_buf;
175  size_t buf_size;
176 
177  // Friend function to set DataType id. For library use only.
178  friend void f_DataType_setId(DataType *dtype, hid_t new_id);
179 
180  void p_commit(hid_t loc_id, const char *name);
181 
182 }; // end of DataType
183 } // namespace H5
184 
185 #endif // H5DataType_H
H5::DataType::operator!=
bool operator!=(const DataType &compared_type) const
Compares this DataType against the given one to determines whether the two objects refer to different...
Definition: H5DataType.cpp:410
H5::Exception
Exception provides wrappers of HDF5 error handling functions.
Definition: H5Exception.h:27
H5::DataType::getId
virtual hid_t getId() const
Get the id of this datatype.
Definition: H5DataType.cpp:900
H5::DataType::getTag
H5std_string getTag() const
Gets the tag associated with an opaque datatype.
Definition: H5DataType.cpp:783
H5::DataType::DataType
DataType()
Default constructor: Creates a stub datatype.
Definition: H5DataType.cpp:48
H5::DataType::copy
void copy(const DataType &like_type)
Copies an existing datatype to this datatype object.
Definition: H5DataType.cpp:208
H5::IdComponent::incRefCount
void incRefCount() const
Increment reference counter for the id of this object.
Definition: H5IdComponent.cpp:54
H5::DataSet
Class DataSet operates on HDF5 datasets.
Definition: H5DataSet.h:27
H5::DataTypeIException
Definition: H5Exception.h:109
H5::DataType::getSuper
DataType getSuper() const
Returns the base datatype from which a datatype is derived.
Definition: H5DataType.cpp:647
H5::DataType::setTag
void setTag(const char *tag) const
Tags an opaque datatype.
Definition: H5DataType.cpp:753
H5::DataType::registerFunc
void registerFunc(H5T_pers_t pers, const char *name, const DataType &dest, H5T_conv_t func) const
Registers the specified conversion function.
Definition: H5DataType.cpp:682
H5::DataType::lock
void lock() const
Locks a datatype, making it read-only and non-destructible.
Definition: H5DataType.cpp:592
H5::DataType::unregister
void unregister(H5T_pers_t pers, const char *name, const DataType &dest, H5T_conv_t func) const
Removes a conversion function from all conversion paths.
Definition: H5DataType.cpp:720
H5::DataType::encode
void encode()
Creates a binary object description of this datatype.
Definition: H5DataType.cpp:310
H5::PredType
Class PredType holds the definition of all the HDF5 predefined datatypes.
Definition: H5PredType.h:27
H5::DataType::find
H5T_conv_t find(const DataType &dest, H5T_cdata_t **pcdata) const
Finds a conversion function that can handle a conversion from this datatype to the specified datatype...
Definition: H5DataType.cpp:538
H5::DataType::close
virtual void close()
Closes the datatype if it is not a predefined type.
Definition: H5DataType.cpp:962
H5::DataSet::getId
virtual hid_t getId() const
Get the id of this dataset.
Definition: H5DataSet.cpp:693
H5::DataType::operator=
DataType & operator=(const DataType &rhs)
Assignment operator.
Definition: H5DataType.cpp:368
H5::Exception::getDetailMsg
H5std_string getDetailMsg() const
Returns the detailed message set at the time the exception is thrown.
Definition: H5Exception.cpp:264
H5::DataType::getClass
H5T_class_t getClass() const
Returns the datatype class identifier.
Definition: H5DataType.cpp:609
H5::DataType::decode
virtual DataType * decode() const
Returns a DataType instance by decoding the binary object description of this datatype.
Definition: H5DataType.cpp:288
H5::DataType::getCreatePlist
PropList getCreatePlist() const
Returns a copy of the property list, which is for datatype creation.
Definition: H5DataType.cpp:875
H5::DataType::convert
void convert(const DataType &dest, size_t nelmts, void *buf, void *background, const PropList &plist=PropList::DEFAULT) const
Converts data from this datatype to the specified datatypes.
Definition: H5DataType.cpp:562
H5::PropList::DEFAULT
static const PropList & DEFAULT
Default property list.
Definition: H5PropList.h:27
H5::DataType::getSize
size_t getSize() const
Returns the size of a datatype.
Definition: H5DataType.cpp:628
H5::PropList::getId
virtual hid_t getId() const
Get the id of this property list.
Definition: H5PropList.cpp:292
H5::H5Object
Class H5Object is a bridge between H5Location and DataSet, DataType, and Group.
Definition: H5Object.h:64
H5::DataType::f_DataType_setId
friend void f_DataType_setId(DataType *dtype, hid_t new_id)
H5::IdComponent::setId
void setId(const hid_t new_id)
Sets the identifier of this object to a new value.
Definition: H5IdComponent.cpp:315
H5
Definition: H5AbstractDs.cpp:33
H5::DataType::operator==
bool operator==(const DataType &compared_type) const
Compares this DataType against the given one to determines whether the two objects refer to the same ...
Definition: H5DataType.cpp:386
H5::DataType::isVariableStr
bool isVariableStr() const
Check whether this datatype is a variable-length string.
Definition: H5DataType.cpp:851
H5::DataType::commit
void commit(const H5Location &loc, const char *name)
Commits a transient datatype to a file, creating a new named datatype.
Definition: H5DataType.cpp:448
H5::DataType::hasBinaryDesc
bool hasBinaryDesc() const
Determines whether this datatype has a binary object description.
Definition: H5DataType.cpp:340
H5::DataType::committed
bool committed() const
Determines whether a datatype is a named type or a transient type.
Definition: H5DataType.cpp:514
H5::DataType
Class DataType provides generic operations on HDF5 datatypes.
Definition: H5DataType.h:27
H5::DataType::fromClass
virtual H5std_string fromClass() const
Returns this class name.
Definition: H5DataType.h:135
H5::H5Location
H5Location is an abstract base class, added in version 1.8.12.
Definition: H5Location.h:30
H5::PropList
Class PropList inherits from IdComponent and provides wrappers for the HDF5 generic property list.
Definition: H5PropList.h:24
H5::DataType::detectClass
bool detectClass(H5T_class_t cls) const
Checks whether a datatype contains (or is) a certain type of datatype.
Definition: H5DataType.cpp:809
H5::DataType::~DataType
virtual ~DataType()
Properly terminates access to this datatype.
Definition: H5DataType.cpp:998


The HDF Group Help Desk:
  Copyright by The HDF Group