Class to wrap grouping operations, gives access to the members of a group and the groups of members.
More...
#include <SurgSim/DataStructures/Groups.h>
|
bool | add (const Key &group, const T &element) |
| Add an element to the given group, if the group doesn't exist it will be created, if the element is already a member of the group, nothing happens. More...
|
|
bool | add (const std::vector< Key > &groups, const T &element) |
| Add a member to the given groups, if any of the groups don't exist they will be created, if the element is already a member of a group, it won't be added to that specific group. More...
|
|
bool | add (const Groups< Key, T > &other) |
| Add all the members from the other group to this group, essentially forming a union of the two. More...
|
|
bool | remove (const Key &group, const T &element) |
| Remove an element from a given group, if the group does not exist or the element is not a member of that group, nothing will happen. More...
|
|
bool | remove (const T &element) |
| Remove an element from all known groups, if the element is not a member of any group, nothing happens. More...
|
|
std::vector< T > | getMembers (const Key &group) const |
| Return all the members of the given group. More...
|
|
std::vector< Key > | getGroups (const T &element) const |
| Return all the groups that the given member is a member of. More...
|
|
std::vector< Key > | getGroups () const |
|
std::vector< T > | operator[] (const Key &group) const |
| Return all the members of the given group. More...
|
|
void | clear () |
| Erases all entries. More...
|
|
|
typedef boost::shared_lock< boost::shared_mutex > | SharedLock |
|
typedef boost::unique_lock< boost::shared_mutex > | UniqueLock |
|
|
boost::shared_mutex | m_mutex |
| The mutex used to lock for reading and writing. More...
|
|
std::unordered_map< Key, std::unordered_set< T > > | m_groups |
| Map groups to members. More...
|
|
std::unordered_map< T, std::unordered_set< Key > > | m_membership |
| Map members to groups. More...
|
|
template<typename Key, typename T>
class SurgSim::DataStructures::Groups< Key, T >
Class to wrap grouping operations, gives access to the members of a group and the groups of members.
Groups is threadsafe with regard to add and remove operations, and observations
- Template Parameters
-
Key | the label to be used for the groups |
T | the type of the group members |
◆ IdentifierType
template<typename Key, typename T>
◆ MemberType
template<typename Key, typename T>
◆ SharedLock
template<typename Key, typename T>
◆ UniqueLock
template<typename Key, typename T>
◆ add() [1/3]
template<typename Key, typename T>
Add all the members from the other group to this group, essentially forming a union of the two.
- Parameters
-
other | object to add groups from |
- Returns
- true if at least one new element was added
◆ add() [2/3]
template<typename Key, typename T>
Add an element to the given group, if the group doesn't exist it will be created, if the element is already a member of the group, nothing happens.
- Parameters
-
group | the group to use |
element | the element to add |
- Returns
- true if the element was actually added to the group
◆ add() [3/3]
template<typename Key, typename T>
Add a member to the given groups, if any of the groups don't exist they will be created, if the element is already a member of a group, it won't be added to that specific group.
- Parameters
-
groups | the groups to use |
element | the element to add |
- Returns
- true if the element was added to at least one group
◆ clear()
template<typename Key , typename T >
◆ getGroups() [1/2]
template<typename Key , typename T>
- Returns
- all the known groups that have members
◆ getGroups() [2/2]
template<typename Key , typename T>
Return all the groups that the given member is a member of.
- Parameters
-
element | the element to query |
- Returns
- groups which contain the given element, empty if the element is not member of any group
◆ getMembers()
template<typename Key, typename T >
Return all the members of the given group.
- Parameters
-
- Returns
- members of the given group, empty if the group has no members, or doesn't exist
◆ operator[]()
template<typename Key, typename T >
Return all the members of the given group.
- Parameters
-
- Returns
- members of the given group, empty if the group has no members
◆ remove() [1/2]
template<typename Key, typename T>
Remove an element from a given group, if the group does not exist or the element is not a member of that group, nothing will happen.
- Parameters
-
group | the group to use |
element | the element to remove |
- Returns
- true if the element was member of that group
◆ remove() [2/2]
template<typename Key, typename T>
Remove an element from all known groups, if the element is not a member of any group, nothing happens.
- Parameters
-
element | the element to remove |
- Returns
- true if there was an actual removal that was executed
◆ m_groups
template<typename Key, typename T>
◆ m_membership
template<typename Key, typename T>
◆ m_mutex
template<typename Key, typename T>
The mutex used to lock for reading and writing.
The documentation for this class was generated from the following files: