15 #ifndef SERIALBOX_CORE_SERIALIZERIMPL_H 16 #define SERIALBOX_CORE_SERIALIZERIMPL_H 105 const filesystem::path&
directory() const noexcept {
return directory_; }
108 std::string
prefix() const noexcept {
return prefix_; }
111 std::string
archiveName() const noexcept {
return archive_->name(); }
114 const filesystem::path&
metaDataFile() const noexcept {
return metaDataFile_; }
119 void clear() noexcept;
131 template <
class StringType,
class ValueType>
133 if(!globalMetainfo_->insert(std::forward<StringType>(key), std::forward<ValueType>(value)))
134 throw Exception(
"cannot add element with key '%s' to globalMetainfo: element already exists",
144 template <
class T,
class StringType>
147 return globalMetainfo_->at(key).template as<T>();
149 throw Exception(
"cannot get element with key '%s' from globalMetainfo: %s", key, e.what());
160 return globalMetainfo_;
173 template <
class StringType,
typename... Args>
175 if(!fieldMap_->insert(std::forward<StringType>(name), std::forward<Args>(args)...))
176 throw Exception(
"cannot register field '%s': field already exists", name);
183 template <
class StringType>
185 return fieldMap_->hasField(std::forward<StringType>(name));
196 template <
class StringType,
class KeyType,
class ValueType>
198 return fieldMap_->getMetainfoOf(name).insert(std::forward<KeyType>(key),
199 std::forward<ValueType>(value));
207 template <
class StringType>
209 return fieldMap_->getFieldMetainfoImplOf(std::forward<StringType>(name));
221 std::shared_ptr<FieldMap>&
fieldMapPtr() noexcept {
return fieldMap_; }
222 const std::shared_ptr<FieldMap>&
fieldMapPtr()
const noexcept {
return fieldMap_; }
232 template <
typename... Args>
234 return (savepointVector_->insert(
SavepointImpl(std::forward<Args>(args)...)) != -1);
240 return savepointVector_->addField(savepoint, fieldID);
247 return savepointVector_->getFieldID(savepoint, field);
252 return savepointVector_->savepoints();
255 return savepointVector_->savepoints();
264 return savepointVector_;
266 std::shared_ptr<SavepointVector>&
savepointVectorPtr() noexcept {
return savepointVector_; }
380 json::json
toJSON()
const;
406 std::shared_ptr<FieldMetainfoImpl>
checkStorageView(
const std::string& name,
430 filesystem::path directory_;
431 filesystem::path metaDataFile_;
434 std::shared_ptr<SavepointVector> savepointVector_;
435 std::shared_ptr<FieldMap> fieldMap_;
436 std::shared_ptr<MetainfoMapImpl> globalMetainfo_;
438 std::unique_ptr<Archive> archive_;
const std::shared_ptr< SavepointVector > & savepointVectorPtr() const noexcept
Get pointer to SavepointVector.
void readAsync(const std::string &name, const SavepointImpl &savepoint, StorageView &storageView)
Asynchronously deserialize field name (given as storageView) at savepoint from disk using std::async...
void registerField(StringType &&name, Args &&... args)
Register a new field within the Serializer.
std::vector< std::shared_ptr< SavepointImpl > > savepoint_vector_type
Vector of savepoints.
std::shared_ptr< MetainfoMapImpl > & globalMetainfoPtr() noexcept
Get pointer to the global meta information.
const SavepointVector & savepointVector() const noexcept
Get refrence to SavepointVector.
OpenModeKind mode() const noexcept
Access the mode of the serializer.
void constructArchive(const std::string &archiveName)
Construct Archive from JSON.
void updateMetaData()
Convert meta-data to JSON and serialize to MetaData-prefix.json and ArchiveMetaData-prefix.json.
static int serializationStatus() noexcept
Get the status of serialization.
void readAsyncImpl(const std::string name, const SavepointImpl savepoint, StorageView storageView)
Implementation of SerializerImpl::readAsync.
void addGlobalMetainfo(StringType &&key, ValueType &&value)
Add a new key-value pair to the global meta-information of the Serializer.
friend std::ostream & operator<<(std::ostream &stream, const SerializerImpl &s)
Convert to stream.
Represent a mutable view to a multi-dimensional storage.
const SavepointVector::savepoint_vector_type & savepoints() const noexcept
Get refrence to savepoint vector.
FieldID getFieldIDAtSavepoint(const SavepointImpl &savepoint, const std::string &field) const
Get the FielID of field field at savepoint savepoint
MetainfoMapImpl & globalMetainfo() noexcept
Get a refrence to the global meta information.
std::shared_ptr< FieldMap > & fieldMapPtr() noexcept
Get pointer to the field map.
Namespace of the serialbox library.
static void disableSerialization() noexcept
Disable serialization.
std::string toString() const
Convert to string.
std::shared_ptr< FieldMetainfoImpl > checkStorageView(const std::string &name, const StorageView &storageView) const
Check if storageView is consistent with the field name
bool upgradeMetaData()
Check if the current directory contains meta-information of an older version of serialbox and upgrade...
Shared implementation of the Serializer.
Uniquely identifiy a field.
const filesystem::path & metaDataFile() const noexcept
Access the path to the meta-data file.
bool addFieldToSavepoint(const SavepointImpl &savepoint, const FieldID &fieldID) noexcept
Add a field to the savepoint.
The SavepointVector manages the registered savepoints and their mapping to the stored fields...
std::vector< std::string > fieldnames() const
Get a vector of all registered fields.
void constructMetaDataFromJson()
Construct meta-data from JSON.
SerializerImpl & operator=(const SerializerImpl &)=delete
Copy assignment [deleted].
const filesystem::path & directory() const noexcept
Access the directory in which the Serializer and Archive are opened.
void write(const std::string &name, const SavepointImpl &savepoint, const StorageView &storageView)
Serialize field name (given as storageView) at savepoint to disk.
T getGlobalMetainfoAs(StringType &&key) const
Query globalMetainfo map for key key and retrieve value as type T
OpenModeKind
Policy for opening files in the Serializer and Archive.
static void enableSerialization() noexcept
Enable serialization.
std::string prefix() const noexcept
Access prefix of all filenames.
json::json toJSON() const
Convert all members of the Serializer to JSON.
void readSliced(const std::string &name, const SavepointImpl &savepoint, StorageView &storageView, Slice slice)
Deserialize sliced field name (given as storageView and slice) at savepoint from disk.
std::string archiveName() const noexcept
Name of the archive in use.
bool registerSavepoint(Args &&... args) noexcept
Register a savepoint.
const FieldMetainfoImpl & getFieldMetainfoImplOf(StringType &&name) const
Query FieldMap for field with name and return a refrence to FieldMetainfoImpl.
bool hasField(StringType &&name) const noexcept
Check if field name has been registred within the Serializer.
Specification of the slice indices which is used for partial loading of serialized data...
Exception class which stores a human-readable error description.
void clear() noexcept
Drop all field and savepoint meta-data.
SerializerImpl(const SerializerImpl &)=delete
Copy constructor [deleted].
Hash-map to query the meta-information of the registered fields.
Shared implementation of the Savepoint.
FieldMap & fieldMap() noexcept
Get refrence to the field map.
void read(const std::string &name, const SavepointImpl &savepoint, StorageView &storageView, bool alsoPrevious=false)
Deserialize field name (given as storageView) at savepoint from disk.
void waitForAll()
Wait for all pending asynchronous read operations and reset the internal queue.
bool addFieldMetainfoImpl(StringType &&name, KeyType &&key, ValueType &&value)
Add key = value or key = {value1, ..., valueN} meta-information to field name