aqnwb 0.1.0
Loading...
Searching...
No Matches
BaseIO.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <iostream>
5#include <memory>
6#include <string>
7#include <vector>
8
9#include "Types.hpp"
10
11#define DEFAULT_STR_SIZE 256
12#define DEFAULT_ARRAY_SIZE 1
13
17
22namespace AQNWB
23{
24
25class BaseRecordingData;
26
35{
36public:
55
61 BaseDataType(Type t = T_I32, SizeType s = 1);
62
65
66 // handy accessors
67 static const BaseDataType U8;
68 static const BaseDataType U16;
69 static const BaseDataType U32;
70 static const BaseDataType U64;
71 static const BaseDataType I8;
72 static const BaseDataType I16;
73 static const BaseDataType I32;
74 static const BaseDataType I64;
75 static const BaseDataType F32;
76 static const BaseDataType F64;
77 static const BaseDataType DSTR;
78 static BaseDataType STR(
79 SizeType size);
80};
81
91class BaseIO
92{
93public:
97 BaseIO(const std::string& filename);
98
102 BaseIO(const BaseIO&) = delete;
103
107 BaseIO& operator=(const BaseIO&) = delete;
108
112 virtual ~BaseIO();
113
118 virtual std::string getFileName() const { return m_filename; }
119
124 virtual Status open() = 0;
125
131 virtual Status open(bool newfile) = 0;
132
137 virtual Status close() = 0;
138
143 virtual Status flush() = 0;
144
155 const void* data,
156 const std::string& path,
157 const std::string& name,
158 const SizeType& size = 1) = 0;
159
167 virtual Status createAttribute(const std::string& data,
168 const std::string& path,
169 const std::string& name) = 0;
170
178 virtual Status createAttribute(const std::vector<std::string>& data,
179 const std::string& path,
180 const std::string& name) = 0;
181
190 virtual Status createAttribute(const std::vector<const char*>& data,
191 const std::string& path,
192 const std::string& name,
193 const SizeType& maxSize) = 0;
194
202 virtual Status createReferenceAttribute(const std::string& referencePath,
203 const std::string& path,
204 const std::string& name) = 0;
205
211 virtual Status createGroup(const std::string& path) = 0;
212
220 virtual Status createLink(const std::string& path,
221 const std::string& reference) = 0;
222
229 virtual Status createStringDataSet(const std::string& path,
230 const std::string& value) = 0;
231
239 const std::string& path, const std::vector<std::string>& values) = 0;
240
249 const std::string& path, const std::vector<std::string>& references) = 0;
250
255 virtual Status startRecording() = 0;
256
261 virtual Status stopRecording() = 0;
262
270 virtual bool canModifyObjects() { return true; }
271
281 virtual std::unique_ptr<BaseRecordingData> createArrayDataSet(
282 const BaseDataType& type,
283 const SizeArray& size,
284 const SizeArray& chunking,
285 const std::string& path) = 0;
286
292 virtual std::unique_ptr<BaseRecordingData> getDataSet(
293 const std::string& path) = 0;
294
301 virtual bool objectExists(const std::string& path) = 0;
302
311 Status createCommonNWBAttributes(const std::string& path,
312 const std::string& objectNamespace,
313 const std::string& neurodataType = "",
314 const std::string& description = "");
315
325 Status createDataAttributes(const std::string& path,
326 const float& conversion,
327 const float& resolution,
328 const std::string& unit);
329
335 Status createTimestampsAttributes(const std::string& path);
336
341 inline bool isOpen() const { return m_opened; }
342
347 inline bool isReadyToOpen() const { return m_readyToOpen; }
348
349protected:
353 const std::string m_filename;
354
360 virtual Status createGroupIfDoesNotExist(const std::string& path) = 0;
361
366
371};
372
379{
380public:
385
390
395
399 virtual ~BaseRecordingData();
400
410 Status writeDataBlock(const std::vector<SizeType>& dataShape,
411 const BaseDataType& type,
412 const void* data);
413
422 virtual Status writeDataBlock(const std::vector<SizeType>& dataShape,
423 const std::vector<SizeType>& positionOffset,
424 const BaseDataType& type,
425 const void* data) = 0;
426
427protected:
431 std::vector<SizeType> size;
432
436 std::vector<SizeType> position;
437
442};
443
444} // namespace AQNWB
AQNWB::Types::SizeType SizeType
Definition BaseIO.hpp:16
AQNWB::Types::SizeArray SizeArray
Definition BaseIO.hpp:15
Represents a base data type.
Definition BaseIO.hpp:35
static const BaseDataType F32
Accessor for 32-bit floating point.
Definition BaseIO.hpp:75
SizeType typeSize
The size of the data type.
Definition BaseIO.hpp:64
static const BaseDataType I64
Accessor for signed 64-bit integer.
Definition BaseIO.hpp:74
static BaseDataType STR(SizeType size)
Accessor for string with specified size.
Definition BaseIO.cpp:15
static const BaseDataType U32
Accessor for unsigned 32-bit integer.
Definition BaseIO.hpp:69
static const BaseDataType DSTR
Accessor for dynamic string.
Definition BaseIO.hpp:77
static const BaseDataType U64
Accessor for unsigned 64-bit integer.
Definition BaseIO.hpp:70
static const BaseDataType U16
Accessor for unsigned 16-bit integer.
Definition BaseIO.hpp:68
static const BaseDataType F64
Accessor for 64-bit floating point.
Definition BaseIO.hpp:76
static const BaseDataType U8
Accessor for unsigned 8-bit integer.
Definition BaseIO.hpp:67
Type type
The data type.
Definition BaseIO.hpp:63
Type
Enumeration of different data types.
Definition BaseIO.hpp:41
@ T_U32
Unsigned 32-bit integer.
Definition BaseIO.hpp:44
@ T_I64
Signed 64-bit integer.
Definition BaseIO.hpp:49
@ T_I8
Signed 8-bit integer.
Definition BaseIO.hpp:46
@ T_U16
Unsigned 16-bit integer.
Definition BaseIO.hpp:43
@ T_F32
32-bit floating point
Definition BaseIO.hpp:50
@ T_I16
Signed 16-bit integer.
Definition BaseIO.hpp:47
@ V_STR
Variable length string.
Definition BaseIO.hpp:53
@ T_U8
Unsigned 8-bit integer.
Definition BaseIO.hpp:42
@ T_STR
String.
Definition BaseIO.hpp:52
@ T_F64
64-bit floating point
Definition BaseIO.hpp:51
@ T_I32
Signed 32-bit integer.
Definition BaseIO.hpp:48
@ T_U64
Unsigned 64-bit integer.
Definition BaseIO.hpp:45
static const BaseDataType I32
Accessor for signed 32-bit integer.
Definition BaseIO.hpp:73
static const BaseDataType I16
Accessor for signed 16-bit integer.
Definition BaseIO.hpp:72
BaseDataType(Type t=T_I32, SizeType s=1)
Constructs a BaseDataType object with the specified type and size.
Definition BaseIO.cpp:9
static const BaseDataType I8
Accessor for signed 8-bit integer.
Definition BaseIO.hpp:71
The BaseIO class is an abstract base class that defines the interface for input/output (IO) operation...
Definition BaseIO.hpp:92
virtual Status stopRecording()=0
Stops the recording process.
virtual Status createAttribute(const BaseDataType &type, const void *data, const std::string &path, const std::string &name, const SizeType &size=1)=0
Creates an attribute at a given location in the file.
virtual Status flush()=0
Flush data to disk.
bool isReadyToOpen() const
Returns true if the file is able to be opened.
Definition BaseIO.hpp:347
virtual Status createReferenceDataSet(const std::string &path, const std::vector< std::string > &references)=0
Creates a dataset that holds an array of references to groups within the file.
virtual Status open()=0
Opens the file for writing.
BaseIO & operator=(const BaseIO &)=delete
Assignment operator is deleted to prevent copying.
BaseIO(const BaseIO &)=delete
Copy constructor is deleted to prevent construction-copying.
virtual Status createStringDataSet(const std::string &path, const std::vector< std::string > &values)=0
Creates a dataset that holds an array of string values.
virtual bool objectExists(const std::string &path)=0
Checks whether a Dataset, Group, or Link already exists at the location in the file.
Status createDataAttributes(const std::string &path, const float &conversion, const float &resolution, const std::string &unit)
Convenience function for creating data related attributes.
Definition BaseIO.cpp:57
const std::string m_filename
The name of the file.
Definition BaseIO.hpp:353
virtual Status createGroupIfDoesNotExist(const std::string &path)=0
Creates a new group if it does not already exist.
BaseIO(const std::string &filename)
Constructor for the BaseIO class.
Definition BaseIO.cpp:34
virtual Status createReferenceAttribute(const std::string &referencePath, const std::string &path, const std::string &name)=0
Sets an object reference attribute for a given location in the file.
virtual Status createGroup(const std::string &path)=0
Creates a new group in the file.
virtual Status createStringDataSet(const std::string &path, const std::string &value)=0
Creates a non-modifiable dataset with a string value.
virtual Status startRecording()=0
Starts the recording process.
virtual bool canModifyObjects()
Returns true if the file is in a mode where objects can be added or deleted. Note,...
Definition BaseIO.hpp:270
virtual Status createAttribute(const std::string &data, const std::string &path, const std::string &name)=0
Creates a string attribute at a given location in the file.
virtual ~BaseIO()
Destructor the BaseIO class.
Definition BaseIO.cpp:41
bool m_opened
Whether the file is currently open.
Definition BaseIO.hpp:370
bool isOpen() const
Returns true if the file is open.
Definition BaseIO.hpp:341
virtual std::unique_ptr< BaseRecordingData > createArrayDataSet(const BaseDataType &type, const SizeArray &size, const SizeArray &chunking, const std::string &path)=0
Creates an extendable dataset with a given base data type, size, chunking, and path.
virtual Status close()=0
Closes the file.
Status createTimestampsAttributes(const std::string &path)
Convenience function for creating timestamp related attributes.
Definition BaseIO.cpp:69
Status createCommonNWBAttributes(const std::string &path, const std::string &objectNamespace, const std::string &neurodataType="", const std::string &description="")
Convenience function for creating NWB related attributes.
Definition BaseIO.cpp:43
bool m_readyToOpen
Whether the file is ready to be opened.
Definition BaseIO.hpp:365
virtual std::unique_ptr< BaseRecordingData > getDataSet(const std::string &path)=0
Returns a pointer to a dataset at a given path.
virtual Status createAttribute(const std::vector< const char * > &data, const std::string &path, const std::string &name, const SizeType &maxSize)=0
Creates a string array attribute at a given location in the file.
virtual Status createAttribute(const std::vector< std::string > &data, const std::string &path, const std::string &name)=0
Creates a string array attribute at a given location in the file.
virtual Status createLink(const std::string &path, const std::string &reference)=0
Creates a soft link to another location in the file.
virtual Status open(bool newfile)=0
Opens an existing file or creates a new file for writing.
virtual std::string getFileName() const
Returns the full path to the file.
Definition BaseIO.hpp:118
The base class to represent recording data that can be extended.
Definition BaseIO.hpp:379
BaseRecordingData & operator=(const BaseRecordingData &)=delete
Deleted copy assignment operator to prevent copying.
std::vector< SizeType > size
The size of the dataset in each dimension.
Definition BaseIO.hpp:431
SizeType nDimensions
The number of dimensions in the data block.
Definition BaseIO.hpp:441
BaseRecordingData(const BaseRecordingData &)=delete
Deleted copy constructor to prevent construction-copying.
BaseRecordingData()
Default constructor.
Definition BaseIO.cpp:83
virtual Status writeDataBlock(const std::vector< SizeType > &dataShape, const std::vector< SizeType > &positionOffset, const BaseDataType &type, const void *data)=0
Writes a block of data (any number of dimensions).
Status writeDataBlock(const std::vector< SizeType > &dataShape, const BaseDataType &type, const void *data)
Writes a block of data using the stored position information. This is not intended to be overwritten ...
Definition BaseIO.cpp:89
std::vector< SizeType > position
The current position in the dataset.
Definition BaseIO.hpp:436
virtual ~BaseRecordingData()
Destructor.
Definition BaseIO.cpp:85
Status
Represents the status of an operation.
Definition Types.hpp:22
std::vector< size_t > SizeArray
Alias for an array of size types used in the project.
Definition Types.hpp:35
size_t SizeType
Alias for the size type used in the project.
Definition Types.hpp:30
The main namespace for AqNWB.