icedb  version 0.5.1
Snow particle scattering database API
Classes | Functions
icedb::Attributes Namespace Reference

Contains everything concerning attributes. More...

Classes

class  Attribute
 This class defines an attribute. More...
 
class  CanHaveAttributes
 This is a virtual base class for objects that can have attributes. This includes tables, groups and HDF5 files. More...
 
class  CanHaveAttributes_impl
 
class  Checked_Existing_Attribute
 An encapsulating class that ensures that an attribute exists before it is accessed. More...
 

Functions

template<class DataType >
constexpr bool isString ()
 Used to flag string types for special treatment. More...
 
template<>
constexpr bool isString< std::string > ()
 
template<class DataType >
void pullData (const std::string &attributeName, std::vector< size_t > &dims, std::vector< DataType > &tdata, gsl::not_null< const H5::H5Object *> obj)
 Template function to pull data from the HDF5 object. More...
 
 INST_ATTR (INST_READ_ATTR_TYPE)
 
template<class DataType , class ObjectType >
void pushData (const std::string &attributeName, const std::vector< size_t > &dimensionality, std::shared_ptr< ObjectType > obj, const std::vector< DataType > &data, bool forceArray=false)
 
 INST_ATTR (INST_WRITE_ATTR_TYPE)
 

Detailed Description

Contains everything concerning attributes.

Function Documentation

◆ INST_ATTR() [1/2]

icedb::Attributes::INST_ATTR ( INST_READ_ATTR_TYPE  )

◆ INST_ATTR() [2/2]

icedb::Attributes::INST_ATTR ( INST_WRITE_ATTR_TYPE  )

◆ isString()

template<class DataType >
constexpr bool icedb::Attributes::isString ( )

Used to flag string types for special treatment.

Definition at line 109 of file Attributes.cpp.

109 { return false; }

◆ isString< std::string >()

template<>
constexpr bool icedb::Attributes::isString< std::string > ( )

Definition at line 110 of file Attributes.cpp.

110 { return true; }

◆ pullData()

template<class DataType >
void icedb::Attributes::pullData ( const std::string &  attributeName,
std::vector< size_t > &  dims,
std::vector< DataType > &  tdata,
gsl::not_null< const H5::H5Object *>  obj 
)

Template function to pull data from the HDF5 object.

Use HDF5 function to query the dataspace, to first see if it is an array, a vector (not a std::vector), or a scalar value. Get and set dimensions, then resize the input data array. Then, read data and copy into the appropriate Variant buffer (data).

Note
Assumes that the attribute exists (must be checked by calling function).
Todo:
Use Checked_Existing_Attribute
See also
Checked_Existing_Attribute
Todo:
Change code when reading multiple strings

Definition at line 119 of file Attributes.cpp.

References icedb::fs::hdf5::ARRAY, icedb::fs::hdf5::BASIC, icedb::fs::hdf5::getAttributeGroupingType(), icedb::fs::hdf5::readAttr(), icedb::fs::hdf5::readAttrArray(), icedb::fs::hdf5::readAttrVector(), icedb::fs::hdf5::STRING, and icedb::fs::hdf5::VLEN.

124  {
128 
129  const icedb::fs::hdf5::DataContainerType datatype = icedb::fs::hdf5::getAttributeGroupingType(obj, attributeName.c_str());
131  icedb::fs::hdf5::readAttrVector(obj, attributeName.c_str(), tdata);
132  dims.resize(1, tdata.size());
133  }
134  else if (datatype == icedb::fs::hdf5::DataContainerType::ARRAY) {
135  icedb::fs::hdf5::readAttrArray(obj, attributeName.c_str(), dims, tdata);
136  }
137  else if (datatype == icedb::fs::hdf5::DataContainerType::STRING) {
139  tdata.resize(1);
140  icedb::fs::hdf5::readAttr(obj, attributeName.c_str(), tdata[0]);
141  //throw;
142  }
143  else if (datatype == icedb::fs::hdf5::DataContainerType::VLEN) {
144  throw;
145  }
146  else throw;
147  }
DataContainerType getAttributeGroupingType(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname)
void readAttrVector(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, std::vector< DataType > &value)
Reads an array (or vector) of objects.
void readAttr(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, DataType &value)
Convenient template to read an attribute of a variable.
void readAttrArray(gsl::not_null< Container *> obj, gsl::not_null< const char *> attname, std::vector< size_t > &dims, std::vector< DataType > &value)
Reads an array (or vector) of objects.
Here is the call graph for this function:

◆ pushData()

template<class DataType , class ObjectType >
void icedb::Attributes::pushData ( const std::string &  attributeName,
const std::vector< size_t > &  dimensionality,
std::shared_ptr< ObjectType >  obj,
const std::vector< DataType > &  data,
bool  forceArray = false 
)
Todo:
Re-work the internal logic to allow multiple string writes into a single attribute.

Definition at line 193 of file Attributes.cpp.

200  {
201  size_t numElems = 1;
202  for (const auto &s : dimensionality) numElems *= s;
203  Expects(numElems > 0);
204 
205  if (isString<DataType>()) {
207  Expects(dimensionality.size() == 1);
208  Expects(dimensionality[0] == 1);
209  icedb::fs::hdf5::addAttr<DataType, ObjectType>(obj.get(), attributeName.c_str(), data[0]);
210  }
211  else {
212  if ((dimensionality.size() == 1) && !forceArray)
213  icedb::fs::hdf5::addAttrVector<DataType, ObjectType>(obj.get(), attributeName.c_str(), data);
214  else icedb::fs::hdf5::addAttrArray<DataType, ObjectType>(obj.get(), attributeName.c_str(), dimensionality, data);
215  }
216  }