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

Represents the state of a directory in the VCS, implementing the VcsObject contract. More...

#include <Tree.hxx>

Inheritance diagram for svcs::core::Tree:
svcs::core::VcsObject

Public Member Functions

 Tree (std::vector< TreeEntry > entries)
 Constructor for the Tree object.
std::string getType () const override
 Returns the type of the VCS object.
std::string serialize () const override
 Serializes the Tree content into a standardized string format for hashing and storage.
void addEntry (const TreeEntry &entry)
 Adds a new entry to the Tree or updates an existing entry if the name matches.
bool removeEntry (const std::string &name)
 Removes an entry (file or subdirectory) from the Tree by name.
std::optional< TreeEntryfindEntry (const std::string &name) const
 Searches for a specific entry within the Tree by name.
const std::vector< TreeEntry > & getEntries () const
 Returns the list of entries stored in the Tree.
Public Member Functions inherited from svcs::core::VcsObject
 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.
std::string getHashId () const
 Returns the unique hash identifier of the object.

Static Public Member Functions

static Tree deserialize (const std::string &raw_content)
 Creates a Tree object from a serialized string read from the object database.
Static Public Member Functions inherited from svcs::core::VcsObject
static std::string calculateHash (const std::string &content)
 Calculates SHA-256 hash for given canonical content.

Additional Inherited Members

Protected Member Functions inherited from svcs::core::VcsObject
void computeHash (const std::string &content)
 Computes the cryptographic hash ID for the object's content.
Protected Attributes inherited from svcs::core::VcsObject
std::string hash_id
 The unique cryptographic hash identifier (e.g., SHA-256) for this object.

Detailed Description

Represents the state of a directory in the VCS, implementing the VcsObject contract.

Stores a collection of TreeEntry objects, effectively mapping names to hash pointers.

Constructor & Destructor Documentation

◆ Tree()

svcs::core::Tree::Tree ( std::vector< TreeEntry > entries)
explicit

Constructor for the Tree object.

The constructor must internally sort the entries before calling computeHash().

Parameters
entriesA collection of TreeEntry structures representing the directory content.

Member Function Documentation

◆ addEntry()

void svcs::core::Tree::addEntry ( const TreeEntry & entry)

Adds a new entry to the Tree or updates an existing entry if the name matches.

If the entries list is modified, the Tree's hash becomes invalid and must be recomputed before saving.

Parameters
entryThe TreeEntry to add or update.

◆ deserialize()

Tree svcs::core::Tree::deserialize ( const std::string & raw_content)
static

Creates a Tree object from a serialized string read from the object database.

Parameters
raw_contentThe serialized string data, typically read from a decompressed object file.
Returns
Tree A fully reconstructed Tree object.

◆ findEntry()

std::optional< TreeEntry > svcs::core::Tree::findEntry ( const std::string & name) const
nodiscard

Searches for a specific entry within the Tree by name.

Parameters
nameThe name of the entry to find.
Returns
std::optional<TreeEntry> An optional containing the entry if found, otherwise empty.

◆ getEntries()

const std::vector< TreeEntry > & svcs::core::Tree::getEntries ( ) const
nodiscard

Returns the list of entries stored in the Tree.

Returns
std::vector<TreeEntry>& A constant reference to the internal vector of entries.

◆ getType()

std::string svcs::core::Tree::getType ( ) const
nodiscardoverridevirtual

Returns the type of the VCS object.

Returns
std::string Always returns "tree". 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.

Implements svcs::core::VcsObject.

◆ removeEntry()

bool svcs::core::Tree::removeEntry ( const std::string & name)

Removes an entry (file or subdirectory) from the Tree by name.

Parameters
nameThe name of the entry to remove.
Returns
bool True if the entry was found and removed, otherwise false.

◆ serialize()

std::string svcs::core::Tree::serialize ( ) const
nodiscardoverridevirtual

Serializes the Tree content into a standardized string format for hashing and storage.

The serialization must ensure the entries are sorted to guarantee hash consistency.

Returns
std::string The standardized, serialized directory structure. 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.

Implements svcs::core::VcsObject.


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