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"
7
8namespace AQNWB::NWB
9{
14class Data : public RegisteredType
15{
16public:
17 REGISTER_SUBCLASS(Data, "hdmf-common")
18
19
25 Data(const std::string& path, std::shared_ptr<IO::BaseIO> io);
26
30 virtual ~Data() override {}
31
41 Status initialize(std::unique_ptr<IO::BaseRecordingData>&& dataset)
42 {
43 m_dataset = std::move(dataset);
44 // setup common attributes
45 Status commonAttrsStatus = m_io->createCommonNWBAttributes(
46 m_path, this->getNamespace(), this->getTypeName());
47 return commonAttrsStatus;
48 }
49
53 inline bool isInitialized() { return m_dataset != nullptr; }
54
55 // Define the data fields to expose for lazy read access
56 DEFINE_FIELD(readData, DatasetField, std::any, "", The main data)
57
60 std::string,
61 "neurodata_type",
62 The name of the type)
63
66 std::string,
67 "namespace",
68 The name of the namespace)
69
70 std::unique_ptr<IO::BaseRecordingData> m_dataset;
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_FIELD(readData, DatasetField, 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:373
#define DEFINE_FIELD(name, storageObjectType, default_type, fieldPath, description)
Defines a lazy-loaded field accessor function.
Definition RegisteredType.hpp:407
bool isInitialized()
Check whether the m_dataset has been initialized.
Definition Data.hpp:53
virtual ~Data() override
Virtual destructor.
Definition Data.hpp:30
Status initialize(std::unique_ptr< IO::BaseRecordingData > &&dataset)
Initialize the dataset for the Data object.
Definition Data.hpp:41
std::unique_ptr< IO::ReadDataWrapper< AttributeField, VTYPE > > readNeurodataType() const
std::unique_ptr< IO::ReadDataWrapper< AttributeField, VTYPE > > readNamespace() const
std::unique_ptr< IO::BaseRecordingData > m_dataset
Definition Data.hpp:70
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::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:318
RegisteredType(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition RegisteredType.cpp:15
std::shared_ptr< IO::BaseIO > m_io
A shared pointer to the IO object.
Definition RegisteredType.hpp:323
virtual std::string getNamespace() const
Get the schema namespace of the class type.
Definition RegisteredType.cpp:67
std::string getPath() const
Gets the path of the registered type.
Definition RegisteredType.hpp:70
std::shared_ptr< IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition RegisteredType.hpp:88
Definition BaseIO.hpp:31
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
constexpr auto DatasetField
Alias for AQNWB::Types::StorageObjectType::Dataset.
Definition RegisteredType.hpp:28