File tree Expand file tree Collapse file tree 3 files changed +17
-1
lines changed
Expand file tree Collapse file tree 3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -347,7 +347,12 @@ const ModuleStateHandle Module::get_state() const
347347
348348void Module::set_state (ModuleStateHandle state)
349349{
350- state_ = state;
350+ if (!state_)
351+ state_ = state;
352+ else if (state) // merge/overwrite
353+ {
354+ state_->overwriteWith (*state);
355+ }
351356 initStateObserver (state_.get ());
352357 postStateChangeInternalSignalHookup ();
353358}
Original file line number Diff line number Diff line change @@ -35,6 +35,14 @@ ModuleStateInterface::~ModuleStateInterface()
3535{
3636}
3737
38+ void ModuleStateInterface::overwriteWith (const ModuleStateInterface& other)
39+ {
40+ for (const auto & otherKey : other.getKeys ())
41+ {
42+ setValue (otherKey, other.getValue (otherKey).value ());
43+ }
44+ }
45+
3846ModuleStateInterfaceFactory::~ModuleStateInterfaceFactory ()
3947{
4048}
Original file line number Diff line number Diff line change @@ -61,6 +61,9 @@ namespace Networks {
6161 virtual bool containsKey (const Name& name) const = 0;
6262 virtual Keys getKeys () const = 0;
6363 virtual ModuleStateHandle clone () const = 0;
64+
65+ // this function preserves key/value pairs not in other
66+ void overwriteWith (const ModuleStateInterface& other);
6467
6568 // non-serialized state: algorithm output needing to be pushed, for instance--TODO: make classes instead of raw string/any
6669 typedef boost::any TransientValue;
You can’t perform that action at this time.
0 commit comments