Represents the state of a directory in the VCS, implementing the VcsObject contract.
More...
#include <Tree.hxx>
|
| | 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< TreeEntry > | findEntry (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.
|
|
| 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 Tree | deserialize (const std::string &raw_content) |
| | Creates a Tree object from a serialized string read from the object database.
|
| static std::string | calculateHash (const std::string &content) |
| | Calculates SHA-256 hash for given canonical content.
|
|
| void | computeHash (const std::string &content) |
| | Computes the cryptographic hash ID for the object's content.
|
| std::string | hash_id |
| | The unique cryptographic hash identifier (e.g., SHA-256) for this object.
|
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.
◆ 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
-
| entries | A collection of TreeEntry structures representing the directory content. |
◆ 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
-
◆ 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_content | The 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
-
| name | The 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
-
| name | The 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: