25 const std::string& directory,
26 const std::string& prefix) {
28 return std::make_unique<BinaryArchive>(mode, directory, prefix);
30 return std::make_unique<MockArchive>(mode);
31 #ifdef SERIALBOX_HAS_NETCDF 33 return std::make_unique<NetCDFArchive>(mode, directory, prefix);
37 ss <<
"cannot create Archive '" << name <<
"': archive does not exist or is not registred.\n";
38 ss <<
"Registered archives:\n";
40 ss <<
" " << archive <<
"\n";
47 #ifdef SERIALBOX_HAS_NETCDF 56 std::string extension = filesystem::path(filename).extension().string();
58 if(extension ==
".dat" || extension ==
".bin")
60 #ifdef SERIALBOX_HAS_NETCDF 61 else if(extension ==
".nc")
65 throw Exception(
"cannot deduce Archive from file extension: %s", filename);
74 std::string archiveName, std::string fieldname) {
76 LOG(info) <<
"Attempting to write field \"" << fieldname <<
"\" via \"" << archiveName
77 <<
"\" archive from " << filename;
82 #ifdef SERIALBOX_HAS_NETCDF 88 throw Exception(
"cannot use Archive '%s': archive does not exist or is not registred",
91 LOG(info) <<
"Successfully wrote field \"" << fieldname <<
"\" to " << filename;
99 std::string archiveName, std::string fieldname) {
101 LOG(info) <<
"Attempting to read field \"" << fieldname <<
"\" via \"" << archiveName
102 <<
"\" archive from " << filename;
107 #ifdef SERIALBOX_HAS_NETCDF 113 throw Exception(
"cannot use Archive '%s': archive does not exist or is not registred",
116 LOG(info) <<
"Successfully read field \"" << fieldname <<
"\" to " << filename;
static std::string archiveFromExtension(std::string filename)
Deduce the name of the archive according to the extension of the filename
static void writeToFile(std::string filename, const StorageView &storageView)
Directly write field (given by storageView) to file.
static const std::string Name
Name of the binary archive.
static void readFromFile(std::string filename, StorageView &storageView)
Directly read field (given by storageView) from file.
static const std::string Name
Name of the NetCDF archive.
#define LOG(severity)
Logging infrastructure.
Represent a mutable view to a multi-dimensional storage.
static std::vector< std::string > registeredArchives()
Get a vector of strings of the registered archives.
Namespace of the serialbox library.
static void writeToFile(std::string filename, const StorageView &storageView, const std::string &field)
Directly write field (given by storageView) to file.
static std::unique_ptr< Archive > create(const std::string &name, OpenModeKind mode, const std::string &directory, const std::string &prefix)
Construct an instance of the archive ´name´
static void readFromFile(std::string filename, StorageView &storageView, std::string archiveName, std::string fieldname)
Directly read field (given by storageView) from file.
static void writeToFile(std::string filename, const StorageView &storageView, std::string archiveName, std::string fieldname)
Directly write field (given by storageView) to file.
static void readFromFile(std::string filename, StorageView &storageView, const std::string &field)
Directly read field (given by storageView) from file.
OpenModeKind
Policy for opening files in the Serializer and Archive.
static const std::string Name
Name of the Mock archive.
#define serialbox_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Exception class which stores a human-readable error description.