opensurgsim
Public Types | Public Member Functions | List of all members
SurgSim::DataStructures::Groups< Key, T > Class Template Reference

Class to wrap grouping operations, gives access to the members of a group and the groups of members. More...

#include <Groups.h>

Public Types

typedef Key IdentifierType
 
typedef T MemberType
 

Public Member Functions

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.
 

Detailed Description

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
Keythe label to be used for the groups
Tthe type of the group members

Member Function Documentation

§ add() [1/3]

template<typename Key, typename T>
bool SurgSim::DataStructures::Groups< Key, T >::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.

Parameters
groupthe group to use
elementthe element to add
Returns
true if the element was actually added to the group

§ add() [2/3]

template<typename Key, typename T>
bool SurgSim::DataStructures::Groups< Key, T >::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.

Parameters
groupsthe groups to use
elementthe element to add
Returns
true if the element was added to at least one group

§ add() [3/3]

template<typename Key, typename T>
bool SurgSim::DataStructures::Groups< Key, T >::add ( const Groups< Key, T > &  other)

Add all the members from the other group to this group, essentially forming a union of the two.

Parameters
otherobject to add groups from
Returns
true if at least one new element was added

§ getGroups() [1/2]

template<typename Key , typename T>
std::vector< Key > SurgSim::DataStructures::Groups< Key, T >::getGroups ( const T &  element) const

Return all the groups that the given member is a member of.

Parameters
elementthe element to query
Returns
groups which contain the given element, empty if the element is not member of any group

§ getGroups() [2/2]

template<typename Key , typename T>
std::vector< Key > SurgSim::DataStructures::Groups< Key, T >::getGroups ( ) const
Returns
all the known groups that have members

§ getMembers()

template<typename Key, typename T >
std::vector< T > SurgSim::DataStructures::Groups< Key, T >::getMembers ( const Key &  group) const

Return all the members of the given group.

Parameters
groupthe group to query
Returns
members of the given group, empty if the group has no members, or doesn't exist

§ operator[]()

template<typename Key, typename T >
std::vector< T > SurgSim::DataStructures::Groups< Key, T >::operator[] ( const Key &  group) const

Return all the members of the given group.

Parameters
groupgroup to query
Returns
members of the given group, empty if the group has no members

§ remove() [1/2]

template<typename Key, typename T>
bool SurgSim::DataStructures::Groups< Key, T >::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.

Parameters
groupthe group to use
elementthe element to remove
Returns
true if the element was member of that group

§ remove() [2/2]

template<typename Key, typename T>
bool SurgSim::DataStructures::Groups< Key, T >::remove ( const T &  element)

Remove an element from all known groups, if the element is not a member of any group, nothing happens.

Parameters
elementthe element to remove
Returns
true if there was an actual removal that was executed

The documentation for this class was generated from the following files: