HDF5 C++ API  1.8.20
 All Classes Namespaces Functions Variables Typedefs Friends Pages
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://support.hdfgroup.org/ftp/HDF5/releases. *
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: makes a copy of the original object
34  DataType(const DataType& original);
35 
36  // Creates a copy of a predefined type
37  DataType(const PredType& pred_type);
38 
39  // Opens 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  DataType(const Attribute& attr, const void* ref, H5R_type_t ref_type = H5R_OBJECT);
46 
47  // Closes this datatype.
48  virtual void close();
49 
50  // Copies an existing datatype to this datatype object.
51  void copy(const DataType& like_type);
52 
53  // Copies the datatype of dset to this datatype object.
54  void copy(const DataSet& dset);
55 
56  // Returns a DataType instance by decoding the binary object
57  // description of this datatype.
58  virtual DataType* decode() const;
59 
60  // Creates a binary object description of this datatype.
61  void encode();
62 
63  // Returns the datatype class identifier.
64  H5T_class_t getClass() const;
65 
66  // Commits a transient datatype to a file; this datatype becomes
67  // a named datatype which can be accessed from the location.
68  void commit(const H5Location& loc, const char* name);
69  void commit(const H5Location& loc, const H5std_string& name);
70 
71  // Determines whether this datatype is a named datatype or
72  // a transient datatype.
73  bool committed() const;
74 
75  // Finds a conversion function that can handle the conversion
76  // this datatype to the given datatype, dest.
77  H5T_conv_t find(const DataType& dest, H5T_cdata_t **pcdata) const;
78 
79  // Converts data from between specified datatypes.
80  void convert(const DataType& dest, size_t nelmts, void *buf, void *background, const PropList& plist=PropList::DEFAULT) const;
81 
82  // Assignment operator
83  DataType& operator=(const DataType& rhs);
84 
85  // Determines whether two datatypes are the same.
86  bool operator==(const DataType& compared_type) const;
87 
88  // Locks a datatype.
89  void lock() const;
90 
91  // Returns the size of a datatype.
92  size_t getSize() const;
93 
94  // Returns the base datatype from which a datatype is derived.
95  // Note: not quite right for specific types yet???
96  DataType getSuper() const;
97 
98  // Registers a conversion function.
99  void registerFunc(H5T_pers_t pers, const char* name, const DataType& dest, H5T_conv_t func) const;
100  void registerFunc(H5T_pers_t pers, const H5std_string& name, const DataType& dest, H5T_conv_t func) const;
101 
102  // Removes a conversion function from all conversion paths.
103  void unregister(H5T_pers_t pers, const char* name, const DataType& dest, H5T_conv_t func) const;
104  void unregister(H5T_pers_t pers, const H5std_string& name, const DataType& dest, H5T_conv_t func) const;
105 
106  // Tags an opaque datatype.
107  void setTag(const char* tag) const;
108  void setTag(const H5std_string& tag) const;
109 
110  // Gets the tag associated with an opaque datatype.
111  H5std_string getTag() const;
112 
113  // Checks whether this datatype contains (or is) a certain type class.
114  bool detectClass(H5T_class_t cls) const;
115 
116  // Checks whether this datatype is a variable-length string.
117  bool isVariableStr() const;
118 
119  // Returns a copy of the creation property list of a datatype.
120  PropList getCreatePlist() const;
121 
123  virtual H5std_string fromClass () const { return("DataType"); }
124 
125  // Creates a copy of an existing DataType using its id
126  DataType(const hid_t type_id);
127 
128  // Default constructor
129  DataType();
130 
131  // Determines whether this datatype has a binary object description.
132  bool hasBinaryDesc() const;
133 
134  // Gets the datatype id.
135  virtual hid_t getId() const;
136 
137  // Destructor: properly terminates access to this datatype.
138  virtual ~DataType();
139 
140  protected:
141 #ifndef DOXYGEN_SHOULD_SKIP_THIS
142  hid_t id; // HDF5 datatype id
143 
144  // Returns an id of a type by decoding the binary object
145  // description of this datatype.
146  hid_t p_decode() const;
147 
148  // Sets the datatype id.
149  virtual void p_setId(const hid_t new_id);
150 
151  // Opens a datatype and returns the id.
152  hid_t p_opentype(const H5Location& loc, const char* dtype_name) const;
153 #endif // DOXYGEN_SHOULD_SKIP_THIS
154 
155  private:
156  // Buffer for binary object description of this datatype, allocated
157  // in DataType::encode and used in DataType::decode
158  unsigned char *encoded_buf;
159  size_t buf_size;
160 
161  // Friend function to set DataType id. For library use only.
162  friend void f_DataType_setId(DataType* dtype, hid_t new_id);
163 
164 #ifndef DOXYGEN_SHOULD_SKIP_THIS
165  void p_commit(hid_t loc_id, const char* name);
166 #endif // DOXYGEN_SHOULD_SKIP_THIS
167 
168 }; // end of DataType
169 } // namespace H5
170 
171 #endif // __H5DataType_H
Class PredType holds the definition of all the HDF5 predefined datatypes.
Definition: H5PredType.h:28
Class Attribute operates on HDF5 attributes.
Definition: H5Attribute.h:29
Class DataType provides generic operations on HDF5 datatypes.
Definition: H5DataType.h:28
Class H5Object is a bridge between H5Location and DataSet, DataType, and Group.
Definition: H5Object.h:37
virtual H5std_string fromClass() const
Returns this class name.
Definition: H5DataType.h:123
H5Location is an abstract base class, providing a collection of wrappers of the C functions that take...
Definition: H5Location.h:42
Class DataSet operates on HDF5 datasets.
Definition: H5DataSet.h:28
Class PropList provides operations for generic property lists.
Definition: H5PropList.h:26
static const PropList & DEFAULT
Default property list.
Definition: H5PropList.h:29


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