Skip to content

Commit

Permalink
#5613: Signal signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 15, 2021
1 parent bcfac23 commit 585880a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
14 changes: 8 additions & 6 deletions libs/selection/CollectiveSpawnargs.h
Expand Up @@ -24,23 +24,25 @@ class CollectiveSpawnargs
// Map Keys to Entities
std::map<std::string, std::set<Entity*>> _entitiesByKey;

sigc::signal<void()> _sigKeyAdded;
sigc::signal<void()> _sigKeyRemoved;
sigc::signal<void()> _sigKeyValueSetChanged;
sigc::signal<void(const std::string&, const std::string&)> _sigKeyAdded;
sigc::signal<void(const std::string&)> _sigKeyRemoved;
sigc::signal<void(const std::string&, const std::string&)> _sigKeyValueSetChanged;

public:
// Signal emitted when a new key is added to the collection
sigc::signal<void()>& signal_KeyAdded()
sigc::signal<void(const std::string&, const std::string&)>& signal_KeyAdded()
{
return _sigKeyAdded;
}

sigc::signal<void()>& signal_KeyValueSetChanged()
// Emitted when the value set of the given key changes. The second argument will contain the value
// provided it is the same for all entities
sigc::signal<void(const std::string&, const std::string&)>& signal_KeyValueSetChanged()
{
return _sigKeyValueSetChanged;
}

sigc::signal<void()>& signal_KeyRemoved()
sigc::signal<void(const std::string&)>& signal_KeyRemoved()
{
return _sigKeyRemoved;
}
Expand Down
25 changes: 22 additions & 3 deletions test/EntityInspector.cpp
Expand Up @@ -30,11 +30,19 @@ class KeyValueStore :
selection::EntitySelection _selectionTracker;

public:
static constexpr const char* DifferingValues = "[differing values]";

KeyValueStore()
{
_selectionTracker.getSpawnargs().signal_KeyAdded().connect(
sigc::mem_fun(this, &KeyValueStore::onKeyAdded)
);
_selectionTracker.getSpawnargs().signal_KeyRemoved().connect(
sigc::mem_fun(this, &KeyValueStore::onKeyRemoved)
);
_selectionTracker.getSpawnargs().signal_KeyValueSetChanged().connect(
sigc::mem_fun(this, &KeyValueStore::onKeyValueSetChanged)
);
}

std::map<std::string, std::string> store;
Expand All @@ -50,9 +58,19 @@ class KeyValueStore :
}

private:
void onKeyAdded()
void onKeyAdded(const std::string& key, const std::string& value)
{
store[key] = value;
}

void onKeyRemoved(const std::string& key)
{
store.erase(key);
}

void onKeyValueSetChanged(const std::string& key, const std::string& uniqueValue)
{
store[key] = uniqueValue.empty() ? DifferingValues : uniqueValue;
}
};

Expand All @@ -76,8 +94,9 @@ inline void expectNonUnique(const KeyValueStore& keyValueStore, const std::strin
return;
}

EXPECT_EQ(keyValueStore.store.at(key), "[differing values]") <<
"Key Value Store should contain " << key << " = [differing values], but value was " << keyValueStore.store.at(key);
EXPECT_EQ(keyValueStore.store.at(key), KeyValueStore::DifferingValues) <<
"Key Value Store should contain " << key << " = " << KeyValueStore::DifferingValues <<
", but value was " << keyValueStore.store.at(key);
}

inline void expectNotListed(const KeyValueStore& keyValueStore, const std::string& key)
Expand Down

0 comments on commit 585880a

Please sign in to comment.