SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::core::VcsObject Class Referenceabstract

Abstract base class representing any storable, addressable object within the VCS. More...

#include <VcsObject.hxx>

Inheritance diagram for svcs::core::VcsObject:
svcs::core::Blob svcs::core::Commit svcs::core::TestableObject svcs::core::Tree

Public Member Functions

 VcsObject ()=default
 Default constructor. Required for derived classes.
 VcsObject (const VcsObject &other)=default
 Copy constructor. Required for derived classes to correctly copy the hash_id.
virtual ~VcsObject ()=default
 Virtual destructor.
virtual std::string serialize () const =0
 Pure virtual method to serialize the object's core data.
virtual std::string getType () const =0
 Pure virtual method to get the type of the VCS object.
std::string getHashId () const
 Returns the unique hash identifier of the object.

Static Public Member Functions

static std::string calculateHash (const std::string &content)
 Calculates SHA-256 hash for given canonical content.

Protected Member Functions

void computeHash (const std::string &content)
 Computes the cryptographic hash ID for the object's content.

Protected Attributes

std::string hash_id
 The unique cryptographic hash identifier (e.g., SHA-256) for this object.

Detailed Description

Abstract base class representing any storable, addressable object within the VCS.

VcsObject enforces the mandatory presence of a hash ID, serialization logic, and type identification for all derived classes. It serves as the core domain entity for the object database.

Constructor & Destructor Documentation

◆ VcsObject()

svcs::core::VcsObject::VcsObject ( const VcsObject & other)
default

Copy constructor. Required for derived classes to correctly copy the hash_id.

Parameters
otherThe VcsObject to copy from.

◆ ~VcsObject()

virtual svcs::core::VcsObject::~VcsObject ( )
virtualdefault

Virtual destructor.

Ensures proper cleanup when deleting derived objects via a base class pointer.

Member Function Documentation

◆ calculateHash()

std::string svcs::core::VcsObject::calculateHash ( const std::string & content)
static

Calculates SHA-256 hash for given canonical content.

Parameters
contentGit-format object content (header + raw_data).
Returns
std::string Calculated 64-character hash.

◆ computeHash()

void svcs::core::VcsObject::computeHash ( const std::string & content)
protected

Computes the cryptographic hash ID for the object's content.

This method should prepend the object's type and content length (Git-style) before hashing the full content and setting the internal hash_id.

Parameters
contentThe serialized string data of the object (usually returned by serialize()).

◆ getHashId()

std::string svcs::core::VcsObject::getHashId ( ) const
nodiscard

Returns the unique hash identifier of the object.

Returns
std::string The cryptographic hash ID.

◆ getType()

virtual std::string svcs::core::VcsObject::getType ( ) const
nodiscardpure virtual

Pure virtual method to get the type of the VCS object.

This is crucial for object storage and reconstruction (e.g., "commit", "blob", "tree").

Returns
std::string The type identifier of the object.

Implemented in svcs::core::Blob, svcs::core::Commit, svcs::core::TestableObject, and svcs::core::Tree.

◆ serialize()

virtual std::string svcs::core::VcsObject::serialize ( ) const
nodiscardpure virtual

Pure virtual method to serialize the object's core data.

The returned string content is what will be hashed and stored in the database.

Returns
std::string The standardized, serialized data of the object.

Implemented in svcs::core::Blob, svcs::core::Commit, svcs::core::TestableObject, and svcs::core::Tree.

Member Data Documentation

◆ hash_id

std::string svcs::core::VcsObject::hash_id
protected

The unique cryptographic hash identifier (e.g., SHA-256) for this object.

Protected to allow internal setting via computeHash() but prevent external modification.


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