refactor:Serialisible concept - #2560
Draft
rprospero wants to merge 19 commits into
Draft
Conversation
Change toVector to simply vector Switch fromVector to just vector
rprospero
force-pushed
the
serialisible_concept
branch
from
July 24, 2026 13:58
99234da to
608a471
Compare
trisyoungs
reviewed
Jul 27, 2026
trisyoungs
left a comment
Member
There was a problem hiding this comment.
Direction is good. Made a couple of comments.
Comment on lines
+75
to
+92
| value["sites"] = | ||
| vector(sites_, [](const auto &sites) { return vector(sites, [](const auto isoWeight) { return isoWeight; }); }); | ||
| target[tag] = value; | ||
| } | ||
|
|
||
| // Read values from a serialisable value | ||
| void SpeciesSites::deserialise(const SerialisedValue &node) | ||
| { | ||
| using namespace Deserialisable; | ||
| clear(); | ||
|
|
||
| toMap(node, "set", | ||
| [&](const std::string &speciesName, const SerialisedValue &sites) | ||
| { | ||
| auto &set = sites_[speciesName]; | ||
| toMap(sites, [&](const std::string &siteName, const SerialisedValue &population) | ||
| { set[siteName] = population.as_floating(); }); | ||
| }); | ||
| map(node, "set", | ||
| [&](const std::string &speciesName, const SerialisedValue &sites) | ||
| { | ||
| auto &set = sites_[speciesName]; | ||
| map(sites, [&](const std::string &siteName, const SerialisedValue &population) | ||
| { set[siteName] = population.as_floating(); }); | ||
| }); |
Member
There was a problem hiding this comment.
I still have a problem with clarity here. I think this refactoring illustrates it pretty well - I'm supposedly serialising a vector, but deserialising a map. Admittedly this might be caused from the underlying type of sites_ being ResolvableKeyedVector, but you see my point!
rprospero
force-pushed
the
serialisible_concept
branch
from
July 28, 2026 13:16
d0a488a to
3c68748
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR replaces the old Serialisable class with class with a pair of concepts. This provides the following advantages
fromVectorandtoVectormethods, we now haveSerialisable::vectorandDeserialisable::vectormethodsfoo.serialise, which would fail iffoowas a string or a double. The newserialiseOntomethod works equally well with classes and raw typesThe fundamental theory of this library is that the overloaded
serialiseOntofunction serialises things anddeserialiseOntodeserialises things. Making a type serialisable merely involves adding another overload to these two functions. For simplicity, I've added a templated overload that works on any type that had the oldserialiseanddeserialisemethods that we used before, so most of the code is largely unchanged.I have the following changes I would like to perform before I pull this PR out of draft
As a guide for preliminary reviews, the best files to look at will be:
src/base/serialiser.his the new minimal header and establishes the new namespaces and theserialiseOntoanddeserialiseOntomethod signaturessrc/base/serialiserLibrary.hcontains both the actual serialisation concepts and the old helper functionssrc/classes/speciesSite.cppgives a good example on how the new library works (mostly the same with cleaner names).