24 void fillRandom(StorageView& storageView);
27 void fillRandom<double>(StorageView& storageView) {
28 std::minstd_rand generator(std::chrono::high_resolution_clock::now().time_since_epoch().count());
29 std::uniform_real_distribution<double> dist(-1.0, 1.0);
30 for(
auto it = storageView.begin(), end = storageView.end(); it != end; ++it) {
31 it.as<
double>() = dist(generator);
36 void fillRandom<float>(StorageView& storageView) {
37 std::minstd_rand generator(std::chrono::high_resolution_clock::now().time_since_epoch().count());
38 std::uniform_real_distribution<float> dist(-1.0f, 1.0f);
39 for(
auto it = storageView.begin(), end = storageView.end(); it != end; ++it)
40 it.as<
float>() = dist(generator);
44 void fillRandom<int>(StorageView& storageView) {
45 std::minstd_rand generator(std::chrono::high_resolution_clock::now().time_since_epoch().count());
46 std::uniform_int_distribution<int> dist(0, 100);
47 for(
auto it = storageView.begin(), end = storageView.end(); it != end; ++it)
48 it.as<
int>() = dist(generator);
52 void fillRandom<std::int64_t>(StorageView& storageView) {
53 std::minstd_rand generator(std::chrono::high_resolution_clock::now().time_since_epoch().count());
54 std::uniform_int_distribution<std::int64_t> dist(0, 100);
55 for(
auto it = storageView.begin(), end = storageView.end(); it != end; ++it)
56 it.as<std::int64_t>() = dist(generator);
60 void fillRandom<bool>(StorageView& storageView) {
61 std::minstd_rand generator(std::chrono::high_resolution_clock::now().time_since_epoch().count());
62 std::uniform_int_distribution<int> dist(0, 1);
63 for(
auto it = storageView.begin(), end = storageView.end(); it != end; ++it)
64 it.as<
bool>() = (bool)dist(generator);
72 : mode_(mode), directory_(
""), prefix_(
""), metaDataFile_(
"") {}
75 const std::shared_ptr<FieldMetainfoImpl> info) {
76 throw Exception(
"MockArchive does not support writing");
81 std::shared_ptr<FieldMetainfoImpl> info)
const {
82 switch(storageView.
type()) {
84 fillRandom<bool>(storageView);
87 fillRandom<int>(storageView);
90 fillRandom<std::int64_t>(storageView);
93 fillRandom<float>(storageView);
96 fillRandom<double>(storageView);
104 return (stream <<
"MockArchive");
virtual void read(StorageView &storageView, const FieldID &fieldID, std::shared_ptr< FieldMetainfoImpl > info) const override
Read the field identified by fieldID and given by storageView from disk.
Represent a mutable view to a multi-dimensional storage.
TypeID type() const noexcept
Get type.
Namespace of the serialbox library.
Uniquely identifiy a field.
virtual std::ostream & toStream(std::ostream &stream) const override
Convert the archive to stream.
virtual FieldID write(const StorageView &storageView, const std::string &fieldID, const std::shared_ptr< FieldMetainfoImpl > info) override
Write the field given by storageView to disk.
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.
MockArchive(OpenModeKind mode)
Initialize the archive.