summaryrefslogtreecommitdiffstats
path: root/c++/src/H5OcreatProp.cpp
blob: a5af9df299f0760903dfddb8cf2a9352ec6ef553 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#include <string>

#include "H5Include.h"
#include "H5Exception.h"
#include "H5IdComponent.h"
#include "H5PropList.h"
#include "H5OcreatProp.h"

namespace H5 {

#ifndef DOXYGEN_SHOULD_SKIP_THIS
// This DOXYGEN_SHOULD_SKIP_THIS block is a work-around approach to control
// the order of creation and deletion of the global constants.  See Design Notes
// in "H5PredType.cpp" for information.

// Initialize a pointer for the constant
ObjCreatPropList *ObjCreatPropList::DEFAULT_ = 0;

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList::getConstant
//              Creates a ObjCreatPropList object representing the HDF5 constant
//              H5P_FILE_ACCESS, pointed to by ObjCreatPropList::DEFAULT_
// exception    H5::PropListIException
// Description
//              If ObjCreatPropList::DEFAULT_ already points to an allocated
//              object, throw a PropListIException.  This scenario should not
//              happen.
// Programmer   Binh-Minh Ribler - 2015
//--------------------------------------------------------------------------
ObjCreatPropList *
ObjCreatPropList::getConstant()
{
    // Tell the C library not to clean up, H5Library::termH5cpp will call
    // H5close - more dependency if use H5Library::dontAtExit()
    if (!IdComponent::H5dontAtexit_called) {
        (void)H5dont_atexit();
        IdComponent::H5dontAtexit_called = true;
    }

    // If the constant pointer is not allocated, allocate it. Otherwise,
    // throw because it shouldn't be.
    if (DEFAULT_ == 0)
        DEFAULT_ = new ObjCreatPropList(H5P_OBJECT_CREATE);
    else
        throw PropListIException("ObjCreatPropList::getConstant",
                                 "ObjCreatPropList::getConstant is being invoked on an allocated DEFAULT_");
    return (DEFAULT_);
}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList::deleteConstants
// Purpose:     Deletes the constant object that ObjCreatPropList::DEFAULT_
//              points to.
// exception    H5::PropListIException
// Programmer   Binh-Minh Ribler - 2015
//--------------------------------------------------------------------------
void
ObjCreatPropList::deleteConstants()
{
    if (DEFAULT_ != 0)
        delete DEFAULT_;
}

//--------------------------------------------------------------------------
// Purpose:     Constant for default property
//--------------------------------------------------------------------------
const ObjCreatPropList &ObjCreatPropList::DEFAULT = *getConstant();

#endif // DOXYGEN_SHOULD_SKIP_THIS

//--------------------------------------------------------------------------
// Function:    Default Constructor
///\brief       Creates a file access property list
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ObjCreatPropList::ObjCreatPropList() : PropList(H5P_OBJECT_CREATE) {}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList copy constructor
///\brief       Copy constructor: same HDF5 object as \a original
///\param       original - IN: ObjCreatPropList instance to copy
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ObjCreatPropList::ObjCreatPropList(const ObjCreatPropList &original) : PropList(original) {}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList overloaded constructor
///\brief       Creates a file access property list using the id of an
///             existing one.
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ObjCreatPropList::ObjCreatPropList(const hid_t plist_id) : PropList(plist_id) {}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList::setAttrPhaseChange
///\brief       Sets attribute storage phase change thresholds.
///\param       max_compact - IN: Maximum number of attributes to be stored in
///                               compact storage.  Default to 8
///\param       min_dense   - IN: Minimum number of attributes to be stored in
///                               dense storage.  Default to 6
///\exception   H5::PropListIException
///\par Description
///             If \c max_compact is set to 0, dense storage will be used.
///             For more detail about on attribute storage, please refer to the
///             H5Pset_attr_phase_change API in the HDF5 C Reference Manual.
// Programmer   Binh-Minh Ribler - September 2015
//--------------------------------------------------------------------------
void
ObjCreatPropList::setAttrPhaseChange(unsigned max_compact, unsigned min_dense) const
{
    herr_t ret_value = H5Pset_attr_phase_change(id, max_compact, min_dense);
    if (ret_value < 0) {
        throw PropListIException("ObjCreatPropList::setAttrPhaseChange", "H5Pset_attr_phase_change failed");
    }
}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList::getAttrPhaseChange
///\brief       Gets attribute storage phase change thresholds.
///\param       max_compact - OUT: Maximum number of attributes to be stored in
///                               compact storage.
///\param       min_dense   - OUT: Minimum number of attributes to be stored in
///                               dense storage.
///\exception   H5::PropListIException
///\par Description
///             If \c max_compact is set to 0, dense storage will be used.
///             For more detail about on attribute storage, please refer to the
///             H5Pget_attr_phase_change API in the HDF5 C Reference Manual.
// Programmer   Binh-Minh Ribler - September 2015
//--------------------------------------------------------------------------
void
ObjCreatPropList::getAttrPhaseChange(unsigned &max_compact, unsigned &min_dense) const
{
    herr_t ret_value;
    ret_value = H5Pget_attr_phase_change(id, &max_compact, &min_dense);
    if (ret_value < 0) {
        throw PropListIException("ObjCreatPropList::getAttrPhaseChange", "H5Pget_attr_phase_change failed");
    }
}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList::setAttrCrtOrder
///\brief       Set the flags for creation order of attributes on an object
///\param       crt_order_flags  - IN: Flags specifying whether to track and
///                     index attribute creation order.  Default: No flag set
///\exception   H5::PropListIException
///\par Description
///             Valid flags are:
///             \li \c H5P_CRT_ORDER_TRACKED - Attribute creation order is tracked
///             \li \c H5P_CRT_ORDER_INDEXED - Attribute creation order is
///                              indexed (requires H5P_CRT_ORDER_TRACKED).
///             When no flag is set, attribute creation order is neither
///             tracked not indexed.  Note that HDF5 currently provides no
///             mechanism to turn on attribute creation order tracking at object
///             creation time and to build the index later.
///             For detail, please refer to the H5Pset_attr_creation_order API
///             in the HDF5 C Reference Manual.
// Programmer   Binh-Minh Ribler - September 2015
//--------------------------------------------------------------------------
void
ObjCreatPropList::setAttrCrtOrder(unsigned crt_order_flags) const
{
    herr_t ret_value = H5Pset_attr_creation_order(id, crt_order_flags);
    if (ret_value < 0) {
        throw PropListIException("ObjCreatPropList::setAttrCrtOrder", "H5Pset_attr_creation_order failed");
    }
}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList::getAttrCrtOrder
///\brief       Returns the flags indicating creation order is tracked/indexed
///             for attributes on an object.
///\return      The flags
///\exception   H5::PropListIException
///\par Description
///             When no flag is set, i.e. crt_order_flags = 0, attribute
///             creation order is neither tracked not indexed.
///             For detail, please refer to the H5Pget_attr_creation_order API
///             in the HDF5 C Reference Manual.
// Programmer   Binh-Minh Ribler - September 2015
//--------------------------------------------------------------------------
unsigned
ObjCreatPropList::getAttrCrtOrder() const
{
    herr_t   ret_value;
    unsigned crt_order_flags = 0;
    ret_value                = H5Pget_attr_creation_order(id, &crt_order_flags);
    if (ret_value < 0) {
        throw PropListIException("ObjCreatPropList::getAttrCrtOrder", "H5Pget_attr_creation_order failed");
    }
    return (crt_order_flags);
}

//--------------------------------------------------------------------------
// Function:    ObjCreatPropList destructor
///\brief       Noop destructor
// Programmer   Binh-Minh Ribler - 2000
//--------------------------------------------------------------------------
ObjCreatPropList::~ObjCreatPropList() {}

} // namespace H5