aqnwb 0.1.0
Loading...
Searching...
No Matches
RegisteredType.hpp File Reference
#include <filesystem>
#include <functional>
#include <memory>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include "Types.hpp"
#include "Utils.hpp"
#include "io/BaseIO.hpp"
#include "io/ReadIO.hpp"
Include dependency graph for RegisteredType.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  AQNWB::NWB::RegisteredType
 Base class for types defined in the NWB schema. More...

Namespaces

namespace  AQNWB
 The main namespace for AqNWB.
namespace  AQNWB::NWB
 Namespace for all classes related to the NWB data standard.

Macros

#define REGISTER_SUBCLASS_WITH_TYPENAME(T, NAMESPACE_VAR, TYPENAME)
 Macro to register a subclass with the RegisteredType class registry.
#define REGISTER_SUBCLASS(T, NAMESPACE)
 Macro to register a subclass with the RegisteredType class registry.
#define REGISTER_SUBCLASS_IMPL(T)
 Macro to initialize the static member registered_ to trigger registration.
#define DEFINE_ATTRIBUTE_FIELD(name, default_type, fieldPath, description)
 Defines a lazy-loaded attribute field accessor function.
#define DEFINE_DATASET_FIELD(readName, writeName, default_type, fieldPath, description)
 Defines a lazy-loaded dataset field accessor function.
#define DEFINE_REGISTERED_FIELD(name, registeredType, fieldPath, description)
 Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes.
#define DEFINE_REFERENCED_REGISTERED_FIELD(name, registeredType, fieldPath, description)
 Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes that are linked to by a reference attribute.

Variables

constexpr auto AQNWB::NWB::AttributeField = AQNWB::Types::StorageObjectType::Attribute
 Alias for AQNWB::Types::StorageObjectType::Attribute.
constexpr auto AQNWB::NWB::DatasetField = AQNWB::Types::StorageObjectType::Dataset
 Alias for AQNWB::Types::StorageObjectType::Dataset.

Macro Definition Documentation

◆ DEFINE_ATTRIBUTE_FIELD

#define DEFINE_ATTRIBUTE_FIELD ( name,
default_type,
fieldPath,
description )
Value:
\
template<typename VTYPE = default_type> \
inline std::unique_ptr<AQNWB::IO::ReadDataWrapper<AttributeField, VTYPE>> \
name() const \
{ \
return std::make_unique< \
m_io, AQNWB::mergePaths(m_path, fieldPath)); \
}
Class for wrapping data objects (datasets or attributes) for reading data from a file.
Definition ReadIO.hpp:270
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

Defines a lazy-loaded attribute field accessor function.

This macro generates a function that returns a lazy-loaded wrapper for an attribute field.

Note
The Doxyfile.in defines a simplified expansion of this function for generating the documentation for the autogenerated function. This means: 1) When updating the macro here, we also need to ensure that the expansion in the Doxyfile.in is still accurate and 2) the docstring that is defined by the macro here is not being used by Doxygen but the version generated by its on PREDEFINED expansion.
Parameters
nameThe name of the function to generate.
default_typeThe default type of the field.
fieldPathThe path to the field.
descriptionA detailed description of the field.

◆ DEFINE_DATASET_FIELD

#define DEFINE_DATASET_FIELD ( readName,
writeName,
default_type,
fieldPath,
description )

Defines a lazy-loaded dataset field accessor function.

This macro generates two functions:

  1. A read function that returns a lazy-loaded wrapper for a dataset field
  2. A write function that returns the dataset object directly
Note
The Doxyfile.in defines a simplified expansion of this function for generating the documentation for the autogenerated function. This means: 1) When updating the macro here, we also need to ensure that the expansion in the Doxyfile.in is still accurate and 2) the docstring that is defined by the macro here is not being used by Doxygen but the version generated by its on PREDEFINED expansion.
Parameters
readNameThe name of the read function to generate.
writeNameThe name of the write function to generate.
default_typeThe default type of the field.
fieldPathThe path to the field.
descriptionA detailed description of the field.

◆ DEFINE_REFERENCED_REGISTERED_FIELD

#define DEFINE_REFERENCED_REGISTERED_FIELD ( name,
registeredType,
fieldPath,
description )
Value:
\
template<typename RTYPE = registeredType> \
inline std::shared_ptr<RTYPE> name() const \
{ \
try { \
std::string attrPath = AQNWB::mergePaths(m_path, fieldPath); \
std::string objectPath = m_io->readReferenceAttribute(attrPath); \
if (m_io->objectExists(objectPath)) { \
return RegisteredType::create<RTYPE>(objectPath, m_io); \
} \
} catch (const std::exception& e) { \
return nullptr; \
} \
return nullptr; \
}

Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes that are linked to by a reference attribute.

This macro generates a function that returns the appropriate subtype of RegisteredType, e.g., to read VectorData from a DynamicTable or a TimeSeries from an NWBFile.

Note
The Doxyfile.in defines a simplified expansion of this function for generating the documentation for the autogenerated function. This means: 1) When updating the macro here, we also need to ensure that the expansion in the Doxyfile.in is still accurate and 2) the docstring that is defined by the macro here is not being used by Doxygen but the version generated by its on PREDEFINED expansion.
Parameters
nameThe name of the function to generate.
registeredTypeThe specific subclass of registered type to use
fieldPathThe path to the attribute that stores reference to the field
descriptionA detailed description of the field.

◆ DEFINE_REGISTERED_FIELD

#define DEFINE_REGISTERED_FIELD ( name,
registeredType,
fieldPath,
description )
Value:
\
template<typename RTYPE = registeredType> \
inline std::shared_ptr<RTYPE> name() const \
{ \
std::string objectPath = AQNWB::mergePaths(m_path, fieldPath); \
if (m_io->objectExists(objectPath)) { \
return RegisteredType::create<RTYPE>(objectPath, m_io); \
} \
return nullptr; \
}

Defines a lazy-loaded accessor function for reading fields that are RegisteredTypes.

This macro generates a function that returns the approbriate subtype of RegisteredType, e.g., to read VectorData from a DynamicTable or a TimeSeries from and NWBFile.

Note
The Doxyfile.in defines a simplified expansion of this function for generating the documentation for the autogenerated function. This means: 1) When updating the macro here, we also need to ensure that the expansion in the Doxyfile.in is still accurate and 2) the docstring that is defined by the macro here is not being used by Doxygen but the version generated by its on PREDEFINED expansion.
Parameters
nameThe name of the function to generate.
registeredTypeThe specific subclass of registered type to use
fieldPathThe path to the field.
descriptionA detailed description of the field.

◆ REGISTER_SUBCLASS

#define REGISTER_SUBCLASS ( T,
NAMESPACE )
Value:
#define REGISTER_SUBCLASS_WITH_TYPENAME(T, NAMESPACE_VAR, TYPENAME)
Macro to register a subclass with the RegisteredType class registry.
Definition RegisteredType.hpp:378

Macro to register a subclass with the RegisteredType class registry.

This macro is a convenience wrapper around the main REGISTER_SUBCLASS macro, providing a default value for TYPENAME.

Parameters
TThe subclass type to register. The name must match the type in the schema.
NAMESPACEThe namespace of the subclass type in the format schema

◆ REGISTER_SUBCLASS_IMPL

#define REGISTER_SUBCLASS_IMPL ( T)
Value:
bool T::registered_ = T::registerSubclass();

Macro to initialize the static member registered_ to trigger registration.

This macro ensures that the registration of the subclass occurs when the program starts.

Parameters
TThe subclass type to register.

◆ REGISTER_SUBCLASS_WITH_TYPENAME

#define REGISTER_SUBCLASS_WITH_TYPENAME ( T,
NAMESPACE_VAR,
TYPENAME )
Value:
static bool registerSubclass() \
{ \
AQNWB::NWB::RegisteredType::registerSubclass( \
std::string(NAMESPACE_VAR) + "::" + #T, \
[](const std::string& path, std::shared_ptr<AQNWB::IO::BaseIO> io) \
-> std::unique_ptr<AQNWB::NWB::RegisteredType> \
{ return std::make_unique<T>(path, io); }, \
TYPENAME, \
NAMESPACE_VAR); \
return true; \
} \
static bool registered_; \
virtual std::string getTypeName() const override \
{ \
return TYPENAME; \
} \
virtual std::string getNamespace() const override \
{ \
return NAMESPACE_VAR; \
}

Macro to register a subclass with the RegisteredType class registry.

This macro defines:

  • A static method registerSubclass that triggers registration of the subclass type when the subclass type is loaded.
  • A static member registered_ that ensures the registration occurs.
  • override getTypeName for the class to return the correct type name
  • override getNamespace for the class to return the correct namespace used
Parameters
TThe subclass type to register. The name must match the type in the schema.
NAMESPACE_VARThe namespace of the subclass type in the format schema. May be specified via a const variable or as a literal string.
TYPENAMEThe name of the type (usually the class name).