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


The HDF Group Help Desk:
  Copyright by The HDF Group
and the Board of Trustees of the University of Illinois