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 
22 namespace H5 {
23 
24 #ifndef DOXYGEN_SHOULD_SKIP_THIS
25 // This DOXYGEN_SHOULD_SKIP_THIS block is a work-around approach to control
26 // the order of creation and deletion of the global constants.  See Design Notes
27 // in "H5PredType.cpp" for information.
28 
29 // Initialize a pointer for the constant
30 ObjCreatPropList* ObjCreatPropList::DEFAULT_ = 0;
31 
32 //--------------------------------------------------------------------------
33 // Function:    ObjCreatPropList::getConstant
34 //              Creates a ObjCreatPropList object representing the HDF5 constant
35 //              H5P_FILE_ACCESS, pointed to by ObjCreatPropList::DEFAULT_
36 // exception    H5::PropListIException
37 // Description
38 //              If ObjCreatPropList::DEFAULT_ already points to an allocated
39 //              object, throw a PropListIException.  This scenario should not
40 //              happen.
41 // Programmer   Binh-Minh Ribler - 2015
42 //--------------------------------------------------------------------------
getConstant()43 ObjCreatPropList* ObjCreatPropList::getConstant()
44 {
45     // Tell the C library not to clean up, H5Library::termH5cpp will call
46     // H5close - more dependency if use H5Library::dontAtExit()
47     if (!IdComponent::H5dontAtexit_called)
48     {
49         (void) H5dont_atexit();
50         IdComponent::H5dontAtexit_called = true;
51     }
52 
53     // If the constant pointer is not allocated, allocate it. Otherwise,
54     // throw because it shouldn't be.
55     if (DEFAULT_ == 0)
56         DEFAULT_ = new ObjCreatPropList(H5P_OBJECT_CREATE);
57     else
58         throw PropListIException("ObjCreatPropList::getConstant", "ObjCreatPropList::getConstant is being invoked on an allocated DEFAULT_");
59     return(DEFAULT_);
60 }
61 
62 //--------------------------------------------------------------------------
63 // Function:    ObjCreatPropList::deleteConstants
64 // Purpose:     Deletes the constant object that ObjCreatPropList::DEFAULT_
65 //              points to.
66 // exception    H5::PropListIException
67 // Programmer   Binh-Minh Ribler - 2015
68 //--------------------------------------------------------------------------
deleteConstants()69 void ObjCreatPropList::deleteConstants()
70 {
71     if (DEFAULT_ != 0)
72         delete DEFAULT_;
73 }
74 
75 //--------------------------------------------------------------------------
76 // Purpose:     Constant for default property
77 //--------------------------------------------------------------------------
78 const ObjCreatPropList& ObjCreatPropList::DEFAULT = *getConstant();
79 
80 #endif // DOXYGEN_SHOULD_SKIP_THIS
81 
82 //--------------------------------------------------------------------------
83 // Function:    Default Constructor
84 ///\brief       Creates a file access property list
85 // Programmer   Binh-Minh Ribler - 2000
86 //--------------------------------------------------------------------------
ObjCreatPropList()87 ObjCreatPropList::ObjCreatPropList() : PropList(H5P_OBJECT_CREATE) {}
88 
89 //--------------------------------------------------------------------------
90 // Function:    ObjCreatPropList copy constructor
91 ///\brief       Copy constructor: same HDF5 object as \a original
92 ///\param       original - IN: ObjCreatPropList instance to copy
93 // Programmer   Binh-Minh Ribler - 2000
94 //--------------------------------------------------------------------------
ObjCreatPropList(const ObjCreatPropList & original)95 ObjCreatPropList::ObjCreatPropList(const ObjCreatPropList& original) : PropList(original) {}
96 
97 //--------------------------------------------------------------------------
98 // Function:    ObjCreatPropList overloaded constructor
99 ///\brief       Creates a file access property list using the id of an
100 ///             existing one.
101 // Programmer   Binh-Minh Ribler - 2000
102 //--------------------------------------------------------------------------
ObjCreatPropList(const hid_t plist_id)103 ObjCreatPropList::ObjCreatPropList(const hid_t plist_id) : PropList(plist_id) {}
104 
105 //--------------------------------------------------------------------------
106 // Function:    ObjCreatPropList::setAttrPhaseChange
107 ///\brief       Sets attribute storage phase change thresholds.
108 ///\param       max_compact - IN: Maximum number of attributes to be stored in
109 ///                               compact storage.  Default to 8
110 ///\param       min_dense   - IN: Minimum number of attributes to be stored in
111 ///                               dense storage.  Default to 6
112 ///\exception   H5::PropListIException
113 ///\par Description
114 ///             If \c max_compact is set to 0, dense storage will be used.
115 ///             For more detail about on attribute storage, please refer to the
116 ///             H5Pset_attr_phase_change API in the HDF5 C Reference Manual.
117 // Programmer   Binh-Minh Ribler - September 2015
118 //--------------------------------------------------------------------------
setAttrPhaseChange(unsigned max_compact,unsigned min_dense) const119 void ObjCreatPropList::setAttrPhaseChange(unsigned max_compact, unsigned min_dense) const
120 {
121     herr_t ret_value = H5Pset_attr_phase_change(id, max_compact, min_dense);
122     if (ret_value < 0)
123     {
124         throw PropListIException("ObjCreatPropList::setAttrPhaseChange", "H5Pset_attr_phase_change failed");
125     }
126 }
127 
128 //--------------------------------------------------------------------------
129 // Function:    ObjCreatPropList::getAttrPhaseChange
130 ///\brief       Gets attribute storage phase change thresholds.
131 ///\param       max_compact - OUT: Maximum number of attributes to be stored in
132 ///                               compact storage.
133 ///\param       min_dense   - OUT: Minimum number of attributes to be stored in
134 ///                               dense storage.
135 ///\exception   H5::PropListIException
136 ///\par Description
137 ///             If \c max_compact is set to 0, dense storage will be used.
138 ///             For more detail about on attribute storage, please refer to the
139 ///             H5Pget_attr_phase_change API in the HDF5 C Reference Manual.
140 // Programmer   Binh-Minh Ribler - September 2015
141 //--------------------------------------------------------------------------
getAttrPhaseChange(unsigned & max_compact,unsigned & min_dense) const142 void ObjCreatPropList::getAttrPhaseChange(unsigned& max_compact, unsigned& min_dense) const
143 {
144     herr_t ret_value;
145     ret_value = H5Pget_attr_phase_change(id, &max_compact, &min_dense);
146     if (ret_value < 0)
147     {
148         throw PropListIException("ObjCreatPropList::getAttrPhaseChange", "H5Pget_attr_phase_change failed");
149     }
150 }
151 
152 //--------------------------------------------------------------------------
153 // Function:    ObjCreatPropList::setAttrCrtOrder
154 ///\brief       Set the flags for creation order of attributes on an object
155 ///\param       crt_order_flags  - IN: Flags specifying whether to track and
156 ///                     index attribute creation order.  Default: No flag set
157 ///\exception   H5::PropListIException
158 ///\par Description
159 ///             Valid flags are:
160 ///             \li \c H5P_CRT_ORDER_TRACKED - Attribute creation order is tracked
161 ///             \li \c H5P_CRT_ORDER_INDEXED - Attribute creation order is
162 ///                              indexed (requires H5P_CRT_ORDER_TRACKED).
163 ///             When no flag is set, attribute creation order is neither
164 ///             tracked not indexed.  Note that HDF5 currently provides no
165 ///             mechanism to turn on attribute creation order tracking at object
166 ///             creation time and to build the index later.
167 ///             For detail, please refer to the H5Pset_attr_creation_order API
168 ///             in the HDF5 C Reference Manual.
169 // Programmer   Binh-Minh Ribler - September 2015
170 //--------------------------------------------------------------------------
setAttrCrtOrder(unsigned crt_order_flags) const171 void ObjCreatPropList::setAttrCrtOrder(unsigned crt_order_flags) const
172 {
173     herr_t ret_value = H5Pset_attr_creation_order(id, crt_order_flags);
174     if (ret_value < 0)
175     {
176         throw PropListIException("ObjCreatPropList::setAttrCrtOrder", "H5Pset_attr_creation_order failed");
177     }
178 }
179 
180 //--------------------------------------------------------------------------
181 // Function:    ObjCreatPropList::getAttrCrtOrder
182 ///\brief       Returns the flags indicating creation order is tracked/indexed
183 ///             for attributes on an object.
184 ///\return      The flags
185 ///\exception   H5::PropListIException
186 ///\par Description
187 ///             When no flag is set, i.e. crt_order_flags = 0, attribute
188 ///             creation order is neither tracked not indexed.
189 ///             For detail, please refer to the H5Pget_attr_creation_order API
190 ///             in the HDF5 C Reference Manual.
191 // Programmer   Binh-Minh Ribler - September 2015
192 //--------------------------------------------------------------------------
getAttrCrtOrder() const193 unsigned ObjCreatPropList::getAttrCrtOrder() const
194 {
195     herr_t ret_value;
196     unsigned crt_order_flags = 0;
197     ret_value = H5Pget_attr_creation_order(id, &crt_order_flags);
198     if (ret_value < 0)
199     {
200         throw PropListIException("ObjCreatPropList::getAttrCrtOrder", "H5Pget_attr_creation_order failed");
201     }
202     return(crt_order_flags);
203 }
204 
205 //--------------------------------------------------------------------------
206 // Function:    ObjCreatPropList destructor
207 ///\brief       Noop destructor
208 // Programmer   Binh-Minh Ribler - 2000
209 //--------------------------------------------------------------------------
~ObjCreatPropList()210 ObjCreatPropList::~ObjCreatPropList() {}
211 
212 } // end namespace
213