Skip to content

Commit 8f22b22

Browse files
author
Tristan Youngs
committed
Data3D.
1 parent 4a1f3c8 commit 8f22b22

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/math/data3D.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,30 @@ bool Data3D::serialise(LineParser &parser) const
440440

441441
return true;
442442
}
443+
444+
// Express as a serialisable value
445+
void Data3D::serialise(std::string tag, SerialisedValue &target) const
446+
{
447+
target[tag] = {{"tag", tag_}, {"x", x_}, {"y", y_}, {"z", z_}, {"values", values_.linearArray()}};
448+
if (hasError_)
449+
target[tag]["errors"] = errors_.linearArray();
450+
}
451+
452+
// Read values from a serialisable value
453+
void Data3D::deserialise(const SerialisedValue &node)
454+
{
455+
tag_ = toml::find<std::string>(node, "tag");
456+
x_ = toml::find<std::vector<double>>(node, "x");
457+
y_ = toml::find<std::vector<double>>(node, "y");
458+
z_ = toml::find<std::vector<double>>(node, "z");
459+
values_.initialise(x_.size(), y_.size(), z_.size());
460+
values_.linearArray() = toml::find<std::vector<double>>(node, "values");
461+
462+
Serialisable::optionalOn(node, "errors",
463+
[this](const auto errors)
464+
{
465+
hasError_ = true;
466+
errors_.initialise(x_.size(), y_.size(), z_.size());
467+
errors_.linearArray() = toml::get<std::vector<double>>(errors);
468+
});
469+
}

src/math/data3D.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class Histogram3D;
1212

1313
// One-Dimensional Data
14-
class Data3D : public Data3DBase
14+
class Data3D : public Data3DBase, public Serialisable<>
1515
{
1616
public:
1717
Data3D();
@@ -122,4 +122,8 @@ class Data3D : public Data3DBase
122122
bool deserialise(LineParser &parser);
123123
// Write data through specified LineParser
124124
bool serialise(LineParser &parser) const;
125+
// Express as a serialisable value
126+
void serialise(std::string tag, SerialisedValue &target) const override;
127+
// Read values from a serialisable value
128+
void deserialise(const SerialisedValue &node) override;
125129
};

0 commit comments

Comments
 (0)