![]() |
A simple bidirectional mapping between names (strings) and distinct consecutive non-negative indices. More...
#include <SurgSim/DataStructures/IndexDirectory.h>
Public Member Functions | |
IndexDirectory () | |
Create an empty directory object. More... | |
IndexDirectory (const std::vector< std::string > &names) | |
Create a directory object initialized to a list of names. More... | |
int | getIndex (const std::string &name) const |
Given a name, return the corresponding index (or -1). More... | |
std::string | getName (int index) const |
Given an index, return the corresponding name (or ""). More... | |
const std::vector< std::string > & | getAllNames () const |
Get a list of all the names available from the index directory. More... | |
bool | hasEntry (const std::string &name) const |
Check whether the specified name exists in the directory. More... | |
size_t | size () const |
Check the number of existing entries in the directory. More... | |
int | getNumEntries () const |
Check the number of existing entries in the directory. More... | |
Protected Member Functions | |
IndexDirectory (const IndexDirectory &directory) | |
Copy constructor. More... | |
IndexDirectory & | operator= (const IndexDirectory &directory) |
Assignment operator. More... | |
int | addEntry (const std::string &name) |
Create a new entry for the specified name. More... | |
Private Attributes | |
std::vector< std::string > | m_names |
The array of entry names, in index order. More... | |
std::unordered_map< std::string, int > | m_indices |
A mapping of entry names to indices. More... | |
Friends | |
template<typename T > | |
class | NamedDataBuilder |
class | DataGroupBuilder |
A simple bidirectional mapping between names (strings) and distinct consecutive non-negative indices.
Access to this class is thread-safe if all of the threads are only performing const operations, i.e. reading the names and indices.
SurgSim::DataStructures::IndexDirectory::IndexDirectory | ( | ) |
Create an empty directory object.
|
explicit |
Create a directory object initialized to a list of names.
names | The names. |
|
protected |
Copy constructor.
Not generally accessible by external code, but is used by friend classes.
|
protected |
Create a new entry for the specified name.
Not generally accessible by external code, but is used by friend classes.
name | The name, which should be non-empty and should not already exist in the directory. |
const std::vector< std::string > & SurgSim::DataStructures::IndexDirectory::getAllNames | ( | ) | const |
Get a list of all the names available from the index directory.
|
inline |
Given a name, return the corresponding index (or -1).
name | The name. |
|
inline |
Given an index, return the corresponding name (or "").
index | The index. |
|
inline |
Check the number of existing entries in the directory.
|
inline |
Check whether the specified name exists in the directory.
name | The name. |
|
protected |
Assignment operator.
Not generally accessible by external code, but is used by friend classes.
|
inline |
Check the number of existing entries in the directory.
|
friend |
|
friend |
|
private |
A mapping of entry names to indices.
|
private |
The array of entry names, in index order.