1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
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://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 #include <string>
15 
16 #include "H5Include.h"
17 #include "H5Exception.h"
18 #include "H5IdComponent.h"
19 #include "H5PropList.h"
20 #include "H5OcreatProp.h"
21 #include "H5DcreatProp.h"
22 #include "H5LcreatProp.h"
23 #include "H5LaccProp.h"
24 #include "H5DaccProp.h"
25 #include "H5Location.h"
26 #include "H5Object.h"
27 #include "H5DataType.h"
28 #include "H5VarLenType.h"
29 
30 namespace H5 {
31 
32 //--------------------------------------------------------------------------
33 // Function:    VarLenType default constructor
34 ///\brief       Default constructor: Creates a stub variable-length datatype.
35 //--------------------------------------------------------------------------
VarLenType()36 VarLenType::VarLenType() : DataType() {}
37 
38 //--------------------------------------------------------------------------
39 // Function:    VarLenType overloaded constructor
40 ///\brief       Creates an VarLenType object using an existing id.
41 ///\param       existing_id - IN: Id of an existing datatype
42 ///\exception   H5::DataTypeIException
43 // Programmer   Binh-Minh Ribler - May, 2004
44 //--------------------------------------------------------------------------
VarLenType(const hid_t existing_id)45 VarLenType::VarLenType(const hid_t existing_id) : DataType(existing_id) {}
46 
47 //--------------------------------------------------------------------------
48 // Function:    VarLenType copy constructor
49 ///\brief       Copy constructor: same HDF5 object as \a original
50 // Programmer   Binh-Minh Ribler - May, 2004
51 //--------------------------------------------------------------------------
VarLenType(const VarLenType & original)52 VarLenType::VarLenType(const VarLenType& original) : DataType(original) {}
53 
54 //--------------------------------------------------------------------------
55 // Function:    VarLenType overloaded constructor
56 ///\brief       Deprecated - will be removed after 1.10.2
57 ///\param       base_type - IN: Pointer to existing datatype
58 ///\exception   H5::DataTypeIException
59 // Description
60 //              DataType passed by pointer to avoid clashing with copy
61 //              constructor.
62 //              Updated: this is unnecessary.
63 //              -BMR, Sep, 2017
64 // Programmer   Binh-Minh Ribler - May, 2004
65 //--------------------------------------------------------------------------
VarLenType(const DataType * base_type)66 VarLenType::VarLenType(const DataType* base_type) : DataType()
67 {
68     id = H5Tvlen_create(base_type->getId());
69     if (id < 0)
70     {
71         throw DataTypeIException("VarLenType constructor",
72                 "H5Tvlen_create returns negative value");
73     }
74 }
75 
76 //--------------------------------------------------------------------------
77 // Function:    VarLenType overloaded constructor
78 ///\brief       Creates a new variable-length datatype based on the specified
79 ///             \a base_type.
80 ///\param       base_type - IN: An existing datatype
81 ///\exception   H5::DataTypeIException
82 // Programmer   Binh-Minh Ribler - May, 2004
83 //--------------------------------------------------------------------------
VarLenType(const DataType & base_type)84 VarLenType::VarLenType(const DataType& base_type) : DataType()
85 {
86     id = H5Tvlen_create(base_type.getId());
87     if (id < 0)
88     {
89         throw DataTypeIException("VarLenType constructor",
90                 "H5Tvlen_create returns negative value");
91     }
92 }
93 
94 //--------------------------------------------------------------------------
95 // Function:    VarLenType overloaded constructor
96 ///\brief       Creates an VarLenType instance by opening an HDF5 variable
97 ///             length datatype given its name, provided as a C char*.
98 ///\param       loc        - IN: Location of the type
99 ///\param       dtype_name - IN: Variable length type name
100 ///\exception   H5::DataTypeIException
101 // Programmer   Binh-Minh Ribler - Dec 2016
102 // Description
103 //              In 1.10.1, this constructor was introduced and may replace the
104 //              existing function CommonFG::openVarLenType(const char*) to
105 //              improve usability.
106 //              -BMR, Dec 2016
107 //--------------------------------------------------------------------------
VarLenType(const H5Location & loc,const char * dtype_name)108 VarLenType::VarLenType(const H5Location& loc, const char *dtype_name) : DataType()
109 {
110     id = p_opentype(loc, dtype_name);
111 }
112 
113 //--------------------------------------------------------------------------
114 // Function:    VarLenType overloaded constructor
115 ///\brief       Creates an VarLenType instance by opening an HDF5 variable
116 ///             length datatype given its name, provided as an \c H5std_string.
117 ///\param       loc        - IN: Location of the type
118 ///\param       dtype_name - IN: Variable length type name
119 ///\exception   H5::DataTypeIException
120 // Programmer   Binh-Minh Ribler - Dec 2016
121 // Description
122 //              In 1.10.1, this constructor was introduced and may replace the
123 //              existing function CommonFG::openVarLenType(const H5std_string&)
124 //              to improve usability.
125 //              -BMR, Dec 2016
126 //--------------------------------------------------------------------------
VarLenType(const H5Location & loc,const H5std_string & dtype_name)127 VarLenType::VarLenType(const H5Location& loc, const H5std_string& dtype_name) : DataType()
128 {
129     id = p_opentype(loc, dtype_name.c_str());
130 }
131 
132 //--------------------------------------------------------------------------
133 // Function:    VarLenType::decode
134 ///\brief       Returns an VarLenType object via DataType* by decoding the
135 ///             binary object description of this type.
136 ///
137 ///\exception   H5::DataTypeIException
138 // Programmer   Binh-Minh Ribler - Aug 2017
139 //--------------------------------------------------------------------------
decode() const140 DataType* VarLenType::decode() const
141 {
142     hid_t encoded_vltype_id = H5I_INVALID_HID;
143     try {
144         encoded_vltype_id = p_decode();
145     }
146     catch (DataTypeIException &err) {
147         throw;
148     }
149     VarLenType *encoded_vltype = new VarLenType;
150     encoded_vltype->p_setId(encoded_vltype_id);
151     return(encoded_vltype);
152 }
153 
154 //--------------------------------------------------------------------------
155 // Function:    VarLenType destructor
156 ///\brief       Properly terminates access to this datatype.
157 // Programmer   Binh-Minh Ribler - May, 2004
158 //--------------------------------------------------------------------------
~VarLenType()159 VarLenType::~VarLenType() {}
160 
161 } // end namespace
162