45 #ifdef SVFS_THREAD_SAFE
46 std::lock_guard<std::mutex> mutex(
m_mutex);
48 auto result =
m_svfs.emplace(std::piecewise_construct,
49 std::forward_as_tuple(
id),
50 std::forward_as_tuple(
id, mod_time,
m_config));
51 if (! result.second) {
53 std::ostringstream os;
54 os <<
"SparseVirtualFileSystem::insert():";
55 os <<
" can not insert \"" <<
id <<
"\"";
67 #ifdef SVFS_THREAD_SAFE
68 std::lock_guard<std::mutex> mutex(
m_mutex);
70 auto iter =
m_svfs.find(
id);
71 if (iter ==
m_svfs.end()) {
72 std::ostringstream os;
73 os <<
"SparseVirtualFileSystem::remove():";
74 os <<
" id \"" <<
id <<
"\" not found.";
91 }
catch (std::out_of_range &err) {
106 }
catch (std::out_of_range &err) {
117 for (
auto &iter:
m_svfs) {
118 ret += iter.second.size_of();
129 for (
auto &iter:
m_svfs) {
130 ret += iter.second.num_bytes();
141 for (
auto &iter:
m_svfs) {
142 ret += iter.second.num_blocks();
152 std::vector<std::string> ret;
153 ret.reserve(
m_svfs.size());
154 for(
const auto &iter:
m_svfs) {
155 ret.push_back(iter.first);
162 for (
auto &iter:
m_svfs) {
Exception specialisation on insert error.
Exception specialisation for out of range error.
Exception specialisation on remove error.
Implementation of a Sparse Virtual File.
const SparseVirtualFile & at(const std::string &id) const
Return the const SparseVirtualFile at the given ID.
void insert(const std::string &id, double mod_time)
Inserts a new SparseVirtualFile corresponding to the given ID and file modification timestamp.
tSparseVirtualFileConfig m_config
The configuration for all SVF values.
SparseVirtualFileSystem(const tSparseVirtualFileConfig &config=tSparseVirtualFileConfig())
Constructor takes a tSparseVirtualFileConfig that is passed to every new SparseVirtualFile.
size_t num_blocks() const noexcept
Returns the total number of blocks in the SparseVirtualFileSystem.
size_t num_bytes() const noexcept
Returns the total number of readable bytes in the SparseVirtualFileSystem.
std::unordered_map< std::string, SparseVirtualFile > m_svfs
The key/value store of SVF values.
std::vector< std::string > keys() const noexcept
Return all the SVF IDs (unordered).
~SparseVirtualFileSystem() noexcept
Destructor.
void remove(const std::string &id)
Remove the SparseVirtualFile corresponding to the given ID.
size_t size_of() const noexcept
Returns the total in-memory size of the SparseVirtualFileSystem structure in bytes.
The namespace for all svfsc code.