opensurgsim
Public Member Functions | Protected Member Functions | Friends | List of all members
SurgSim::DataStructures::IndexDirectory Class Reference

A simple bidirectional mapping between names (strings) and distinct consecutive non-negative indices. More...

#include <IndexDirectory.h>

Public Member Functions

 IndexDirectory ()
 Create an empty directory object.
 
 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...
 
IndexDirectoryoperator= (const IndexDirectory &directory)
 Assignment operator. More...
 
int addEntry (const std::string &name)
 Create a new entry for the specified name. 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/2]

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

Create a directory object initialized to a list of names.

Parameters
namesThe names.

§ IndexDirectory() [2/2]

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
nameThe 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
nameThe 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
indexThe 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
nameThe 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()

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