SVCS - English Documentation
Loading...
Searching...
No Matches
Tree.hxx
Go to the documentation of this file.
1
17#pragma once
18
19#include "VcsObject.hxx"
20#include <optional>
21#include <string>
22#include <vector>
23
34 * @details Содержит фундаментальные типы объектов СКВ, такие как Blob, Tree, Commit,
35 * которые формируют строительные блоки системы контроля версий.
36 */
37namespace svcs::core {
38
50struct TreeEntry {
58 std::string mode;
59
67 std::string name;
68
76 std::string hash_id;
77
84 */
85 std::string type;
86
100 bool operator<(const TreeEntry& other) const;
101};
102
116TreeEntry createEntry(std::string name, std::string hash_id);
117
129class Tree : public VcsObject {
130private:
138 std::vector<TreeEntry> entries;
139
140public:
152 explicit Tree(std::vector<TreeEntry> entries);
153
154 // VcsObject overrides
155
159
166 [[nodiscard]] std::string getType() const override;
167
180 [[nodiscard]] std::string serialize() const override;
181
193 static Tree deserialize(const std::string& raw_content);
194
206 void addEntry(const TreeEntry& entry);
207
219 bool removeEntry(const std::string& name);
220
232 [[nodiscard]] std::optional<TreeEntry> findEntry(const std::string& name) const;
233
243 [[nodiscard]] const std::vector<TreeEntry>& getEntries() const;
244};
245
246}
Definition of the abstract base class for all Version Control System objects.
Represents the state of a directory in the VCS, implementing the VcsObject contract.
Definition Tree.hxx:84
void addEntry(const TreeEntry &entry)
Adds a new entry to the Tree or updates an existing entry if the name matches.
Definition Tree.cxx:107
Tree(std::vector< TreeEntry > entries)
Constructor for the Tree object.
Definition Tree.cxx:29
const std::vector< TreeEntry > & getEntries() const
Returns the list of entries stored in the Tree.
Definition Tree.cxx:146
bool removeEntry(const std::string &name)
Removes an entry (file or subdirectory) from the Tree by name.
Definition Tree.cxx:119
std::string getType() const override
Returns the type of the VCS object.
Definition Tree.cxx:130
std::optional< TreeEntry > findEntry(const std::string &name) const
Searches for a specific entry within the Tree by name.
Definition Tree.cxx:134
static Tree deserialize(const std::string &raw_content)
Creates a Tree object from a serialized string read from the object database.
Definition Tree.cxx:61
std::string serialize() const override
Serializes the Tree content into a standardized string format for hashing and storage.
Definition Tree.cxx:45
Abstract base class representing any storable, addressable object within the VCS.
Definition VcsObject.hxx:33
Core VCS data structures and object model.
TreeEntry createEntry(std::string name, std::string hash_id)
Creating tree entry.
Definition Tree.cxx:25
Represents a single item (file or subdirectory) within a Tree object.
Definition Tree.hxx:34
std::string type
The type of the referenced object ("blob" or "tree").
Definition Tree.hxx:57
std::string name
The name of the file or subdirectory.
Definition Tree.hxx:45
std::string mode
File mode (permissions) and type identifier (e.g., "100644" for a blob, "040000" for a tree).
Definition Tree.hxx:39
bool operator<(const TreeEntry &other) const
Comparison operator required for sorting.
Definition Tree.cxx:21
std::string hash_id
The hash ID (SHA-256) of the referenced object (Blob or Tree).
Definition Tree.hxx:51