SurgSim::DataStructures::NamedDataBuilder< T > Class Template Reference

A class that allows you to build a NamedData structure. More...

`#include <SurgSim/DataStructures/NamedDataBuilder.h>`

## Public Member Functions

| NamedDataBuilder ()
| Constructs an empty builder object. More...
NamedData< T > | createData () const
| Produces a NamedData object with an immutable set of names and indices. More...
std::shared_ptr< NamedData< T > > | createSharedData () const
| Produces a shared pointer to an empty NamedData object with an immutable set of names and indices. More...
int | addEntry (const std::string &name)
| Creates a new entry for the specified name. More...
void | addEntriesFrom (const std::vector< std::string > &names)
| Create new entries from a vector of names. More...
template<typename U >
void | addEntriesFrom (const NamedDataBuilder< U > &builder)
| Create new entries from another NamedDataBuilder. More...
template<typename U >
void | addEntriesFrom (const NamedData< U > &data)
| Create new entries from an already initialized NamedData. More...
void | addEntriesFrom (const IndexDirectory &directory)
| Create new entries from an IndexDirectory. 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 in the builder. More...
bool | hasEntry (const std::string &name) const
| Check whether the specified name exists in the builder. More...
size_t | size () const
| Check the number of existing entries in the builder. More...
int | getNumEntries () const
| Check the number of existing entries in the builder. More...

## Private Attributes

IndexDirectory | m_directory
| The mapping between names and indices that will be used to create the NamedData instance. More...

## Detailed Description

### template<typename T>
class SurgSim::DataStructures::NamedDataBuilder< T >

A class that allows you to build a NamedData structure.

Since the data layout of a NamedData object cannot be modified, this class can be helpful in initially setting up the names and their corresponding indices. You can add entries to the builder using addEntry and addEntriesFrom calls, then create the NamedData instance with createData() or createSharedData().

See also
  NamedData

## Constructor & Destructor Documentation

## NamedDataBuilder()

template<typename T>

SurgSim::DataStructures::NamedDataBuilder< T >::NamedDataBuilder | ( |  | ) |

inline

Constructs an empty builder object.

## Member Function Documentation

## addEntriesFrom() [1/4]

template<typename T>

void SurgSim::DataStructures::NamedDataBuilder< T >::addEntriesFrom | ( | const std::vector< std::string > & | names | ) |

inline

Create new entries from a vector of names.

Parameters

  names | The names.

## addEntriesFrom() [2/4]

template<typename T>
template<typename U >

void SurgSim::DataStructures::NamedDataBuilder< T >::addEntriesFrom | ( | const NamedDataBuilder< U > & | builder | ) |

inline

Create new entries from another NamedDataBuilder.

Template Parameters

  typename | U The data type of the other NamedDataBuilder.

Parameters

  builder | The other builder.

## addEntriesFrom() [3/4]

template<typename T>
template<typename U >

void SurgSim::DataStructures::NamedDataBuilder< T >::addEntriesFrom | ( | const NamedData< U > & | data | ) |

inline

Create new entries from an already initialized NamedData.

Template Parameters

  typename | U The data type of the NamedData.

Parameters

  data | The data object.

## addEntriesFrom() [4/4]

template<typename T>

void SurgSim::DataStructures::NamedDataBuilder< T >::addEntriesFrom | ( | const IndexDirectory & | directory | ) |

inline

Create new entries from an IndexDirectory.

Parameters

  directory | The index directory object.

## addEntry()

template<typename T>

int SurgSim::DataStructures::NamedDataBuilder< T >::addEntry | ( | const std::string & | name | ) |

inline

Creates a new entry for the specified name.

Parameters

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

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

## createData()

template<typename T>

NamedData<T> SurgSim::DataStructures::NamedDataBuilder< T >::createData | ( |  | ) | const

inline

Produces a NamedData object with an immutable set of names and indices.

None of the values will contain any current data.

Returns
  the NamedData object by value.

## createSharedData()

template<typename T>

std::shared_ptr<NamedData<T> > SurgSim::DataStructures::NamedDataBuilder< T >::createSharedData | ( |  | ) | const

inline

Produces a shared pointer to an empty NamedData object with an immutable set of names and indices.

None of the values will contain any current data.

Returns
  a shared pointer to the NamedData object.

## getAllNames()

template<typename T>

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

inline

Get a list of all the names available in the builder.

Returns
  all the names.

## getIndex()

template<typename T>

int SurgSim::DataStructures::NamedDataBuilder< T >::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()

template<typename T>

std::string SurgSim::DataStructures::NamedDataBuilder< T >::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()

template<typename T>

int SurgSim::DataStructures::NamedDataBuilder< T >::getNumEntries | ( |  | ) | const

inline

Check the number of existing entries in the builder.

Returns
  the number of entries.

See also
  size()

## hasEntry()

template<typename T>

bool SurgSim::DataStructures::NamedDataBuilder< T >::hasEntry | ( | const std::string & | name | ) | const

inline

Check whether the specified name exists in the builder.

Parameters

  name | The name.

Returns
  true if the entry exists.

## size()

template<typename T>

size_t SurgSim::DataStructures::NamedDataBuilder< T >::size | ( |  | ) | const

inline

Check the number of existing entries in the builder.

Returns
  the number of entries.

See also
  getNumEntries()

## Member Data Documentation

## m_directory

template<typename T>

IndexDirectory SurgSim::DataStructures::NamedDataBuilder< T >::m_directory

private

The mapping between names and indices that will be used to create the NamedData instance.

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

- SurgSim/DataStructures/NamedDataBuilder.h