SVCS - English Documentation
Loading...
Searching...
No Matches
svcs::core::ObjectStorage Class Reference

Manages the version control object database, including persistence and object restoration. More...

#include <ObjectStorage.hxx>

Inheritance diagram for svcs::core::ObjectStorage:
svcs::test::core::MockObjectStorage

Public Member Functions

 ObjectStorage (const std::string &root_path, const std::shared_ptr< ISubject > &subject=nullptr)
 Constructor for ObjectStorage.
virtual ~ObjectStorage ()
 Destructor.
void setSubject (std::shared_ptr< ISubject > subj)
 Sets or replaces the event subject used by the ObjectStorage.
std::string getObjectPath (const std::string &hash) const
 Forms the full filesystem path for an object based on its hash.
virtual bool saveObject (const VcsObject &obj) const
 Saves a VcsObject to the object database.
virtual std::unique_ptr< VcsObjectloadObject (const std::string &hash) const
 Loads an object from the disk by its hash ID.
bool objectExists (const std::string &hash) const
 Checks if an object with the given hash exists on disk.

Detailed Description

Manages the version control object database, including persistence and object restoration.

Implements low-level file system operations (path generation, reading, writing), compression, decompression, and object deserialization.

Constructor & Destructor Documentation

◆ ObjectStorage()

svcs::core::ObjectStorage::ObjectStorage ( const std::string & root_path,
const std::shared_ptr< ISubject > & subject = nullptr )
explicit

Constructor for ObjectStorage.

Parameters
root_pathThe root path of the repository (e.g., the directory containing ".svcs").
subjectShared pointer to the ISubject interface for event logging. Defaults to nullptr if logging is not required yet.

Member Function Documentation

◆ getObjectPath()

std::string svcs::core::ObjectStorage::getObjectPath ( const std::string & hash) const
nodiscard

Forms the full filesystem path for an object based on its hash.

Uses the first two characters of the hash for the subdirectory name and the remaining 38 characters for the filename.

Parameters
hashThe full 40-character SHA-1 hash ID.
Returns
std::string The full, platform-agnostic file path.

◆ loadObject()

std::unique_ptr< VcsObject > svcs::core::ObjectStorage::loadObject ( const std::string & hash) const
nodiscardvirtual

Loads an object from the disk by its hash ID.

Reads the compressed file, decompresses it, performs integrity checks, and deserializes the object using the internal factory method.

Parameters
hashThe hash ID of the object to load.
Returns
std::unique_ptr<VcsObject> The restored object instance.
Exceptions
std::runtime_errorif the object is not found, corrupted, or invalid.

Reimplemented in svcs::test::core::MockObjectStorage.

◆ objectExists()

bool svcs::core::ObjectStorage::objectExists ( const std::string & hash) const
nodiscard

Checks if an object with the given hash exists on disk.

Parameters
hashThe hash ID to check.
Returns
bool True if the object file exists.

◆ saveObject()

bool svcs::core::ObjectStorage::saveObject ( const VcsObject & obj) const
nodiscardvirtual

Saves a VcsObject to the object database.

Serializes the object, prefixes it with a header, compresses it, and writes it to a file. Publishes events on success/failure.

Parameters
objThe VcsObject to save.
Returns
bool True if saving was successful.
Exceptions
std::runtime_errorif hash is invalid or file IO fails.

Reimplemented in svcs::test::core::MockObjectStorage.

◆ setSubject()

void svcs::core::ObjectStorage::setSubject ( std::shared_ptr< ISubject > subj)
inline

Sets or replaces the event subject used by the ObjectStorage.

Parameters
subjThe new ISubject pointer to use for publishing events.

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