|
SERiF 0.0.1a
3+1D Stellar Structure and Evolution
|
A universal data container class. More...
#include <DObject.h>
Public Types | |
| using | DataType |
| Supported data types for the DObject. | |
| using | Plugin = std::function<void(DObject&)> |
| Placeholder type for plugins. | |
Public Member Functions | |
| DObject () | |
| Default constructor. | |
| DObject (const DataType &data) | |
| Constructor to initialize a DObject with data. | |
| const DataType & | getData () const noexcept |
| Retrieves the data stored in the DObject. | |
| template<typename T> | |
| T | getDataAs () const |
| Retrieves the data stored in the DObject as a typed object so that std::get<T>() is not needed. | |
| void | setData (const DataType &data) |
| Sets the data for the DObject. | |
| void | setDebugging (bool enableDebug) |
| Enables or disables debugging and tracing for the DObject. | |
| bool | isDebuggingEnabled () const noexcept |
| Checks if debugging is enabled for the DObject. | |
| int | setErrorCode (int code) noexcept |
| int | getErrorCode () const noexcept |
| Get the error code tracked by the DObject. | |
| void | registerPlugin (const std::string &id, Plugin plugin) |
| Registers a plugin with the DObject. | |
| void | unregisterPlugin (const std::string &id) |
| Unregisters a plugin by its identifier. | |
| void | runPlugin (const std::string &id) |
| Executes a plugin by its identifier. | |
| void | runAllPlugins () |
| Executes all registered plugins in the registry. | |
Public Attributes | |
| std::map< int, std::string > | dataTypeMap |
Private Attributes | |
| DataType | data_ |
| The main data stored in the DObject. | |
| bool | debugEnabled_ = false |
| Indicates whether debugging is enabled. | |
| int | errorCode_ = 0 |
| Error code tracked by the DObject. | |
| std::map< std::string, Plugin > | plugins_ |
| Registry for dynamically registered plugins. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const DObject &obj) |
| Provides a human-readable summary of the DObject. | |
A universal data container class.
The DObject class is designed to store arbitrary data alongside descriptive metadata. It supports plugin registration to allow extensible functionality.
The general purpose of this is to simplify memory managment, function interfaces, and interoperability with other languages by wrapping all of that up inside of one location (DObject). There are still a limited number of types that DOBject can represent these include
If more types are needed, they can be added to the DataType variant.
In general the usage of this might look like
All memory managment should be taken care of as all datatypes accepted by the varient are either primatives or include their own built in memory managment (i.e. this means that wherever possible vectors should be used in place of raw arrays).
| using DObject::DataType |
Supported data types for the DObject.
This type alias uses std::variant to store different types of data, ensuring type safety and flexibility.
| using DObject::Plugin = std::function<void(DObject&)> |
| DObject::DObject | ( | ) |
| DObject::DObject | ( | const DataType & | data | ) |
Constructor to initialize a DObject with data.
| data | The data to be stored in the DObject. |
Definition at line 40 of file DObject.cpp.
|
noexcept |
Retrieves the data stored in the DObject.
Use the appropriate type (matching the stored data) with std::get<T>().
Definition at line 46 of file DObject.cpp.
|
inline |
|
noexcept |
Get the error code tracked by the DObject.
Definition at line 80 of file DObject.cpp.
|
noexcept |
Checks if debugging is enabled for the DObject.
Definition at line 67 of file DObject.cpp.
| void DObject::registerPlugin | ( | const std::string & | id, |
| Plugin | plugin ) |
Registers a plugin with the DObject.
Plugins are stored in a registry and can add custom functionality to the DObject.
| id | A unique identifier for the plugin. |
| plugin | The plugin function to register. |
Definition at line 87 of file DObject.cpp.
| void DObject::runAllPlugins | ( | ) |
Executes all registered plugins in the registry.
Iterates through all plugins and invokes them on the current DObject.
Definition at line 117 of file DObject.cpp.
| void DObject::runPlugin | ( | const std::string & | id | ) |
Executes a plugin by its identifier.
Invokes the registered plugin function. If the plugin is not found, no action is taken.
| id | The unique identifier of the plugin to execute. |
Definition at line 106 of file DObject.cpp.
| void DObject::setData | ( | const DataType & | data | ) |
Sets the data for the DObject.
Updates the stored data and optionally updates metadata.
| data | The new data to store in the DObject. |
Definition at line 53 of file DObject.cpp.
| void DObject::setDebugging | ( | bool | enableDebug | ) |
Enables or disables debugging and tracing for the DObject.
When debugging is enabled, the DObject tracks creation and modification history.
| enableDebug | True to enable debugging, false to disable it. |
Definition at line 60 of file DObject.cpp.
|
noexcept |
@breif Set error code tracked by the DOBject
@breif Sets an error code and returns the old one
Definition at line 74 of file DObject.cpp.
| void DObject::unregisterPlugin | ( | const std::string & | id | ) |
Unregisters a plugin by its identifier.
Removes the plugin from the registry if it exists.
| id | The unique identifier of the plugin to unregister. |
Definition at line 97 of file DObject.cpp.
|
friend |
Provides a human-readable summary of the DObject.
Useful for quick inspection or logging during debugging sessions.
| os | The output stream to write to. |
| obj | The DObject to summarize. |
Definition at line 126 of file DObject.cpp.
|
private |
| std::map<int, std::string> DObject::dataTypeMap |
|
private |
|
private |
|
private |