Turi Create
4.0
|
#include <core/storage/serialization/dir_archive.hpp>
Public Member Functions | |
~dir_archive () | |
void | open_directory_for_write (std::string directory, bool fail_on_existing=false) |
void | open_directory_for_read (std::string directory) |
std::string | get_directory () const |
std::string | get_next_write_prefix () |
std::string | get_next_read_prefix () |
general_ifstream * | get_input_stream () |
general_ofstream * | get_output_stream () |
void | close () |
void | set_metadata (std::string key, std::string val) |
bool | get_metadata (std::string key, std::string &val) const |
Static Public Member Functions | |
static void | delete_archive (std::string directory) |
static bool | directory_has_existing_archive (const std::vector< std::pair< std::string, fileio::file_status > > &dircontents) |
The dir_archive object manages a directory archive. It is an internal class which provides two basic containers:
The directory archive provide management for the prefixes and the objects as well as directory archive creation / deletion.
To use:
Similarly, to read:
Definition at line 96 of file dir_archive.hpp.
turi::dir_archive::~dir_archive | ( | ) |
Destructor. Also closes.
void turi::dir_archive::close | ( | ) |
Closes the directory archive, committing all writes.
|
static |
Deletes the contents of an archive safely. (i.e. performing a non-recursive delete so we don't ever, even by accident, delete stuff we are not meant to delete).
It will delete the directory the archive is in if the directory is empty after deletion of all the archive files.
Never throws.
|
static |
Returns true if the directory contains an archive
std::string turi::dir_archive::get_directory | ( | ) | const |
Returns the current directory opened by either open_directory_for_read() or open_directory_for_write(); if nothing is opened, this returns an empty string.
general_ifstream* turi::dir_archive::get_input_stream | ( | ) |
Returns a pointer to the object stream reader. Returns NULL if the input directory is not opened for read.
bool turi::dir_archive::get_metadata | ( | std::string | key, |
std::string & | val | ||
) | const |
Reads any metadata associated with the archive. Returns true if the key exists, false otherwise.
std::string turi::dir_archive::get_next_read_prefix | ( | ) |
The directory must be opened for read. This returns the next prefix in the sequence of generated prefixes. The order of prefixes returns is the same order as the prefixes generated by get_next_write_prefix() when the archive was created.
std::string turi::dir_archive::get_next_write_prefix | ( | ) |
The directory must be opened for write. This returns a new prefix which can be written to.
general_ofstream* turi::dir_archive::get_output_stream | ( | ) |
Returns a pointer to the object stream writer. Returns NULL if the input directory is not opened for write.
void turi::dir_archive::open_directory_for_read | ( | std::string | directory | ) |
Opens a directory for reading. Directory must be an absolute path. This function will fail if the directory is not an archive.
Throws an exception with a string message if the directory cannot be opened.
void turi::dir_archive::open_directory_for_write | ( | std::string | directory, |
bool | fail_on_existing = false |
||
) |
Opens a directory for writing. Directory must be an absolute path.
if fail_on_existing is false: (default)
if fail_on_existing is true:
Throws an exception with a string message if the directory cannot be opened.
void turi::dir_archive::set_metadata | ( | std::string | key, |
std::string | val | ||
) |
Associates additional metadata with the archive that can be read back with get_metadata() when it is loaded.