aqnwb 0.1.0
Loading...
Searching...
No Matches
DynamicTable.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
5#include "Utils.hpp"
6#include "io/BaseIO.hpp"
7#include "io/ReadIO.hpp"
11
12namespace AQNWB::NWB
13{
21class DynamicTable : public Container
22{
23public:
24 // Register the TimeSeries as a subclass of Container
25 REGISTER_SUBCLASS(DynamicTable, "hdmf-common")
26
27
32 DynamicTable(const std::string& path, std::shared_ptr<IO::BaseIO> io);
33
37 virtual ~DynamicTable();
38
46 Status initialize(const std::string& description);
47
57
64 Status addColumn(std::unique_ptr<VectorData>& vectorData,
65 const std::vector<std::string>& values);
66
74 Status addReferenceColumn(const std::string& name,
75 const std::string& colDescription,
76 const std::vector<std::string>& dataset);
77
84 Status setRowIDs(std::unique_ptr<ElementIdentifiers>& elementIDs,
85 const std::vector<int>& values);
86
101 virtual void setColNames(const std::vector<std::string>& newColNames)
102 {
103 m_colNames = newColNames;
104 }
105
116 template<typename DTYPE = std::any>
117 std::shared_ptr<VectorDataTyped<DTYPE>> readColumn(const std::string& colName)
118 {
119 std::string columnPath = AQNWB::mergePaths(m_path, colName);
120 if (m_io->objectExists(columnPath)) {
121 if (m_io->getStorageObjectType(columnPath) == StorageObjectType::Dataset)
122 {
123 return std::make_shared<VectorDataTyped<DTYPE>>(columnPath, m_io);
124 }
125 }
126 return nullptr;
127 }
128
131 std::string,
132 "colnames",
133 The names of the columns in the table)
134
137 std::string,
138 "description",
139 Description of what is in this dynamic table)
140
144 "id",
145 "unique identifiers for the rows of this dynamic table")
146
147protected:
151 std::vector<std::string> m_colNames;
152};
153} // namespace AQNWB::NWB
AQNWB::Types::Status Status
Definition BaseIO.hpp:22
#define REGISTER_SUBCLASS(T, NAMESPACE)
Macro to register a subclass with the RegisteredType class registry.
Definition RegisteredType.hpp:373
#define DEFINE_FIELD(name, storageObjectType, default_type, fieldPath, description)
Defines a lazy-loaded field accessor function.
Definition RegisteredType.hpp:407
#define DEFINE_REGISTERED_FIELD(name, registeredType, fieldPath, description)
Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes.
Definition RegisteredType.hpp:439
Container(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Container.cpp:10
Status initialize()
Initialize the container.
Definition Container.cpp:20
std::vector< std::string > m_colNames
Names of the columns in the table.
Definition DynamicTable.hpp:151
Status setRowIDs(std::unique_ptr< ElementIdentifiers > &elementIDs, const std::vector< int > &values)
Adds a column of element identifiers to the table.
Definition DynamicTable.cpp:61
std::shared_ptr< VectorDataTyped< DTYPE > > readColumn(const std::string &colName)
Read an arbitrary column of the DyanmicTable.
Definition DynamicTable.hpp:117
virtual ~DynamicTable()
Destructor.
Definition DynamicTable.cpp:30
DynamicTable(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition DynamicTable.cpp:12
std::unique_ptr< IO::ReadDataWrapper< AttributeField, VTYPE > > readColNames() const
Status finalize()
Finalizes writing the DynamicTable.
Definition DynamicTable.cpp:100
Status addColumn(std::unique_ptr< VectorData > &vectorData, const std::vector< std::string > &values)
Adds a column of vector string data to the table.
Definition DynamicTable.cpp:43
Status addReferenceColumn(const std::string &name, const std::string &colDescription, const std::vector< std::string > &dataset)
Adds a column of references to the table.
Definition DynamicTable.cpp:80
std::unique_ptr< IO::ReadDataWrapper< AttributeField, VTYPE > > readDescription() const
virtual void setColNames(const std::vector< std::string > &newColNames)
Sets the column names of the DynamicTable.
Definition DynamicTable.hpp:101
std::shared_ptr< RTYPE > readIdColumn() const
A list of unique identifiers for values within a dataset, e.g. rows of a DynamicTable.
Definition ElementIdentifiers.hpp:12
std::string m_path
The path of the registered type.
Definition RegisteredType.hpp:318
std::shared_ptr< IO::BaseIO > m_io
A shared pointer to the IO object.
Definition RegisteredType.hpp:323
Namespace for all classes related to the NWB data standard.
Definition TimeSeries.hpp:12
constexpr auto AttributeField
Alias for AQNWB::Types::StorageObjectType::Attribute.
Definition RegisteredType.hpp:23
static std::string mergePaths(const std::string &path1, const std::string &path2)
Merge two paths into a single path, handling extra trailing and starting "/".
Definition Utils.hpp:112