Helper class to provide type-safe access to aux data. More...
#include <AuxElement.h>
Public Types | |
typedef AuxDataTraits< T > ::reference_type | reference_type |
Type referencing an item. | |
typedef AuxDataTraits< T > ::element_type | element_type |
Type the user sees. | |
typedef AuxDataTraits< T > ::container_pointer_type | container_pointer_type |
Pointer into the container holding this item. | |
Public Member Functions | |
Accessor (const std::string &name) | |
Constructor. | |
Accessor (const std::string &name, const std::string &clsname) | |
Constructor. | |
reference_type | operator() (AuxElement &e) const |
Fetch the variable for one element, as a non-const reference. | |
reference_type | operator() (AuxVectorData &container, size_t index) const |
Fetch the variable for one element, as a non-const reference. | |
void | set (AuxElement &e, const element_type &x) const |
Set the variable for one element. | |
container_pointer_type | getDataArray (AuxVectorData &container) const |
Get a pointer to the start of the auxiliary data array. | |
bool | isAvailableWritable (const AuxElement &e) const |
Test to see if this variable exists in the store and is writable. |
Helper class to provide type-safe access to aux data.
This is written as a separate class in order to be able to cache the name -> auxid lookup.
You might use this something like this:
// Only need to do this once. Myclass::Accessor<int> vint1 ("myInt"); ... const Myclass* m = ...; int x = vint1 (*m);
You can also use this to define getters/setters in your class:
class Myclass { ... int get_x() const { static Accessor<int> acc ("x", "Myclass"); return acc (*this); } int& get_x() { static Accessor<int> acc ("x", "Myclass"); return acc (*this); }
SG::AuxElement::Accessor< T >::Accessor | ( | const std::string & | name | ) | [inline] |
Constructor.
name | Name of this aux variable. |
The name -> auxid lookup is done here.
SG::AuxElement::Accessor< T >::Accessor | ( | const std::string & | name, | |
const std::string & | clsname | |||
) | [inline] |
Constructor.
name | Name of this aux variable. | |
clsname | The name of its associated class. May be blank. |
The name -> auxid lookup is done here.
AuxElement::Accessor< T >::container_pointer_type SG::AuxElement::Accessor< T >::getDataArray | ( | AuxVectorData & | container | ) | const [inline] |
Get a pointer to the start of the auxiliary data array.
container | The container from which to fetch the variable. |
bool SG::AuxElement::Accessor< T >::isAvailableWritable | ( | const AuxElement & | e | ) | const [inline] |
Test to see if this variable exists in the store and is writable.
e | An element of the container which to test the variable. |
AuxElement::Accessor< T >::reference_type SG::AuxElement::Accessor< T >::operator() | ( | AuxVectorData & | container, | |
size_t | index | |||
) | const [inline] |
Fetch the variable for one element, as a non-const reference.
container | The container from which to fetch the variable. | |
index | The index of the desired element. |
This allows retrieving aux data by container / index. Looping over the index via this method will be faster then looping over the elements of the container.
AuxElement::Accessor< T >::reference_type SG::AuxElement::Accessor< T >::operator() | ( | AuxElement & | e | ) | const [inline] |
Fetch the variable for one element, as a non-const reference.
e | The element for which to fetch the variable. |
void SG::AuxElement::Accessor< T >::set | ( | AuxElement & | e, | |
const element_type & | x | |||
) | const [inline] |
Set the variable for one element.
e | The element for which to fetch the variable. | |
x | The variable value to set. |