Loading...
Searching...
No Matches
DObject Class Reference

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.

## Detailed Description

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

- bool
- short int
- int
- long int
- float
- double
- long double
- std::string
- std::monostate
- std::vector<int>
- std::vector<float>
- std::vector<double>
- std::vector<std::string>
- std::vector<std::vector<int>>
- std::vector<std::vector<float>>
- std::vector<std::vector<double>>
- std::vector<std::vector<std::vector<int>>>
- std::vector<std::vector<std::vector<float>>>
- std::vector<std::vector<std::vector<double>>

If more types are needed, they can be added to the DataType variant.

In general the usage of this might look like

DObject obj;
std::vector<int> data = {1, 2, 3, 4, 5};
obj.setData(data);
std::cout << "Data is " << obj << std::end;
someFunction(&obj);
DObject::DObject
DObject()
Default constructor.
Definition DObject.cpp:33
DObject::setData
void setData(const DataType &data)
Sets the data for the DObject.
Definition DObject.cpp:53

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).

Definition at line 89 of file DObject.h.

## Member Typedef Documentation

## DataType

using DObject::DataType

Initial value:
std::variant<
bool, short int, int, long int, float, double,
long double, std::string, std::monostate, std::vector<int>,
std::vector<float>, std::vector<double>, std::vector<std::string>,
std::vector<std::vector<int>>, std::vector<std::vector<float>>,
std::vector<std::vector<double>>,
std::vector<std::vector<std::vector<int>>>,
std::vector<std::vector<std::vector<float>>>,
std::vector<std::vector<std::vector<double>>>
>

Supported data types for the DObject.

This type alias uses `std::variant` to store different types of data, ensuring type safety and flexibility.

Definition at line 97 of file DObject.h.

## Plugin

using DObject::Plugin = std::function<void(DObject&)>

Placeholder type for plugins.

In the future, this will be replaced with a concrete interface.

Definition at line 125 of file DObject.h.

## Constructor & Destructor Documentation

## DObject() [1/2]

DObject::DObject | ( |  | ) |

Default constructor.

Creates an empty DObject.

Definition at line 33 of file DObject.cpp.

## DObject() [2/2]

DObject::DObject | ( | const DataType & | data | ) |

Constructor to initialize a DObject with data.

Parameters

  data | The data to be stored in the DObject.

Definition at line 40 of file DObject.cpp.

## Member Function Documentation

## getData()

const DObject::DataType & DObject::getData | ( |  | ) | const

noexcept

Retrieves the data stored in the DObject.

Use the appropriate type (matching the stored data) with `std::get<T>()`.

Returns
  A constant reference to the stored data.

Definition at line 46 of file DObject.cpp.

## getDataAs()

template<typename T>

T DObject::getDataAs | ( |  | ) | const

inline

Retrieves the data stored in the DObject as a typed object so that std::get<T>() is not needed.

Returns
  Data as type T

Definition at line 156 of file DObject.h.

## getErrorCode()

int DObject::getErrorCode | ( |  | ) | const

noexcept

Get the error code tracked by the DObject.

Returns
  The error code

Definition at line 80 of file DObject.cpp.

## isDebuggingEnabled()

bool DObject::isDebuggingEnabled | ( |  | ) | const

noexcept

Checks if debugging is enabled for the DObject.

Returns
  True if debugging is enabled, false otherwise.

Definition at line 67 of file DObject.cpp.

## registerPlugin()

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.

Parameters

  id | A unique identifier for the plugin.
  plugin | The plugin function to register.

Definition at line 87 of file DObject.cpp.

## runAllPlugins()

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.

## runPlugin()

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.

Parameters

  id | The unique identifier of the plugin to execute.

Definition at line 106 of file DObject.cpp.

## setData()

void DObject::setData | ( | const DataType & | data | ) |

Sets the data for the DObject.

Updates the stored data and optionally updates metadata.

Parameters

  data | The new data to store in the DObject.

Definition at line 53 of file DObject.cpp.

## setDebugging()

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.

Parameters

  enableDebug | True to enable debugging, false to disable it.

Definition at line 60 of file DObject.cpp.

## setErrorCode()

int DObject::setErrorCode | ( | int | code | ) |

noexcept

@breif Set error code tracked by the DOBject

Returns
  The previous error code

@breif Sets an error code and returns the old one

Definition at line 74 of file DObject.cpp.

## unregisterPlugin()

void DObject::unregisterPlugin | ( | const std::string & | id | ) |

Unregisters a plugin by its identifier.

Removes the plugin from the registry if it exists.

Parameters

  id | The unique identifier of the plugin to unregister.

Definition at line 97 of file DObject.cpp.

## Friends And Related Symbol Documentation

## operator<<

std::ostream & operator<< | ( | std::ostream & | os,
|  | const DObject & | obj )

friend

Provides a human-readable summary of the DObject.

Useful for quick inspection or logging during debugging sessions.

Parameters

  os | The output stream to write to.
  obj | The DObject to summarize.

Returns
  A reference to the output stream.

Definition at line 126 of file DObject.cpp.

## Member Data Documentation

## data_

DataType DObject::data_

private

The main data stored in the DObject.

Definition at line 251 of file DObject.h.

## dataTypeMap

std::map<int, std::string> DObject::dataTypeMap

Initial value:
= {
{0, "bool"}, {1, "short int"}, {2, "int"}, {3, "long int"}, {4, "float"},
{5, "double"}, {6, "long double"}, {7, "string"}, {8, "std::monostate"},
{9, "vector<int>"}, {10, "vector<float>"}, {11, "vector<double>"},
{12, "vector<string>"}, {13, "vector<vector<int>"},
{14, "vector<vector<float>"}, {15, "vector<vector<double>"},
{16, "vector<vector<vector<int>>"}, {17, "vector<vector<vector<float>>"},
{18, "vector<vector<vector<double>>"}
}

Definition at line 109 of file DObject.h.

## debugEnabled_

bool DObject::debugEnabled_ = false

private

Indicates whether debugging is enabled.

Definition at line 252 of file DObject.h.

## errorCode_

int DObject::errorCode_ = 0

private

Error code tracked by the DObject.

Definition at line 253 of file DObject.h.

## plugins_

std::map<std::string, Plugin> DObject::plugins_

private

Registry for dynamically registered plugins.

Definition at line 254 of file DObject.h.

The documentation for this class was generated from the following files:

- src/dobj/public/DObject.h
- src/dobj/private/DObject.cpp