This class does internal caching of the strings to accelerate the name lookup. It is better to create a Key and reuse it rather than recreate it many times from strings.
If you use this with a new type, you must add a new definition of attribute_table_index. Yes, this is an evil hack, but I couldn't get linking to work with static members of the template class.
The keys in IMP
maintain a cached mapping between strings and indexes. This mapping is global--that is all IMP
Models and Particles in the same program use the same mapping for each type of key. The type of the key is determined by an integer which should be unique for each type. If the integer is not unique, everything works, just more memory is wasted and types are interconvertible.
Keys used for storing attributes in particles should never be statically initialized. While this is annoying, statically initializing them is bad, as unused attribute keys can result in wasted memory in each particle.
If LazyAdd is true, keys created with a new string will be added, otherwise this is an error.
Public Types | |
typedef KeyBase< ID, LazyAdd > | This |
Public Member Functions | |
unsigned int | get_index () const |
const std::string | get_string () const |
Turn a key into a pretty string. | |
KeyBase (std::string c) | |
Generate a key from the given string. | |
KeyBase () | |
make a default key in a well-defined null state | |
This | operator+ (int o) const |
This & | operator++ () |
This & | operator-- () |
void | show (std::ostream &out=std::cout) const |
Static Public Member Functions | |
static KeyBase< ID, LazyAdd > | add_alias (KeyBase< ID, LazyAdd > old_key, std::string new_name) |
Make new_name an alias for old_key. | |
static unsigned int | add_key (std::string sc) |
static std::vector< std::string > | get_all_strings () |
Get a list of all of the keys of this type. | |
static unsigned int | get_ID () |
static bool | get_key_exists (std::string sc) |
Return true if there already is a key with that string. | |
static unsigned int | get_number_unique () |
Get the total number of keys of this type. | |
static const std::string | get_string (int i) |
static void | show_all (std::ostream &out) |
Show all the keys of this type. | |
Static Package Functions | |
static unsigned int | find_index (std::string sc) |
Static Package Attributes | |
__pad0__:KeyData::Map& get_map() { return IMP::internal::get_key_data(ID).get_map() | |
__pad1__:KeyData::RMap& get_rmap() { return IMP::internal::get_key_data(ID).get_rmap() |
IMP::KeyBase< ID, LazyAdd >::KeyBase | ( | std::string | c | ) | [explicit] |
Generate a key from the given string.
This operation can be expensive, so please cache the result.
static KeyBase<ID, LazyAdd> IMP::KeyBase< ID, LazyAdd >::add_alias | ( | KeyBase< ID, LazyAdd > | old_key, | |
std::string | new_name | |||
) | [static] |
Make new_name an alias for old_key.
Afterwards
KeyBase<ID>(old_key.get_string()) == KeyBase<ID>(new_name)
static std::vector<std::string> IMP::KeyBase< ID, LazyAdd >::get_all_strings | ( | ) | [static] |
Get a list of all of the keys of this type.
This can be used to check for typos and similar keys.
static unsigned int IMP::KeyBase< ID, LazyAdd >::get_number_unique | ( | ) | [static] |
Get the total number of keys of this type.
This is mostly for debugging to make sure that there are no extra keys created.
This& IMP::KeyBase< ID, LazyAdd >::operator++ | ( | ) |