3 #include "compat/gsl/gsl" 4 #include "compat/gsl/gsl_assert" 5 #include "compat/gsl/span" 21 virtual void _setTableSelf(std::shared_ptr<H5::DataSet> obj) = 0;
23 virtual std::shared_ptr<H5::DataSet> _getTableSelf()
const = 0;
27 Table(
const std::string &name =
"");
45 size_t getNumDimensions()
const;
47 Dimensions_Type getDimensions()
const;
50 void attachDimensionScale(
size_t DimensionNumber, gsl::not_null<const Table *> scale);
51 void detachDimensionScale(
size_t DimensionNumber, gsl::not_null<const Table *> scale);
56 bool isDimensionScale()
const;
59 void setDimensionScale(
const std::string &dimensionScaleName);
61 void setDimensionScaleAxisLabel(
size_t DimensionNumber,
const std::string &label);
63 std::string getDimensionScaleAxisLabel(
size_t DimensionNumber)
const;
65 std::string getDimensionScaleName()
const;
69 std::type_index atype = getTableTypeId();
70 if (atype ==
typeid(Type))
return true;
75 std::type_index getTableTypeId()
const;
83 template <
class DataType>
84 void readAll(std::vector<size_t> &dims, std::vector<DataType> &data)
const;
90 template <
class DataType>
91 void writeAllInner(
const gsl::span<const DataType> &outData)
const;
99 template <
class DataType>
100 void writeAll(
const gsl::span<const DataType> &outData)
const {
101 static_assert(icedb::Data_Types::Is_Valid_Data_Type<DataType>() ==
true,
102 "Data to be written must be a valid data type");
103 this->
template writeAllInner<DataType>(outData);
110 template <
class DataType>
111 void writeAll(
const gsl::span<DataType> &outData)
const {
112 this->
template writeAll<DataType>(gsl::span<const DataType>(outData.cbegin(), outData.cend()));
119 template <
class DataType>
120 void writeAll(
const std::vector<DataType> &outData)
const {
121 this->
template writeAll<DataType>(gsl::span<const DataType>(outData.data(), outData.size()));
134 void _createTable(
const std::string &tableName,
const std::type_index& type,
const std::vector<size_t> &dims,
const std::vector<size_t> &chunks);
139 virtual void _setTablesParent(std::shared_ptr<H5::Group> obj) = 0;
141 virtual std::shared_ptr<H5::Group> _getTablesParent()
const = 0;
145 std::set<std::string> getTableNames()
const;
147 bool doesTableExist(
const std::string &tableName)
const;
151 void unlinkTable(
const std::string &tableName);
171 template <
class DataType>
173 Expects(!doesTableExist(tableName));
174 std::vector<size_t> chunksGuess;
176 chunksGuess = getChunkStrategy(dims);
177 chunks = &chunksGuess;
179 _createTable(tableName, Data_Types::getType<DataType>(), dims, *chunks);
180 return openTable(tableName);
192 template <
class DataType>
194 const std::string &tableName,
195 std::initializer_list<size_t> dims,
196 const std::vector<size_t> *chunks =
nullptr)
198 std::vector<size_t> vdims{ dims };
199 auto tbl = createTable<DataType>(tableName, vdims, chunks);
213 template <
class DataType>
215 const std::string &tableName,
216 std::initializer_list<size_t> dims,
217 std::initializer_list<DataType> data,
218 const std::vector<size_t> *chunks =
nullptr)
220 auto tbl = createTable<DataType>(tableName, dims, chunks);
222 tbl->template writeAll<DataType>(gsl::span<const DataType>(data.begin(), data.end()));
236 template <
class DataType>
238 const std::string &tableName,
239 std::initializer_list<size_t> dims,
240 const std::vector<DataType> &data,
241 const std::vector<size_t> *chunks =
nullptr)
243 auto tbl = createTable<DataType>(tableName, dims, chunks);
244 tbl->template writeAll<DataType>(data);
258 template <
class DataType>
260 const std::string &tableName,
261 std::initializer_list<size_t> dims,
262 const gsl::span<DataType> &data,
263 const std::vector<size_t> *chunks =
nullptr)
265 auto tbl = createTable<DataType>(tableName, dims, chunks);
266 tbl->template writeAll<DataType>(data);
280 template <
class DataType>
282 const std::string &tableName,
283 std::initializer_list<size_t> dims,
284 const gsl::span<const DataType> &data,
285 const std::vector<size_t> *chunks =
nullptr)
287 auto tbl = createTable<DataType>(tableName, dims, chunks);
288 tbl->template writeAll<DataType>(data);
bool isTableOfType() const
Check if this table has the matching Type.
std::unique_ptr< Table > Table_Type
The preferred method of access of a Table is through std::unique_ptr.
const std::string name
The name of the Table.
void writeAll(const gsl::span< DataType > &outData) const
Write the passed data to the table. Writes whole table.
Table::Table_Type createTable(const std::string &tableName, const std::vector< size_t > &dims, const std::vector< size_t > *chunks=nullptr)
Create a table.
The virtual base class used in all objects that can contain tables (groups and datasets).
void writeAll(const std::vector< DataType > &outData) const
Write the passed data to the table. Writes whole table. Convenience converter function.
Table::Table_Type createTable(const std::string &tableName, std::initializer_list< size_t > dims, const gsl::span< const DataType > &data, const std::vector< size_t > *chunks=nullptr)
Create a table and sets the table's initial data.
Table::Table_Type createTable(const std::string &tableName, std::initializer_list< size_t > dims, const std::vector< DataType > &data, const std::vector< size_t > *chunks=nullptr)
Create a table and sets the table's initial data.
std::vector< size_t > Dimensions_Type
The dimensions of a Table are expressed as a vector of unsigned integers.
This is a virtual base class for objects that can have attributes. This includes tables, groups and HDF5 files.
Table::Table_Type createTable(const std::string &tableName, std::initializer_list< size_t > dims, const gsl::span< DataType > &data, const std::vector< size_t > *chunks=nullptr)
Create a table and sets the table's initial data.
void writeAll(const gsl::span< const DataType > &outData) const
Write the passed data to the table. Writes whole table.
Table::Table_Type createTable(const std::string &tableName, std::initializer_list< size_t > dims, const std::vector< size_t > *chunks=nullptr)
Create a table.
Table::Table_Type createTable(const std::string &tableName, std::initializer_list< size_t > dims, std::initializer_list< DataType > data, const std::vector< size_t > *chunks=nullptr)
Create a table and writes initial data. Used with small tables.
std::vector< size_t > getChunkStrategy(const std::vector< size_t > &dims)
The default chunking strategy for this table. Used for storage i/o speed, and for compression...