All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes | List of all members
SurgSim::DataStructures::NamedDataBuilder< T > Class Template Reference

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

#include <SurgSim/DataStructures/NamedDataBuilder.h>

Collaboration diagram for SurgSim::DataStructures::NamedDataBuilder< T >:
Collaboration graph
[legend]

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

template<typename T>
SurgSim::DataStructures::NamedDataBuilder< T >::NamedDataBuilder ( )
inline

Constructs an empty builder object.

Member Function Documentation

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
namesThe names.
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
typenameU The data type of the other NamedDataBuilder.
Parameters
builderThe other builder.
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
typenameU The data type of the NamedData.
Parameters
dataThe data object.
template<typename T>
void SurgSim::DataStructures::NamedDataBuilder< T >::addEntriesFrom ( const IndexDirectory directory)
inline

Create new entries from an IndexDirectory.

Parameters
directoryThe index directory object.
template<typename T>
int SurgSim::DataStructures::NamedDataBuilder< T >::addEntry ( const std::string &  name)
inline

Creates a new entry for the specified name.

Parameters
nameThe 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.
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.
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.
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.
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
nameThe name.
Returns
the index for that name if one exists; -1 otherwise.
template<typename T>
std::string SurgSim::DataStructures::NamedDataBuilder< T >::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.
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()
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
nameThe name.
Returns
true if the entry exists.
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

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: