IMP logo
IMP Reference Guide  2.20.0
The Integrative Modeling Platform
IMP::Key< ID > Class Template Reference

A base class for Keys. More...

#include <IMP/Key.h>

+ Inheritance diagram for IMP::Key< ID >:

Detailed Description

template<unsigned int ID>
class IMP::Key< ID >

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.

Definition at line 45 of file Key.h.

Public Member Functions

 Key ()
 make a default key in a well-defined null state More...
 
 Key (std::string const &c, bool is_implicit_add_permitted=true)
 Generate a key object 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
 
Keyoperator++ ()
 
Keyoperator-- ()
 
void show (std::ostream &out=std::cout) const
 

Static Public Member Functions

static Key< ID > add_alias (Key< ID > old_key, std::string new_name)
 Make new_name an alias for old_key. More...
 
static unsigned int add_key (std::string sc)
 
static 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_of_keys ()
 
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...
 

Constructor & Destructor Documentation

template<unsigned int ID>
IMP::Key< ID >::Key ( )

make a default key in a well-defined null state

Definition at line 135 of file Key.h.

template<unsigned int ID>
IMP::Key< ID >::Key ( std::string const &  c,
bool  is_implicit_add_permitted = true 
)
explicit

Generate a key object from the given string.

Generate a key object from the given string.

Parameters
ckey string representation
is_implicit_add_permittedIf true, a key for c can be created even if it hasn't been created earlier. If false, than it is assumed that a key for c has already been instantiated by e.g., a previous call to Key(c, true) or using Key::add_key(). Formally, it is assumed that get_has_key(c) is true.
Note
This operation can be expensive, so please cache the result.

Definition at line 150 of file Key.h.

Member Function Documentation

template<unsigned int ID>
static Key<ID> IMP::Key< ID >::add_alias ( Key< ID >  old_key,
std::string  new_name 
)
static

Make new_name an alias for old_key.

Afterwards

Key<ID>(old_key.get_string()) == Key<ID>(new_name)

Definition at line 200 of file Key.h.

template<unsigned int ID>
static Vector<std::string> IMP::Key< ID >::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.

template<unsigned int ID>
static bool IMP::Key< ID >::get_key_exists ( std::string  sc)
static

Return true if there already is a key with that string.

Definition at line 173 of file Key.h.

template<unsigned int ID>
static unsigned int IMP::Key< ID >::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.

Definition at line 234 of file Key.h.

template<unsigned int ID>
const std::string IMP::Key< ID >::get_string ( ) const

Turn a key into a pretty string.

Definition at line 181 of file Key.h.

template<unsigned int ID>
Key& IMP::Key< ID >::operator++ ( )

Definition at line 239 of file Key.h.

template<unsigned int ID>
static void IMP::Key< ID >::show_all ( std::ostream &  out)
static

Show all the keys of this type.


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