Skip to content

Commit 7ea6f26

Browse files
committed
Preserve default state values
1 parent 1559d0a commit 7ea6f26

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/Dataflow/Network/Module.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,12 @@ const ModuleStateHandle Module::get_state() const
347347

348348
void 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
}

src/Dataflow/Network/ModuleStateInterface.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
3846
ModuleStateInterfaceFactory::~ModuleStateInterfaceFactory()
3947
{
4048
}

src/Dataflow/Network/ModuleStateInterface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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;

0 commit comments

Comments
 (0)