aqnwb 0.1.0
Loading...
Searching...
No Matches
Data.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4
5#include "io/BaseIO.hpp"
8
9namespace AQNWB::NWB
10{
15class Data : public RegisteredType
16{
17public:
18 // Register the Data class with the type registry
19 REGISTER_SUBCLASS(Data, "hdmf-common")
20
21
27 Data(const std::string& path, std::shared_ptr<IO::BaseIO> io);
28
32 virtual ~Data() override {}
33
43 {
44 auto dataset = m_io->createArrayDataSet(dataConfig, this->m_path);
45 if (dataset == nullptr) {
46 return Status::Failure;
47 }
48 // setup common attributes
49 Status commonAttrsStatus = m_io->createCommonNWBAttributes(
50 m_path, this->getNamespace(), this->getTypeName());
51 return commonAttrsStatus;
52 }
53
57 inline bool isInitialized() { return this->readData()->exists(); }
58
59 // Define the data fields to expose for lazy read access
60 DEFINE_DATASET_FIELD(readData, recordData, std::any, "", The main data)
61
63 std::string,
64 "neurodata_type",
65 The name of the type)
66
68 std::string,
69 "namespace",
70 The name of the namespace)
71};
72
87template<typename DTYPE = std::any>
88class DataTyped : public Data
89{
90public:
97 DataTyped(const std::string& path, std::shared_ptr<IO::BaseIO> io)
98 : Data(path, io)
99 {
100 }
101
105 virtual ~DataTyped() override {}
106
119 static std::shared_ptr<DataTyped<DTYPE>> fromData(const Data& data)
120 {
121 return std::make_shared<DataTyped<DTYPE>>(data.getPath(), data.getIO());
122 }
123
124 // Define the data fields to expose for lazy read access
125 DEFINE_DATASET_FIELD(readData, recordData, DTYPE, "", The main data)
126
129};
130} // 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:410
#define DEFINE_ATTRIBUTE_FIELD(name, default_type, fieldPath, description)
Defines a lazy-loaded attribute field accessor function.
Definition RegisteredType.hpp:443
#define DEFINE_DATASET_FIELD(readName, writeName, default_type, fieldPath, description)
Defines a lazy-loaded dataset field accessor function.
Definition RegisteredType.hpp:475
The configuration for an array dataset.
Definition BaseIO.hpp:200
bool isInitialized()
Check whether the dataset has been initialized.
Definition Data.hpp:57
std::shared_ptr< IO::BaseRecordingData > recordData(bool reset=false)
virtual ~Data() override
Virtual destructor.
Definition Data.hpp:32
std::unique_ptr< IO::ReadDataWrapper< AttributeField, VTYPE > > readNeurodataType() const
std::unique_ptr< IO::ReadDataWrapper< AttributeField, VTYPE > > readNamespace() const
Status initialize(const IO::ArrayDataSetConfig &dataConfig)
Initialize the dataset for the Data object.
Definition Data.hpp:42
Data(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.cpp:9
std::unique_ptr< IO::ReadDataWrapper< DatasetField, VTYPE > > readData() const
static std::shared_ptr< DataTyped< DTYPE > > fromData(const Data &data)
Create a DataTyped object from a Data object.
Definition Data.hpp:119
DataTyped(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.hpp:97
std::shared_ptr< IO::BaseRecordingData > recordData(bool reset=false)
std::unique_ptr< IO::ReadDataWrapper< DatasetField, VTYPE > > readData() const
virtual ~DataTyped() override
Virtual destructor.
Definition Data.hpp:105
virtual std::string getTypeName() const
Get the name of the class type.
Definition RegisteredType.cpp:60
std::string m_path
The path of the registered type.
Definition RegisteredType.hpp:338
std::shared_ptr< IO::BaseIO > m_io
A shared pointer to the IO object.
Definition RegisteredType.hpp:343
virtual std::string getNamespace() const
Get the schema namespace of the class type.
Definition RegisteredType.cpp:67
RegisteredType(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
Constructor.
Definition RegisteredType.cpp:15
std::string getPath() const
Gets the path of the registered type.
Definition RegisteredType.hpp:71
std::shared_ptr< AQNWB::IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition RegisteredType.hpp:89
Namespace for all classes related to the NWB data standard.
Definition TimeSeries.hpp:13