Go to the documentation of this file.
16 #ifndef SURGSIM_DATASTRUCTURES_GROUPS_H
17 #define SURGSIM_DATASTRUCTURES_GROUPS_H
19 #include <unordered_map>
20 #include <unordered_set>
23 #include <boost/thread.hpp>
29 namespace DataStructures
36 template <
typename Key,
typename T>
49 bool add(
const Key& group,
const T& element);
56 bool add(
const std::vector<Key>& groups,
const T& element);
68 bool remove(
const Key& group,
const T& element);
73 bool remove(
const T& element);
78 std::vector<T>
getMembers(
const Key& group)
const;
83 std::vector<Key>
getGroups(
const T& element)
const;
91 std::vector<T>
operator[](
const Key& group)
const;
99 typedef boost::shared_lock<boost::shared_mutex>
SharedLock;
106 std::unordered_map<Key, std::unordered_set<T>>
m_groups;
Class to wrap grouping operations, gives access to the members of a group and the groups of members.
Definition: Groups.h:37
boost::shared_lock< boost::shared_mutex > SharedLock
Definition: Groups.h:99
Definition: CompoundShapeToGraphics.cpp:29
std::vector< T > getMembers(const Key &group) const
Return all the members of the given group.
Definition: Groups-inl.h:91
std::unordered_map< T, std::unordered_set< Key > > m_membership
Map members to groups.
Definition: Groups.h:109
T MemberType
Definition: Groups.h:42
boost::shared_mutex m_mutex
The mutex used to lock for reading and writing.
Definition: Groups.h:103
Key IdentifierType
Definition: Groups.h:41
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 a...
Definition: Groups-inl.h:25
std::vector< Key > getGroups() const
Definition: Groups-inl.h:117
boost::unique_lock< boost::shared_mutex > UniqueLock
Definition: Groups.h:100
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 t...
Definition: Groups-inl.h:62
std::unordered_map< Key, std::unordered_set< T > > m_groups
Map groups to members.
Definition: Groups.h:106
void clear()
Erases all entries.
Definition: Groups-inl.h:157
std::vector< T > operator[](const Key &group) const
Return all the members of the given group.
Definition: Groups-inl.h:149