IMP
2.3.1
The Integrative Modeling Platform
|
A base class for Keys. More...
#include <IMP/kernel/Key.h>
A base class for Keys.
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.
Definition at line 46 of file kernel/Key.h.
Public Member Functions | |
Key () | |
make a default key in a well-defined null state More... | |
Key (std::string c) | |
Generate a key from the given string. More... | |
unsigned int | get_index () const |
const std::string | get_string () const |
Turn a key into a pretty string. More... | |
Key | operator+ (int o) const |
Key & | operator++ () |
Key & | operator-- () |
void | show (std::ostream &out=std::cout) const |
Static Public Member Functions | |
static Key< ID, LazyAdd > | add_alias (Key< ID, LazyAdd > old_key, std::string new_name) |
Make new_name an alias for old_key. More... | |
static unsigned int | add_key (std::string sc) |
static base::Vector< std::string > | get_all_strings () |
Get a list of all of the keys of this type. More... | |
static bool | get_key_exists (std::string sc) |
Return true if there already is a key with that string. More... | |
static unsigned int | get_number_unique () |
Get the total number of keys of this type. More... | |
static void | show_all (std::ostream &out) |
Show all the keys of this type. More... | |
IMP::kernel::Key< ID, LazyAdd >::Key | ( | ) |
make a default key in a well-defined null state
Definition at line 94 of file kernel/Key.h.
|
explicit |
Generate a key from the given string.
This operation can be expensive, so please cache the result.
Definition at line 98 of file kernel/Key.h.
|
static |
Make new_name an alias for old_key.
Afterwards
Definition at line 143 of file kernel/Key.h.
|
static |
Get a list of all of the keys of this type.
This can be used to check for typos and similar keys.
|
static |
Return true if there already is a key with that string.
Definition at line 116 of file kernel/Key.h.
|
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.
Definition at line 175 of file kernel/Key.h.
const std::string IMP::kernel::Key< ID, LazyAdd >::get_string | ( | ) | const |
Turn a key into a pretty string.
Definition at line 124 of file kernel/Key.h.
Key& IMP::kernel::Key< ID, LazyAdd >::operator++ | ( | ) |
Definition at line 180 of file kernel/Key.h.
|
static |
Show all the keys of this type.