Handle mappings between names and auxid_t. More...
#include <AuxTypeRegistry.h>
Classes | |
struct | stringpair_hash |
Helper to hash the key type. | |
struct | typeinfo_t |
Hold information about one aux data item. | |
Public Types | |
typedef AthContainers_detail::upgrade_mutex | mutex_t |
typedef AthContainers_detail::strict_shared_lock < AuxTypeRegistry > | lock_t |
typedef AthContainers_detail::upgrading_lock < mutex_t > | upgrading_lock_t |
Public Member Functions | |
template<class T > | |
SG::auxid_t | getAuxID (const std::string &name, const std::string &clsname="") |
Look up a name -> auxid_t mapping. | |
SG::auxid_t | getAuxID (const std::type_info &ti, const std::string &name, const std::string &clsname="") |
Look up a name -> auxid_t mapping. | |
SG::auxid_t | findAuxID (const std::string &name, const std::string &clsname="") const |
Look up a name -> auxid_t mapping. | |
IAuxTypeVector * | makeVector (SG::auxid_t auxid, size_t size, size_t capacity) const |
Construct a new vector to hold an aux item. | |
IAuxTypeVector * | makeVector (lock_t &lock, SG::auxid_t auxid, size_t size, size_t capacity) const |
Construct a new vector to hold an aux item (external locking). | |
std::string | getName (SG::auxid_t auxid) const |
Return the name of an aux data item. | |
std::string | getName (lock_t &lock, SG::auxid_t auxid) const |
Return the name of an aux data item (external locking). | |
std::string | getClassName (SG::auxid_t auxid) const |
Return the class name associated with an aux data item (may be blank). | |
std::string | getClassName (lock_t &lock, SG::auxid_t auxid) const |
Return the class name associated with an aux data item (may be blank). [external locking.]. | |
const std::type_info * | getType (SG::auxid_t auxid) const |
Return the type of an aux data item. | |
const std::type_info * | getType (lock_t &lock, SG::auxid_t auxid) const |
Return the type of an aux data item (external locking). | |
std::string | getTypeName (SG::auxid_t auxid) const |
Return the type name of an aux data item. | |
std::string | getTypeName (lock_t &lock, SG::auxid_t auxid) const |
Return the type name of an aux data item (external locking). | |
const std::type_info * | getVecType (SG::auxid_t auxid) const |
Return the type of the STL vector used to hold an aux data item. | |
const std::type_info * | getVecType (lock_t &lock, SG::auxid_t auxid) const |
Return the type name of the STL vector used to hold an aux data item (external locking). | |
std::string | getVecTypeName (SG::auxid_t auxid) const |
Return the type of the STL vector used to hold an aux data item. | |
std::string | getVecTypeName (lock_t &lock, SG::auxid_t auxid) const |
Return the type name of the STL vector used to hold an aux data item (external locking). | |
size_t | getEltSize (SG::auxid_t auxid) const |
Return size of an element in the STL vector. | |
size_t | getEltSize (lock_t &lock, SG::auxid_t auxid) const |
Return size of an element in the STL vector (external locking). | |
void | copy (SG::auxid_t auxid, void *dst, size_t dst_index, const void *src, size_t src_index) |
Copy an element between vectors. | |
void | copy (lock_t &lock, SG::auxid_t auxid, void *dst, size_t dst_index, const void *src, size_t src_index) |
Copy an element between vectors (external locking). | |
void | copyForOutput (SG::auxid_t auxid, void *dst, size_t dst_index, const void *src, size_t src_index) |
Copy an element between vectors. Apply any transformations needed for output. | |
void | copyForOutput (lock_t &lock, SG::auxid_t auxid, void *dst, size_t dst_index, const void *src, size_t src_index) |
Copy an element between vectors (external locking). Apply any transformations needed for output. | |
void | swap (SG::auxid_t auxid, void *a, size_t aindex, void *b, size_t bindex) |
Swap an element between vectors. | |
void | swap (lock_t &lock, SG::auxid_t auxid, void *a, size_t aindex, void *b, size_t bindex) |
Swap an element between vectors (external locking). | |
void | clear (SG::auxid_t auxid, void *dst, size_t dst_index) |
Clear an element within a vector. | |
void | clear (lock_t &lock, SG::auxid_t auxid, void *dst, size_t dst_index) |
Clear an element within a vector (external locking). | |
const IAuxTypeVectorFactory * | getFactory (const std::type_info &ti) const |
Return the vector factory for a given vector element type. | |
const IAuxTypeVectorFactory * | getFactory (lock_t &lock, const std::type_info &ti) const |
Return the vector factory for a given vector element type. (external locking). | |
const IAuxTypeVectorFactory * | getFactory (upgrading_lock_t &lock, const std::type_info &ti) const |
Return the vector factory for a given vector element type. (external locking). | |
void | addFactory (const std::type_info &ti, IAuxTypeVectorFactory *factory) |
Add a new type -> factory mapping. | |
void | lock_shared () const |
Lock the registry for shared access. | |
void | unlock_shared () const |
Unlock the registry for shared access. | |
Static Public Member Functions | |
static AuxTypeRegistry & | instance () |
Return the singleton registry instance. |
Handle mappings between names and auxid_t.
Each auxiliary data item associated with a container has a name. Internally, they are identified by small integers of type auxid_t
. This class handles the mapping between names and auxid_t's
. It also keeps track of the type of each aux data item, and provides some generic methods for operating on this data.
The auxid_t
namespace is global, shared among all classes. It's no problem for two classes to use aux data with the same auxid_t
, as long as the type is the same. If they want to define them as different types, though, that's a problem. To help with this, an optional class name may be supplied; this qualifies the aux data name to make it unique across classes.
This class is meant to be used as a singleton. Use the instance
method to get the singleton instance.
Methods are locked internally, so access is thread-safe. However, since calls to registry methods are often used in a loop, externally-locked variants are also provided in order to reduce the overhead of locking. Use them like this:
SG::AuxTypeRegistry& r = SG::AuxTypeRegistry::instance(); SG::AuxTypeRegistry::lock_t lock (r); std::string name = r.getName (lock, auxid);
Thread-safety is not supported in standalone builds.
void SG::AuxTypeRegistry::addFactory | ( | const std::type_info & | ti, | |
IAuxTypeVectorFactory * | factory | |||
) |
Add a new type -> factory mapping.
ti | Type of the vector element. | |
factory | The factory instance. The registry will take ownership. |
This records that factory
can be used to construct vectors with an element type of ti
. If a mapping already exists, the new factory is discarded, unless the old one is a dynamic factory and the new one isn't, in which case the new replaces the old one.
void SG::AuxTypeRegistry::clear | ( | lock_t & | lock, | |
SG::auxid_t | auxid, | |||
void * | dst, | |||
size_t | dst_index | |||
) |
Clear an element within a vector (external locking).
lock | The registry lock. | |
auxid | The aux data item being operated on. | |
dst | Pointer to the start of the vector's data. | |
dst_index | Index of the element in the vector. |
void SG::AuxTypeRegistry::clear | ( | SG::auxid_t | auxid, | |
void * | dst, | |||
size_t | dst_index | |||
) |
Clear an element within a vector.
auxid | The aux data item being operated on. | |
dst | Pointer to the start of the vector's data. | |
dst_index | Index of the element in the vector. |
void SG::AuxTypeRegistry::copy | ( | lock_t & | lock, | |
SG::auxid_t | auxid, | |||
void * | dst, | |||
size_t | dst_index, | |||
const void * | src, | |||
size_t | src_index | |||
) |
Copy an element between vectors (external locking).
lock | The registry lock. | |
auxid | The aux data item being operated on. | |
dst | Pointer to the start of the destination vector's data. | |
dst_index | Index of destination element in the vector. | |
src | Pointer to the start of the source vector's data. | |
src_index | Index of source element in the vector. |
dst
and @ src can be either the same or different.
void SG::AuxTypeRegistry::copy | ( | SG::auxid_t | auxid, | |
void * | dst, | |||
size_t | dst_index, | |||
const void * | src, | |||
size_t | src_index | |||
) |
Copy an element between vectors.
auxid | The aux data item being operated on. | |
dst | Pointer to the start of the destination vector's data. | |
dst_index | Index of destination element in the vector. | |
src | Pointer to the start of the source vector's data. | |
src_index | Index of source element in the vector. |
dst
and @ src can be either the same or different.
void SG::AuxTypeRegistry::copyForOutput | ( | lock_t & | lock, | |
SG::auxid_t | auxid, | |||
void * | dst, | |||
size_t | dst_index, | |||
const void * | src, | |||
size_t | src_index | |||
) |
Copy an element between vectors (external locking). Apply any transformations needed for output.
lock | The registry lock. | |
auxid | The aux data item being operated on. | |
dst | Pointer to the start of the destination vector's data. | |
dst_index | Index of destination element in the vector. | |
src | Pointer to the start of the source vector's data. | |
src_index | Index of source element in the vector. |
dst
and @ src can be either the same or different.
void SG::AuxTypeRegistry::copyForOutput | ( | SG::auxid_t | auxid, | |
void * | dst, | |||
size_t | dst_index, | |||
const void * | src, | |||
size_t | src_index | |||
) |
Copy an element between vectors. Apply any transformations needed for output.
auxid | The aux data item being operated on. | |
dst | Pointer to the start of the destination vector's data. | |
dst_index | Index of destination element in the vector. | |
src | Pointer to the start of the source vector's data. | |
src_index | Index of source element in the vector. |
dst
and @ src can be either the same or different.
SG::auxid_t SG::AuxTypeRegistry::findAuxID | ( | const std::string & | name, | |
const std::string & | clsname = "" | |||
) | const |
Look up a name -> auxid_t
mapping.
name | The name of the aux data item. | |
clsname | The name of its associated class. May be blank. |
Will only find an existing auxid_t
; unlike getAuxID
, this won't make a new one. If the item isn't found, this returns null_auxid
.
SG::auxid_t SG::AuxTypeRegistry::getAuxID | ( | const std::type_info & | ti, | |
const std::string & | name, | |||
const std::string & | clsname = "" | |||
) |
Look up a name -> auxid_t
mapping.
ti | Type of the aux data item. | |
name | The name of the aux data item. | |
clsname | The name of its associated class. May be blank. |
The type of the item is given by ti. Return null_auxid
if we don't know how to make vectors of ti. (Use addFactory
to register additional types.) If an item with the same name was previously requested with a different type, then raise SG::ExcAuxTypeMismatch
.
SG::auxid_t SG::AuxTypeRegistry::getAuxID | ( | const std::string & | name, | |
const std::string & | clsname = "" | |||
) | [inline] |
Look up a name -> auxid_t
mapping.
name | The name of the aux data item. | |
clsname | The name of its associated class. May be blank. |
The type of the item is given by the template parameter T
. If an item with the same name was previously requested with a different type, then raise SG::ExcAuxTypeMismatch
.
name | The name of the aux data item. | |
clsname | The name of its associated class. May be blank. |
The type of the item is given by the template parameter T
. If an item with the same name was previously requested with a different type, then raise an AuxTypeMismatch
exception.
std::string SG::AuxTypeRegistry::getClassName | ( | lock_t & | lock, | |
SG::auxid_t | auxid | |||
) | const |
Return the class name associated with an aux data item (may be blank). [external locking.].
Return the class name associated with an aux data item (may be blank). [external locking].
lock | The registry lock. | |
auxid | The desired aux data item. |
std::string SG::AuxTypeRegistry::getClassName | ( | SG::auxid_t | auxid | ) | const |
Return the class name associated with an aux data item (may be blank).
auxid | The desired aux data item. |
size_t SG::AuxTypeRegistry::getEltSize | ( | lock_t & | lock, | |
SG::auxid_t | auxid | |||
) | const |
Return size of an element in the STL vector (external locking).
lock | The registry lock. | |
auxid | The desired aux data item. |
size_t SG::AuxTypeRegistry::getEltSize | ( | SG::auxid_t | auxid | ) | const |
Return size of an element in the STL vector.
auxid | The desired aux data item. |
const IAuxTypeVectorFactory * SG::AuxTypeRegistry::getFactory | ( | upgrading_lock_t & | lock, | |
const std::type_info & | ti | |||
) | const |
Return the vector factory for a given vector element type. (external locking).
lock | The registry lock. | |
ti | The type of the vector element. |
Returns 0 if the type is not known. (Use addFactory
to add new mappings.)
const IAuxTypeVectorFactory * SG::AuxTypeRegistry::getFactory | ( | lock_t & | lock, | |
const std::type_info & | ti | |||
) | const |
Return the vector factory for a given vector element type. (external locking).
lock | The registry lock. | |
ti | The type of the vector element. |
Returns 0 if the type is not known. (Use addFactory
to add new mappings.)
const IAuxTypeVectorFactory * SG::AuxTypeRegistry::getFactory | ( | const std::type_info & | ti | ) | const |
Return the vector factory for a given vector element type.
ti | The type of the vector element. |
Returns 0 if the type is not known. (Use addFactory
to add new mappings.)
std::string SG::AuxTypeRegistry::getName | ( | lock_t & | lock, | |
SG::auxid_t | auxid | |||
) | const |
Return the name of an aux data item (external locking).
lock | The registry lock. | |
auxid | The desired aux data item. |
std::string SG::AuxTypeRegistry::getName | ( | SG::auxid_t | auxid | ) | const |
Return the name of an aux data item.
auxid | The desired aux data item. |
const std::type_info * SG::AuxTypeRegistry::getType | ( | lock_t & | lock, | |
SG::auxid_t | auxid | |||
) | const |
Return the type of an aux data item (external locking).
lock | The registry lock. | |
auxid | The desired aux data item. |
const std::type_info * SG::AuxTypeRegistry::getType | ( | SG::auxid_t | auxid | ) | const |
Return the type of an aux data item.
auxid | The desired aux data item. |
std::string SG::AuxTypeRegistry::getTypeName | ( | lock_t & | lock, | |
SG::auxid_t | auxid | |||
) | const |
Return the type name of an aux data item (external locking).
lock | The registry lock. | |
auxid | The desired aux data item. |
Returns an empty string if the type is not known.
std::string SG::AuxTypeRegistry::getTypeName | ( | SG::auxid_t | auxid | ) | const |
Return the type name of an aux data item.
auxid | The desired aux data item. |
Returns an empty string if the type is not known.
const std::type_info * SG::AuxTypeRegistry::getVecType | ( | lock_t & | lock, | |
SG::auxid_t | auxid | |||
) | const |
Return the type name of the STL vector used to hold an aux data item (external locking).
Return the type of the STL vector used to hold an aux data item. (external locking).
lock | The registry lock. | |
auxid | The desired aux data item. |
const std::type_info * SG::AuxTypeRegistry::getVecType | ( | SG::auxid_t | auxid | ) | const |
Return the type of the STL vector used to hold an aux data item.
auxid | The desired aux data item. |
std::string SG::AuxTypeRegistry::getVecTypeName | ( | lock_t & | lock, | |
SG::auxid_t | auxid | |||
) | const |
Return the type name of the STL vector used to hold an aux data item (external locking).
Return the type name of the STL vector used to hold an aux data item. (external locking).
lock | The registry lock. | |
auxid | The desired aux data item. |
Returns an empty string if the type is not known.
std::string SG::AuxTypeRegistry::getVecTypeName | ( | SG::auxid_t | auxid | ) | const |
Return the type of the STL vector used to hold an aux data item.
Return the type name of the STL vector used to hold an aux data item.
auxid | The desired aux data item. |
Returns an empty string if the type is not known.
IAuxTypeVector * SG::AuxTypeRegistry::makeVector | ( | lock_t & | lock, | |
SG::auxid_t | auxid, | |||
size_t | size, | |||
size_t | capacity | |||
) | const |
Construct a new vector to hold an aux item (external locking).
lock | The registry lock. | |
auxid | The desired aux data item. | |
size | Initial size of the new vector. | |
capacity | Initial capacity of the new vector. |
IAuxTypeVector * SG::AuxTypeRegistry::makeVector | ( | SG::auxid_t | auxid, | |
size_t | size, | |||
size_t | capacity | |||
) | const |
Construct a new vector to hold an aux item.
auxid | The desired aux data item. | |
size | Initial size of the new vector. | |
capacity | Initial capacity of the new vector. |
void SG::AuxTypeRegistry::swap | ( | lock_t & | lock, | |
SG::auxid_t | auxid, | |||
void * | a, | |||
size_t | aindex, | |||
void * | b, | |||
size_t | bindex | |||
) |
Swap an element between vectors (external locking).
lock | The registry lock. | |
auxid | The aux data item being operated on. | |
a | Pointer to the start of the first vector's data. | |
aindex | Index of the element in the first vector. | |
b | Pointer to the start of the second vector's data. | |
bindex | Index of the element in the second vector. |
a
and @ b can be either the same or different.
void SG::AuxTypeRegistry::swap | ( | SG::auxid_t | auxid, | |
void * | a, | |||
size_t | aindex, | |||
void * | b, | |||
size_t | bindex | |||
) |
Swap an element between vectors.
auxid | The aux data item being operated on. | |
a | Pointer to the start of the first vector's data. | |
aindex | Index of the element in the first vector. | |
b | Pointer to the start of the second vector's data. | |
bindex | Index of the element in the second vector. |
a
and @ b can be either the same or different.