Volume Cartographer 2.27.0
Protected Attributes | List of all members
volcart::Metadata Class Reference

Generic interface for storing metadata as key/value pairs. More...

#include <vc/core/types/Metadata.hpp>

Public Member Functions

 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...
 

Protected Attributes

nlohmann::json json_ {}
 
filesystem::path path_
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Metadata()

volcart::Metadata::Metadata ( const filesystem::path &  fileLocation)
explicit

Read a metadata file from disk.

Exceptions
volcart::IOException

Member Function Documentation

◆ 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_errorIf the key is not present.
Template Parameters
TValue 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
IOException

◆ set()

template<typename T >
void volcart::Metadata::set ( const std::string &  key,
value 
)
inline

Set a metadata key and value.

Template Parameters
TValue type. JSON library will store using the specified type.

Definition at line 99 of file Metadata.hpp.

Member Data Documentation

◆ json_

nlohmann::json volcart::Metadata::json_ {}
protected

JSON data storage

Definition at line 114 of file Metadata.hpp.

◆ 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: