aqnwb 0.2.0
Loading...
Searching...
No Matches
Data.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <any>
4#include <memory>
5
6#include "io/BaseIO.hpp"
9
10namespace AQNWB::NWB
11{
16class Data : public RegisteredType
17{
18public:
19 // Register the Data class with the type registry
21
22protected:
29 Data(const std::string& path, std::shared_ptr<IO::BaseIO> io);
30
31public:
35 virtual ~Data() override {}
36
45 Status initialize(const IO::ArrayDataSetConfig& dataConfig);
46
50 inline bool isInitialized() { return this->readData()->exists(); }
51
52 // Define the data fields to expose for lazy read access
53 DEFINE_DATASET_FIELD(readData, recordData, std::any, "", The main data)
54
56 std::string,
57 "neurodata_type",
58 The name of the type)
59
61 std::string,
62 "namespace",
63 The name of the namespace)
64};
65
80template<typename DTYPE = std::any>
81class DataTyped : public Data
82{
83 friend class AQNWB::NWB::RegisteredType; /* base can call constructor */
84
85protected:
92 DataTyped(const std::string& path, std::shared_ptr<IO::BaseIO> io)
93 : Data(path, io)
94 {
95 }
96
97 using Data::Data; /* inherit from immediate base */
98
99public:
110 static std::shared_ptr<DataTyped> create(
111 const std::string& path, std::shared_ptr<AQNWB::IO::BaseIO> io)
112 {
113 return RegisteredType::create<DataTyped>(path, io);
114 }
115
119 virtual ~DataTyped() override {}
120
133 static std::shared_ptr<DataTyped<DTYPE>> fromData(
134 const std::shared_ptr<Data>& data)
135 {
136 return DataTyped<DTYPE>::create(data->getPath(), data->getIO());
137 }
138
139 // Define the data fields to expose for lazy read access
140 DEFINE_DATASET_FIELD(readData, recordData, DTYPE, "", The main data)
141
144};
145} // namespace AQNWB::NWB
AQNWB::Types::Status Status
Definition BaseIO.hpp:22
#define REGISTER_SUBCLASS(T, BASE, NAMESPACE)
Macro to register a subclass with the RegisteredType class registry.
Definition RegisteredType.hpp:501
#define DEFINE_ATTRIBUTE_FIELD(name, default_type, fieldPath, description)
Defines a lazy-loaded attribute field accessor function.
Definition RegisteredType.hpp:534
#define DEFINE_DATASET_FIELD(readName, writeName, default_type, fieldPath, description)
Defines a lazy-loaded dataset field accessor function.
Definition RegisteredType.hpp:573
The configuration for an array dataset.
Definition BaseIO.hpp:204
bool isInitialized()
Check whether the dataset has been initialized.
Definition Data.hpp:50
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordData(bool reset=false)
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readNeurodataType() const
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readData() const
Data(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.cpp:9
Status initialize(const IO::ArrayDataSetConfig &dataConfig)
Initialize the dataset for the Data object.
Definition Data.cpp:14
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::AttributeField, VTYPE > > readNamespace() const
std::unique_ptr< AQNWB::IO::ReadDataWrapper< AQNWB::NWB::DatasetField, VTYPE > > readData() const
DataTyped(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.hpp:92
std::shared_ptr< AQNWB::IO::BaseRecordingData > recordData(bool reset=false)
static std::shared_ptr< DataTyped< DTYPE > > fromData(const std::shared_ptr< Data > &data)
Create a DataTyped object from a Data object.
Definition Data.hpp:133
static std::shared_ptr< DataTyped > create(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
Factor method to create a DataTyped object.
Definition Data.hpp:110
virtual ~DataTyped() override
Virtual destructor.
Definition Data.hpp:119
Data(const std::string &path, std::shared_ptr< IO::BaseIO > io)
Constructor.
Definition Data.cpp:9
Base class for types defined in the NWB schema.
Definition RegisteredType.hpp:48
static std::shared_ptr< RegisteredType > create(const std::string &fullClassName, const std::string &path, std::shared_ptr< IO::BaseIO > io, bool fallbackToBase=false)
Create an instance of a registered subclass by name.
Definition RegisteredType.cpp:75
RegisteredType(const std::string &path, std::shared_ptr< AQNWB::IO::BaseIO > io)
Constructor.
Definition RegisteredType.cpp:18
std::string getPath() const
Gets the path of the registered type.
Definition RegisteredType.hpp:59
std::shared_ptr< AQNWB::IO::BaseIO > getIO() const
Get a shared pointer to the IO object.
Definition RegisteredType.hpp:77
The namespace for IO components of AqNWB.
Namespace for all classes related to the NWB data standard.