Volume Cartographer 2.27.0
DiskBasedObjectBaseClass.hpp
Go to the documentation of this file.
1#pragma once
2
7
8namespace volcart
9{
26{
27public:
29 using Identifier = std::string;
30
32 using Description = std::pair<Identifier, std::string>;
33
36
38 [[nodiscard]] Identifier id() const;
39
41 [[nodiscard]] auto path() const -> filesystem::path;
42
44 [[nodiscard]] auto name() const -> std::string;
45
47 void setName(std::string n);
48
60 template <typename T>
61 void setMetadataEntry(const std::string& key, T value)
62 {
63 metadata_.set(key, value);
64 }
65
71 template <typename T>
72 auto getMetadataEntry(const std::string& key) const -> std::optional<T>
73 {
74 return metadata_.get<T>(key);
75 }
76
78 void saveMetadata() const;
79
80protected:
82 explicit DiskBasedObjectBaseClass(filesystem::path path);
83
86 filesystem::path path, Identifier uuid, std::string name);
87
90
92 filesystem::path path_;
93};
94} // namespace volcart
Base class for objects stored on disk with an associated metadata file.
void setMetadataEntry(const std::string &key, T value)
Set a metadata entry.
std::pair< Identifier, std::string > Description
auto path() const -> filesystem::path
Get the path to the object.
auto getMetadataEntry(const std::string &key) const -> std::optional< T >
Get a metadata entry.
Identifier id() const
Get the "unique" ID for the object.
DiskBasedObjectBaseClass(filesystem::path path, Identifier uuid, std::string name)
auto name() const -> std::string
Get the human-readable name for the object.
void saveMetadata() const
Update metadata on disk.
void setName(std::string n)
Set the human-readable name of the object.
DiskBasedObjectBaseClass(filesystem::path path)
Generic interface for storing metadata as key/value pairs.
Definition: Metadata.hpp:27
void set(const std::string &key, T value)
Set a metadata key and value.
Definition: Metadata.hpp:99
auto get(const std::string &key) const -> std::optional< T >
Get a metadata value by key.
Definition: Metadata.hpp:79
Volume Cartographer library