SVCS - English Documentation
Loading...
Searching...
No Matches
ObjectStorage.hxx
Go to the documentation of this file.
1
19#pragma once
20
21#include "VcsObject.hxx"
22#include <filesystem>
23#include <string>
24#include <memory>
25#include <utility>
27
40 */
41namespace svcs::core {
42
43using namespace svcs::services;
44
58class ObjectStorage {
59private:
67 const std::filesystem::path objects_dir;
68
76 std::shared_ptr<ISubject> subject;
77
91 [[nodiscard]] std::string compress(const std::string& data) const;
92
106 [[nodiscard]] std::string decompress(const std::string& compressed_data) const;
107
125 [[nodiscard]] std::unique_ptr<VcsObject> createObjectFromContent(
126 const std::string& type,
127 const std::string& content
128 ) const;
129
130public:
142 explicit ObjectStorage(const std::string& root_path, const std::shared_ptr<ISubject>& subject = nullptr);
143
148
151 virtual ~ObjectStorage();
152
162 void setSubject(std::shared_ptr<ISubject> subj) { subject = std::move(subj); };
163
179 [[nodiscard]] std::string getObjectPath(const std::string& hash) const;
180
198 [[nodiscard]] virtual bool saveObject(const VcsObject& obj) const;
199
217 [[nodiscard]] virtual std::unique_ptr<VcsObject> loadObject(const std::string& hash) const;
218
230 [[nodiscard]] bool objectExists(const std::string& hash) const;
231};
232
233}
Defines the interface for the Subject (Publisher) component of the Observer pattern.
Definition of the abstract base class for all Version Control System objects.
ObjectStorage(const std::string &root_path, const std::shared_ptr< ISubject > &subject=nullptr)
Constructor for ObjectStorage.
Definition ObjectStorage.cxx:36
void setSubject(std::shared_ptr< ISubject > subj)
Sets or replaces the event subject used by the ObjectStorage.
Definition ObjectStorage.hxx:106
virtual std::unique_ptr< VcsObject > loadObject(const std::string &hash) const
Loads an object from the disk by its hash ID.
Definition ObjectStorage.cxx:151
virtual ~ObjectStorage()
Destructor.
Definition ObjectStorage.cxx:61
bool objectExists(const std::string &hash) const
Checks if an object with the given hash exists on disk.
Definition ObjectStorage.cxx:358
std::string getObjectPath(const std::string &hash) const
Forms the full filesystem path for an object based on its hash.
Definition ObjectStorage.cxx:65
virtual bool saveObject(const VcsObject &obj) const
Saves a VcsObject to the object database.
Definition ObjectStorage.cxx:83
Abstract base class representing any storable, addressable object within the VCS.
Definition VcsObject.hxx:33
Core VCS data structures and object model.
Service layer components and infrastructure services.