Generic interface for storing metadata as key/value pairs.
More...
#include <vc/core/types/Metadata.hpp>
|
|
|
| Metadata ()=default |
| | Default constructor.
|
| |
| | Metadata (const filesystem::path &fileLocation) |
| | Read a metadata file from disk. More...
|
| |
|
|
auto | path () const -> filesystem::path |
| | Get the path where the metadata file will be written.
|
| |
|
void | setPath (const filesystem::path &path) |
| | Set the path where the metadata file will be written.
|
| |
| void | save () const |
| | Save the metadata file to the stored path. More...
|
| |
|
void | save (const filesystem::path &path) const |
| | Save the metadata file to a specified path.
|
| |
|
|
auto | hasKey (const std::string &key) const -> bool |
| | Return whether the given key is defined.
|
| |
| template<typename T > |
| auto | get (const std::string &key) const -> std::optional< T > |
| | Get a metadata value by key. More...
|
| |
| template<typename T > |
| void | set (const std::string &key, T value) |
| | Set a metadata key and value. More...
|
| |
| void | printObject () const |
| | Print an object representation of the metadata to std::cout. More...
|
| |
Generic interface for storing metadata as key/value pairs.
- Author
- Sean Karlage, Seth Parker
- Date
- 10/27/15
Internally uses JSON for Modern C++ for easy storage and [de]serialization: https://nlohmann.github.io/json/
Definition at line 26 of file Metadata.hpp.
◆ Metadata()
| volcart::Metadata::Metadata |
( |
const filesystem::path & |
fileLocation | ) |
|
|
explicit |
Read a metadata file from disk.
- Exceptions
-
◆ get()
template<typename T >
| auto volcart::Metadata::get |
( |
const std::string & |
key | ) |
const -> std::optional<T>
|
|
inline |
Get a metadata value by key.
If the stored value is convertible to T, the returned optional will have an assigned value. If the stored value is null, the returned optional will have no value. This can be checked with result.has_value(), and the value can be retrieved with result.value().
- Exceptions
-
| std::runtime_error | If the key is not present. |
- Template Parameters
-
| T | Value return type. JSON library will attempt to convert to the specified type. |
Definition at line 79 of file Metadata.hpp.
◆ printObject()
| void volcart::Metadata::printObject |
( |
| ) |
const |
Print an object representation of the metadata to std::cout.
- Warning
- This should only be used for debugging.
◆ save()
| void volcart::Metadata::save |
( |
| ) |
const |
Save the metadata file to the stored path.
- Exceptions
-
◆ set()
template<typename T >
| void volcart::Metadata::set |
( |
const std::string & |
key, |
|
|
T |
value |
|
) |
| |
|
inline |
Set a metadata key and value.
- Template Parameters
-
| T | Value type. JSON library will store using the specified type. |
Definition at line 99 of file Metadata.hpp.
◆ json_
| nlohmann::json volcart::Metadata::json_ {} |
|
protected |
◆ path_
| filesystem::path volcart::Metadata::path_ |
|
protected |
Location where the JSON file will be stored
Definition at line 116 of file Metadata.hpp.
The documentation for this class was generated from the following file: