6 #include "compat/gsl/gsl_assert" 7 #include "compat/gsl/gsl" 13 namespace Attributes {
30 std::vector<DataType>
data;
37 if (dimensionality.size() > 1)
return true;
47 Attribute(
const std::string &name, std::initializer_list<size_t> dims, std::initializer_list<DataType> data)
48 : name{ name }, dimensionality{ dims }, data{ data }
50 static_assert(icedb::Data_Types::Is_Valid_Data_Type<DataType>() ==
true,
51 "Attributes must be a valid data type");
65 virtual void _setAttributeParent(std::shared_ptr<H5::H5Object> obj) = 0;
66 virtual std::shared_ptr<H5::H5Object> _getAttributeParent()
const = 0;
70 bool doesAttributeExist(
const std::string &attributeName)
const;
72 static bool doesAttributeExist(gsl::not_null<const H5::H5Object*> parent,
const std::string &attributeName);
75 std::type_index getAttributeTypeId(
const std::string &attributeName)
const;
78 static std::type_index getAttributeTypeId(gsl::not_null<const H5::H5Object*> parent,
const std::string &attributeName);
82 std::type_index atype = getAttributeTypeId(attributeName);
83 if (atype ==
typeid(Type))
return true;
88 std::set<std::string> getAttributeNames()
const;
91 void deleteAttribute(
const std::string &attributeName);
103 template <
class DataType>
static void readAttributeData(
104 gsl::not_null<const H5::H5Object*> parent,
105 const std::string &attributeName,
106 std::vector<size_t> &dimensions,
107 std::vector<DataType> &
data);
116 template <
class DataType>
void readAttributeData(
117 const std::string &attributeName,
118 std::vector<size_t> &dimensions,
119 std::vector<DataType> &data)
const;
126 template <
class DataType>
void writeAttributeData(
127 const std::string &attributeName,
128 const std::vector<size_t> &dimensionas,
129 const std::vector<DataType> &data);
139 gsl::not_null<const H5::H5Object*> obj,
const std::string &attributeName)
163 Expects(attribute.
data.size() == sz);
176 const std::string &
name,
177 std::initializer_list<size_t> dims,
178 std::initializer_list<DataType> data) {
180 writeAttribute(attr);
Attribute(const std::string &name, std::initializer_list< size_t > dims, std::initializer_list< DataType > data)
Create a multi-dimensional attribute with pre-populated data.
std::vector< size_t > dimensionality
The attribute's dimensional span. NetCDF only accepts one-dimensional attributes. ...
void writeAttribute(const Attribute< DataType > &attribute)
Convenience function to write an Attribute to an object.
Attribute(const std::string &name, DataType val)
Create a zero-dimensional attribute with pre-populated data.
std::string name
The name of the attribute.
void writeAttribute(const std::string &name, std::initializer_list< size_t > dims, std::initializer_list< DataType > data)
Convenience function to write a small Attribute to an object, using initializer lists.
static Attribute< DataType > readAttribute(gsl::not_null< const H5::H5Object *> obj, const std::string &attributeName)
Convenience function to read an attribute's data and return an Attribute object.
std::vector< DataType > data
This is a virtual base class for objects that can have attributes. This includes tables, groups and HDF5 files.
bool isAttributeOfType(const std::string &attributeName) const
Is the type of the attribute "Type"?
Attribute< DataType > readAttribute(const std::string &attributeName) const
Convenience function to read an attribute's data and return an Attribute object.
This class defines an attribute.
bool isArray() const
Does this attribute span more than one dimension?
Attribute(const std::string &name)
Create an empty attribute.