SurgSim::DataStructures::IndexDirectory Class Reference

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

## Detailed Description

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.

## Constructor & Destructor Documentation

## IndexDirectory() [1/3]

SurgSim::DataStructures::IndexDirectory::IndexDirectory | ( |  | ) |

Create an empty directory object.

## IndexDirectory() [2/3]

SurgSim::DataStructures::IndexDirectory::IndexDirectory | ( | const std::vector< std::string > & | names | ) |

explicit

Create a directory object initialized to a list of names.

Parameters

  names | The names.

## IndexDirectory() [3/3]

SurgSim::DataStructures::IndexDirectory::IndexDirectory | ( | const IndexDirectory & | directory | ) |

protected

Copy constructor.

Not generally accessible by external code, but is used by friend classes.

See also
  NamedDataBuilder, DataGroupBuilder

## Member Function Documentation

## addEntry()

int SurgSim::DataStructures::IndexDirectory::addEntry | ( | const std::string & | name | ) |

protected

Create a new entry for the specified name.

Not generally accessible by external code, but is used by friend classes.

See also
  NamedDataBuilder, DataGroupBuilder

Parameters

  name | The name, which should be non-empty and should not already exist in the directory.

Returns
  the index of the created entry, or -1 if the entry could not be added.

## getAllNames()

const std::vector< std::string > & SurgSim::DataStructures::IndexDirectory::getAllNames | ( |  | ) | const

Get a list of all the names available from the index directory.

Returns
  all the names, in index order.

## getIndex()

int SurgSim::DataStructures::IndexDirectory::getIndex | ( | const std::string & | name | ) | const

inline

Given a name, return the corresponding index (or -1).

Parameters

  name | The name.

Returns
  the index for that name if one exists; -1 otherwise.

## getName()

std::string SurgSim::DataStructures::IndexDirectory::getName | ( | int | index | ) | const

inline

Given an index, return the corresponding name (or "").

Parameters

  index | The index.

Returns
  the name for that index if one exists; an empty string otherwise.

## getNumEntries()

int SurgSim::DataStructures::IndexDirectory::getNumEntries | ( |  | ) | const

inline

Check the number of existing entries in the directory.

Returns
  the size of the directory.

See also
  size()

## hasEntry()

bool SurgSim::DataStructures::IndexDirectory::hasEntry | ( | const std::string & | name | ) | const

inline

Check whether the specified name exists in the directory.

Parameters

  name | The name.

Returns
  true if the entry exists.

## operator=()

IndexDirectory & SurgSim::DataStructures::IndexDirectory::operator= | ( | const IndexDirectory & | directory | ) |

protected

Assignment operator.

Not generally accessible by external code, but is used by friend classes.

See also
  NamedDataBuilder, DataGroupBuilder

## size()

size_t SurgSim::DataStructures::IndexDirectory::size | ( |  | ) | const

inline

Check the number of existing entries in the directory.

Returns
  the size of the directory.

See also
  getNumEntries()

## Friends And Related Function Documentation

## DataGroupBuilder

friend class DataGroupBuilder

friend

## NamedDataBuilder

template<typename T >

friend class NamedDataBuilder

friend

## Member Data Documentation

## m_indices

std::unordered_map<std::string, int> SurgSim::DataStructures::IndexDirectory::m_indices

private

A mapping of entry names to indices.

## m_names

std::vector<std::string> SurgSim::DataStructures::IndexDirectory::m_names

private

The array of entry names, in index order.

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

- SurgSim/DataStructures/IndexDirectory.h
- SurgSim/DataStructures/IndexDirectory.cpp