feat(src/dobj): initial metadata class implimentation for dobj added

The dobj class will need to hold metadata about its constituent data. The metadata class provides this.
This commit is contained in:
2025-01-19 07:36:12 -05:00
parent be7096124f
commit 17f622fec1
2 changed files with 250 additions and 0 deletions

View File

@@ -0,0 +1,138 @@
#include "Metadata.h"
/**
* @file Metadata.cpp
* @brief Implementation of the Metadata class used in the dobj module.
*
* Provides methods to manage metadata for data objects, including size, type,
* dimensions, and debugging flags.
*/
/**
* @brief Constructor to initialize Metadata with specific attributes.
*
* @param byteSize The total size of the data in bytes.
* @param dataType The type of the data (e.g., "float", "double").
* @param dimensions A vector representing the size of each dimension (e.g., {3, 4} for a 3x4 matrix).
* @param debugFlag Whether debugging information is enabled for this Metadata instance.
*/
Metadata::Metadata(std::size_t byteSize, std::string dataType, std::vector<std::size_t> dimensions, bool debugFlag)
: byteSize_(byteSize), dataType_(std::move(dataType)), dimensions_(std::move(dimensions)), debugFlag_(debugFlag) {}
/**
* @brief Gets the total size of the data in bytes.
*
* The size is often required for memory allocation and validation in numerical routines.
*
* @return The total byte size of the data.
*/
std::size_t Metadata::getByteSize() const noexcept {
return byteSize_;
}
/**
* @brief Sets the total size of the data in bytes.
*
* It's important to ensure this matches the actual data size in memory to prevent overflows
* or incorrect computations downstream.
*
* @param byteSize The total byte size to set.
*/
void Metadata::setByteSize(std::size_t byteSize) noexcept {
byteSize_ = byteSize;
}
/**
* @brief Gets the type of the data.
*
* The type (e.g., "float", "double") is critical for casting raw data or interfacing with libraries
* that require specific types.
*
* @return A string representing the data type.
*/
const std::string& Metadata::getDataType() const noexcept {
return dataType_;
}
/**
* @brief Sets the type of the data.
*
* When setting the data type, ensure it aligns with the underlying data representation.
* Mismatched types can lead to undefined behavior in numerical calculations.
*
* @param dataType A string representing the data type.
*/
void Metadata::setDataType(const std::string& dataType) {
dataType_ = dataType;
}
/**
* @brief Gets the dimensions of the data.
*
* Dimensions define the shape of the data (e.g., 2D arrays, 3D matrices). This is essential
* for ensuring that operations (e.g., matrix multiplication) are performed correctly.
*
* @return A vector representing the size of each dimension.
*/
const std::vector<std::size_t>& Metadata::getDimensions() const noexcept {
return dimensions_;
}
/**
* @brief Sets the dimensions of the data.
*
* When modifying dimensions, verify that they are consistent with the actual data representation.
*
* @param dimensions A vector representing the size of each dimension.
*/
void Metadata::setDimensions(const std::vector<std::size_t>& dimensions) {
dimensions_ = dimensions;
}
/**
* @brief Checks if debugging information is enabled.
*
* Debugging flags can be useful for tracking performance metrics or error provenance.
*
* @return True if debugging is enabled, false otherwise.
*/
bool Metadata::isDebugEnabled() const noexcept {
return debugFlag_;
}
/**
* @brief Sets the debugging flag.
*
* Enabling debugging can introduce performance overhead but provides valuable insights
* during development or testing.
*
* @param debugFlag Whether debugging is enabled.
*/
void Metadata::setDebugEnabled(bool debugFlag) noexcept {
debugFlag_ = debugFlag;
}
/**
* @brief Prints the metadata information for debugging purposes.
*
* This function provides a human-readable summary of the metadata. Useful for quick checks
* or logging during debugging sessions.
*
* @param os The output stream to print to.
* @param metadata The Metadata object to print.
* @return A reference to the output stream.
*/
std::ostream& operator<<(std::ostream& os, const Metadata& metadata) {
os << "Metadata Information:\n";
os << " Byte Size: " << metadata.byteSize_ << " bytes\n";
os << " Data Type: " << metadata.dataType_ << "\n";
os << " Dimensions: [";
for (size_t i = 0; i < metadata.dimensions_.size(); ++i) {
os << metadata.dimensions_[i];
if (i < metadata.dimensions_.size() - 1) os << ", ";
}
os << "]\n";
os << " Debug Enabled: " << (metadata.debugFlag_ ? "Yes" : "No") << "\n";
return os;
}

112
src/dobj/public/Metadata.h Normal file
View File

@@ -0,0 +1,112 @@
#ifndef METADATA_H
#define METADATA_H
#if defined(__APPLE__) || defined(__linux__)
#define EXPORT_SYMBOL __attribute__((visibility("default")))
#else
#define EXPORT_SYMBOL
#endif
#include <string>
#include <vector>
#include <cstddef>
#include <iostream>
/**
* @file Metadata.h
* @brief Public interface for the Metadata class used in the dobj module.
*
* The Metadata class provides descriptive information about the data encapsulated
* within a dobj, including size, type, dimensions, and debugging flags.
*/
/**
* @class Metadata
* @brief Represents metadata information for data objects in the dobj module.
*
* The Metadata class encapsulates details such as data size, type, dimensions,
* and optional debugging flags. It is designed to provide descriptive attributes
* in a lightweight and efficient manner.
*/
class EXPORT_SYMBOL Metadata {
public:
/**
* @brief Default constructor for Metadata.
*/
Metadata() = default;
/**
* @brief Constructor to initialize Metadata with specific attributes.
*
* @param byteSize The total size of the data in bytes.
* @param dataType The type of the data (e.g., "float", "double").
* @param dimensions A vector representing the size of each dimension (e.g., {3, 4} for a 3x4 matrix).
* @param debugFlag Whether debugging information is enabled for this Metadata instance.
*/
Metadata(std::size_t byteSize, std::string dataType, std::vector<std::size_t> dimensions, bool debugFlag = false);
/**
* @brief Gets the total size of the data in bytes.
* @return The total byte size of the data.
*/
[[nodiscard]] std::size_t getByteSize() const noexcept;
/**
* @brief Sets the total size of the data in bytes.
* @param byteSize The total byte size to set.
*/
void setByteSize(std::size_t byteSize) noexcept;
/**
* @brief Gets the type of the data.
* @return A string representing the data type.
*/
[[nodiscard]] const std::string& getDataType() const noexcept;
/**
* @brief Sets the type of the data.
* @param dataType A string representing the data type.
*/
void setDataType(const std::string& dataType);
/**
* @brief Gets the dimensions of the data.
* @return A vector representing the size of each dimension.
*/
[[nodiscard]] const std::vector<std::size_t>& getDimensions() const noexcept;
/**
* @brief Sets the dimensions of the data.
* @param dimensions A vector representing the size of each dimension.
*/
void setDimensions(const std::vector<std::size_t>& dimensions);
/**
* @brief Checks if debugging information is enabled.
* @return True if debugging is enabled, false otherwise.
*/
[[nodiscard]] bool isDebugEnabled() const noexcept;
/**
* @brief Sets the debugging flag.
* @param debugFlag Whether debugging is enabled.
*/
void setDebugEnabled(bool debugFlag) noexcept;
/**
* @brief Prints the metadata information for debugging purposes.
*
* @param os The output stream to print to.
* @param metadata The Metadata object to print.
* @return A reference to the output stream.
*/
friend std::ostream& operator<<(std::ostream& os, const Metadata& metadata);
private:
std::size_t byteSize_ = 0; ///< Total size of the data in bytes.
std::string dataType_; ///< Type of the data (e.g., "float", "double").
std::vector<std::size_t> dimensions_; ///< Dimensions of the data (e.g., {3, 4} for a 3x4 matrix).
bool debugFlag_ = false; ///< Indicates whether debugging is enabled.
};
#endif // METADATA_H