Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Attributes | List of all members
Utopia::DataIO::HDFObject< objectcategory > Class Template Reference

Common base class for all HDF5 classes in the DATAIO Module i.e., for all classes that wrap HDF5-C-Library functionality like HDFDataset, HDFGroup, HDFFile. This class is not intendet as something to be used independently, but only as a base class to be inherited from. More...

#include <hdfobject.hh>

Collaboration diagram for Utopia::DataIO::HDFObject< objectcategory >:
Collaboration graph
[legend]

Public Member Functions

void swap (HDFObject &other)
 swap the state of the caller with the state of the argument
 
std::string get_path () const
 Get the name or path object.
 
auto get_id_object () const
 Get the id object.
 
auto get_logger () const
 Get the logger object.
 
hid_t get_C_id () const
 Get the C id object.
 
auto get_refcount ()
 Get the reference count of object.
 
virtual bool is_valid () const
 Check if the object is still valid.
 
void close ()
 Close function which takes care of correctly closing the object and managing the reference counter.
 
void bind_to (hid_t id, std::function< herr_t(hid_t) > closing_func, std::string path={})
 Open the object and bind it to a HDF5 object identified by 'id' with name 'path'. Object should be created beforehand.
 
 HDFObject ()
 Construct HDFObject from the given arguments.
 
 HDFObject (HDFObject &&other)
 Construct HDFObject by moving.
 
 HDFObject (const HDFObject &other)=default
 Construct HDFObject by copying another object.
 
 HDFObject (hid_t id, std::function< herr_t(hid_t) > closing_func, std::string path={})
 Construct HDFObject from the given argument.
 
HDFObjectoperator= (const HDFObject &other)
 Copy assignment operator.
 
HDFObjectoperator= (HDFObject &&other)
 move assignment operator
 
virtual ~HDFObject ()
 Destroy the HDFObject object. Has to be implemented in subclass!
 

Static Public Attributes

static constexpr HDFCategory category = objectcategory
 Named variable for template arg.
 

Protected Attributes

HDFIdentifier _id
 Identifier object that binds an instance of this class to an HDF5 object.
 
std::string _path
 Name of the object.
 
std::shared_ptr< spdlog::logger > _log
 pointer to the logger for dataio
 

Detailed Description

template<HDFCategory objectcategory>
class Utopia::DataIO::HDFObject< objectcategory >

Common base class for all HDF5 classes in the DATAIO Module i.e., for all classes that wrap HDF5-C-Library functionality like HDFDataset, HDFGroup, HDFFile. This class is not intendet as something to be used independently, but only as a base class to be inherited from.

Template Parameters
HDFCategorytype of object an instance of this class refers to

Constructor & Destructor Documentation

◆ HDFObject() [1/4]

template<HDFCategory objectcategory>
Utopia::DataIO::HDFObject< objectcategory >::HDFObject ( )
inline

Construct HDFObject from the given arguments.

246 : _id(), _path(""), _log(spdlog::get("data_io"))
247 {
248 }
std::string _path
Name of the object.
Definition hdfobject.hh:50
std::shared_ptr< spdlog::logger > _log
pointer to the logger for dataio
Definition hdfobject.hh:56
HDFIdentifier _id
Identifier object that binds an instance of this class to an HDF5 object.
Definition hdfobject.hh:44

◆ HDFObject() [2/4]

template<HDFCategory objectcategory>
Utopia::DataIO::HDFObject< objectcategory >::HDFObject ( HDFObject< objectcategory > &&  other)
inline

Construct HDFObject by moving.

254 :
255 _id(std::move(other._id)), _path(std::move(other._path)),
256 _log(std::move(other._log))
257 {
258 other._id.set_id(-1);
259 }
hid_t _id
Definition hdfidentifier.hh:30
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213

◆ HDFObject() [3/4]

template<HDFCategory objectcategory>
Utopia::DataIO::HDFObject< objectcategory >::HDFObject ( const HDFObject< objectcategory > &  other)
default

Construct HDFObject by copying another object.

◆ HDFObject() [4/4]

template<HDFCategory objectcategory>
Utopia::DataIO::HDFObject< objectcategory >::HDFObject ( hid_t  id,
std::function< herr_t(hid_t) >  closing_func,
std::string  path = {} 
)
inline

Construct HDFObject from the given argument.

Parameters
idC-Library identifier, by rvalue reference count. This is done such that the id is 'stolen' by this object and hence reference counts stay the same
pathName of the object
277 {}) :
278 _log(spdlog::get("data_io"))
279 {
280 bind_to(id, closing_func, path);
281 }
void bind_to(hid_t id, std::function< herr_t(hid_t) > closing_func, std::string path={})
Open the object and bind it to a HDF5 object identified by 'id' with name 'path'. Object should be cr...
Definition hdfobject.hh:186

◆ ~HDFObject()

template<HDFCategory objectcategory>
virtual Utopia::DataIO::HDFObject< objectcategory >::~HDFObject ( )
inlinevirtual

Destroy the HDFObject object. Has to be implemented in subclass!

322 {
323 close();
324 }
void close()
Close function which takes care of correctly closing the object and managing the reference counter.
Definition hdfobject.hh:161

Member Function Documentation

◆ bind_to()

template<HDFCategory objectcategory>
void Utopia::DataIO::HDFObject< objectcategory >::bind_to ( hid_t  id,
std::function< herr_t(hid_t) >  closing_func,
std::string  path = {} 
)
inline

Open the object and bind it to a HDF5 object identified by 'id' with name 'path'. Object should be created beforehand.

Parameters
idid of the object to bind to, by rvalue reference. This is made such that the given id is 'stolen' by this object and reference count remains unchanged
pathName or path of the object to bind to
188 {})
189 {
190 if (is_valid())
191 {
192 throw std::runtime_error("Error: Cannot bind object to new "
193 "identifier while the old is still valid");
194 }
195
196 if (not check_validity(H5Iis_valid(id), path))
197 {
198 throw std::invalid_argument(
199 "Error: invalid argument! The id given "
200 "for an object of " +
201 generate_object_name(*this) +
202 " cannot be managed by an HDFObject instance!");
203 }
204
205 _log->debug("Opening object of ", generate_object_name(*this));
206
207 _id.open(id, closing_func);
208
209 if (path.size() == 0)
210 {
211 // putting some stupid special treatments here because HDF5
212 // cannot handle things generically
213
214 // attribute has to be treated separately
215 if constexpr (category == HDFCategory::attribute)
216 {
217 _path.resize(H5Aget_name(id, 0, NULL) + 1);
218
219 H5Aget_name(id, _path.size(), _path.data());
220 }
221 else
222 {
223
224 // a preliminary call to H5Iget_name will give the needed size.
225 // cumbersome, but works. The +1 is for the null terminator
226 _path.resize(H5Iget_name(id, NULL, 0)+1);
227
228 // then, a second call will give the full name
229 H5Iget_name(id, _path.data(), _path.size());
230
231 }
232
233 // remove the final 0 character, as std::string does not require it
234 _path.pop_back();
235 }
236 else
237 {
238 _path = path;
239 }
240 }
void open(hid_t id, std::function< herr_t(hid_t) > closing_func)
Open the object and bind it to another C-Level id.
Definition hdfidentifier.hh:156
static constexpr HDFCategory category
Named variable for template arg.
Definition hdfobject.hh:63
virtual bool is_valid() const
Check if the object is still valid.
Definition hdfobject.hh:143
bool check_validity(htri_t valid, const std::string_view object_name)
Check for validity of a hdf5 htri_t type or similar.
Definition hdfutilities.hh:73
std::string generate_object_name(const Object &object)
Use category and path variable of object to make a string that identifies the object it is applied to...
Definition hdfutilities.hh:220

◆ close()

template<HDFCategory objectcategory>
void Utopia::DataIO::HDFObject< objectcategory >::close ( )
inline

Close function which takes care of correctly closing the object and managing the reference counter.

162 {
163
164 if (is_valid())
165 {
166 _id.close();
167
168 _path = "";
169 }
170 }
void close()
Close the identifier and render the C-Level id held invalid.
Definition hdfidentifier.hh:134

◆ get_C_id()

template<HDFCategory objectcategory>
hid_t Utopia::DataIO::HDFObject< objectcategory >::get_C_id ( ) const
inline

Get the C id object.

Returns
hid_t
121 {
122 return _id.get_id();
123 }
hid_t get_id() const
Get the HDF5 id held by this object.
Definition hdfidentifier.hh:53

◆ get_id_object()

template<HDFCategory objectcategory>
auto Utopia::DataIO::HDFObject< objectcategory >::get_id_object ( ) const
inline

Get the id object.

Returns
hid_t C-Library identifier held by this object
100 {
101 return _id;
102 }

◆ get_logger()

template<HDFCategory objectcategory>
auto Utopia::DataIO::HDFObject< objectcategory >::get_logger ( ) const
inline

Get the logger object.

Returns
auto
111 {
112 return _log;
113 }

◆ get_path()

template<HDFCategory objectcategory>
std::string Utopia::DataIO::HDFObject< objectcategory >::get_path ( ) const
inline

Get the name or path object.

Returns
std::string name of the object
89 {
90 return _path;
91 }

◆ get_refcount()

template<HDFCategory objectcategory>
auto Utopia::DataIO::HDFObject< objectcategory >::get_refcount ( )
inline

Get the reference count of object.

Returns
auto
132 {
133 return _id.get_refcount();
134 }
auto get_refcount() const
Get the number of references currently referring to the object identified by this ID.
Definition hdfidentifier.hh:89

◆ is_valid()

template<HDFCategory objectcategory>
virtual bool Utopia::DataIO::HDFObject< objectcategory >::is_valid ( ) const
inlinevirtual

Check if the object is still valid.

Returns
true
false

Reimplemented in Utopia::DataIO::HDFType.

144 {
145 if (get_C_id() == -1)
146 {
147 return false;
148 }
149 else
150 {
151 // use check_validity to provide correct name
153 }
154 }
hid_t get_C_id() const
Get the C id object.
Definition hdfobject.hh:120

◆ operator=() [1/2]

Copy assignment operator.

Parameters
other
Returns
HDFObject&
291 {
292 _id = other._id;
293 _path = other._path;
294 _log = other._log;
295
296 return *this;
297 }

◆ operator=() [2/2]

template<HDFCategory objectcategory>
HDFObject & Utopia::DataIO::HDFObject< objectcategory >::operator= ( HDFObject< objectcategory > &&  other)
inline

move assignment operator

Parameters
other
Returns
HDFObject&
307 {
308 _id = std::move(other._id);
309 _path = std::move(other._path);
310 _log = std::move(other._log);
311
312 other._id.set_id(-1);
313
314 return *this;
315 }

◆ swap()

template<HDFCategory objectcategory>
void Utopia::DataIO::HDFObject< objectcategory >::swap ( HDFObject< objectcategory > &  other)
inline

swap the state of the caller with the state of the argument

Parameters
other
72 {
73 using std::swap;
74 swap(_id, other._id);
75 swap(_path, other._path);
76 swap(_log, other._log);
77 }
void swap(HDFObject &other)
swap the state of the caller with the state of the argument
Definition hdfobject.hh:71

Member Data Documentation

◆ _id

template<HDFCategory objectcategory>
HDFIdentifier Utopia::DataIO::HDFObject< objectcategory >::_id
protected

Identifier object that binds an instance of this class to an HDF5 object.

◆ _log

template<HDFCategory objectcategory>
std::shared_ptr< spdlog::logger > Utopia::DataIO::HDFObject< objectcategory >::_log
protected

pointer to the logger for dataio

◆ _path

template<HDFCategory objectcategory>
std::string Utopia::DataIO::HDFObject< objectcategory >::_path
protected

Name of the object.

◆ category

template<HDFCategory objectcategory>
constexpr HDFCategory Utopia::DataIO::HDFObject< objectcategory >::category = objectcategory
staticconstexpr

Named variable for template arg.


The documentation for this class was generated from the following file: