opensurgsim
Public Member Functions | List of all members
SurgSim::DataStructures::NamedVariantData Class Reference

A NamedData collection of variant data type. More...

#include <NamedVariantData.h>

Inheritance diagram for SurgSim::DataStructures::NamedVariantData:
SurgSim::DataStructures::NamedData< boost::any >

Public Member Functions

 NamedVariantData (const NamedData< boost::any > &namedData)
 Implicit conversion for NamedVariantData constructor is used on purpose.
 
template<typename T >
bool hasTypedData (int index) const
 Check whether the entry with the specified index contains valid data. More...
 
template<typename T >
bool hasTypedData (const std::string &name) const
 Check whether the entry with the specified name contains valid data. More...
 
template<typename T >
bool get (int index, T *value) const
 Given an index, get the corresponding value. More...
 
template<typename T >
bool get (const std::string &name, T *value) const
 Given a name, get the corresponding value. More...
 
- Public Member Functions inherited from SurgSim::DataStructures::NamedData< boost::any >
 NamedData ()
 Create an empty object, with no associated names and indices yet.
 
 NamedData (std::shared_ptr< const IndexDirectory > directory)
 Create an object containing items from an index directory. More...
 
 NamedData (const std::vector< std::string > &names)
 Construct an object, using the names from a vector of strings. More...
 
 NamedData (const NamedData &namedData)
 Construct an object as a copy of the data from another object. More...
 
 NamedData (NamedData &&namedData)
 Create an object and move the data from another object. More...
 
NamedDataoperator= (const NamedData &namedData)
 Copy the data from another object. More...
 
NamedDataoperator= (NamedData &&namedData)
 Move the data from another object. More...
 
bool isValid () const
 Check if the object has been initialized, which means it has a set of entries (i.e., names, indices, and the map between them). More...
 
std::shared_ptr< const IndexDirectorygetDirectory () const
 Return the object's layout directory, which is its collection of names and indices. 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...
 
bool hasEntry (int index) const
 Check whether the object contains an entry with the specified index. More...
 
bool hasEntry (const std::string &name) const
 Check whether the object contains an entry with the specified name. More...
 
bool hasData (int index) const
 Check whether the entry with the specified index contains valid data. More...
 
bool hasData (const std::string &name) const
 Check whether the entry with the specified name contains valid data. More...
 
bool get (int index, boost::any *value) const
 Given an index, get the corresponding value. More...
 
bool get (const std::string &name, boost::any *value) const
 Given a name, get the corresponding value. More...
 
bool set (int index, const boost::any &value)
 Record the data for an entry specified by an index. More...
 
bool set (int index, boost::any &&value)
 Record the data for an entry specified by an index. More...
 
bool set (const std::string &name, const boost::any &value)
 Record the data for an entry specified by a name. More...
 
bool set (const std::string &name, boost::any &&value)
 Record the data for an entry specified by a name. More...
 
bool reset (int index)
 Invalidate an entry— mark it as not containing any valid data. More...
 
bool reset (const std::string &name)
 Invalidate an entry— mark it as not containing any valid data. More...
 
void resetAll ()
 Invalidate all entries— mark everything as not containing any valid data.
 
size_t size () const
 Check the number of existing entries. More...
 
int getNumEntries () const
 Check the number of existing entries. More...
 
void copy (const NamedData< N > &source, const NamedDataCopyMap &map)
 Copy the data from another NamedData, based on a map of indices. More...
 
void cacheIndex (const std::string &name, int *index) const
 Caches an entry's index if it is not already cached. More...
 

Detailed Description

A NamedData collection of variant data type.

A NamedVariantData collection is a collection variant datatypes. Each entry in the collection can be accessed by using either its unique name (a std::string) or its unique index (a non-negative integer). Access by name is more convenient, but also less efficient.

This sub-class of NameData encapsulates the boost::any variant type, and adds two get functions that provide typed access to the contained data.

Member Function Documentation

§ get() [1/2]

template<typename T >
bool SurgSim::DataStructures::NamedVariantData::get ( int  index,
T *  value 
) const
inline

Given an index, get the corresponding value.

It's only possible to get the value if the data was set using set(int, const T&) or set(const std::string&, const T&), without being subsequently invalidated by reset(int) or reset(const std::string&). In other words, get returns the same value as hasData would return.

Template Parameters
Tthe data type used for the value at the given index.
Parameters
indexThe index of the entry.
[out]valueThe location for the retrieved value. Must not be null.
Returns
true if a valid value is available, was written to value, and value is the correct type.

§ get() [2/2]

template<typename T >
bool SurgSim::DataStructures::NamedVariantData::get ( const std::string &  name,
T *  value 
) const
inline

Given a name, get the corresponding value.

It's only possible to get the value if the data was set using set(int, const T&) or set(const std::string&, const T&), without being subsequently invalidated by reset(int) or reset(const std::string&). In other words, get returns the same value as hasData would return.

Template Parameters
Tthe data type used for the value with the given name.
Parameters
nameThe name of the entry.
[out]valueThe location for the retrieved value. Must not be null.
Returns
true if a valid value is available, was written to value, and value is the correct type.

§ hasTypedData() [1/2]

template<typename T >
bool SurgSim::DataStructures::NamedVariantData::hasTypedData ( int  index) const
inline

Check whether the entry with the specified index contains valid data.

The check verifies that the entry's data is of type T, was set using set(int, const T&) or set(const std::string&, const T&), without being subsequently invalidated by reset(int) or reset(const std::string&).

Template Parameters
Tthe data type to check for at the given index.
Parameters
indexThe index of the entry.
Returns
true if that entry exists, is of type T, and contains valid data.

§ hasTypedData() [2/2]

template<typename T >
bool SurgSim::DataStructures::NamedVariantData::hasTypedData ( const std::string &  name) const
inline

Check whether the entry with the specified name contains valid data.

The check verifies that the entry's data is of type T, was set using set(int, const T&) or set(const std::string&, const T&), without being subsequently invalidated by reset(int) or reset(const std::string&).

Template Parameters
Tthe data type to check for at the given index.
Parameters
nameThe name of the entry.
Returns
true if that entry exists, is of type T, and contains valid data.

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