8 #ifndef IMPKERNEL_KEY_H
9 #define IMPKERNEL_KEY_H
12 #include "internal/key_helpers.h"
20 IMPKERNEL_BEGIN_NAMESPACE
45 template <
unsigned int ID,
bool LazyAdd>
49 static const internal::KeyData::Map& get_map() {
50 return IMP::kernel::internal::get_key_data(ID).get_map();
52 static const internal::KeyData::RMap& get_rmap() {
53 return IMP::kernel::internal::get_key_data(ID).get_rmap();
56 static unsigned int find_index(std::string sc) {
60 if (get_map().find(sc) == get_map().end()) {
63 val = IMP::kernel::internal::get_key_data(ID).add_key(sc);
65 val = get_map().find(sc)->second;
72 bool is_default()
const;
75 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
76 static unsigned int get_ID() {
return ID; }
78 static const std::string get_string(
int i) {
81 if (static_cast<unsigned int>(i) < get_rmap().size()) {
87 << i <<
" with a table of size " << get_rmap().size());
98 explicit Key(std::string c) : str_(find_index(c)) {}
100 #if !defined(IMP_DOXYGEN)
101 explicit Key(
unsigned int i) : str_(i) {
107 static unsigned int add_key(std::string sc) {
111 val = IMP::kernel::internal::get_key_data(ID).add_key(sc);
116 static
bool get_key_exists(std::
string sc) {
119 val = get_map().find(sc) != get_map().end();
125 if (is_default())
return std::string(
"nullptr");
127 val = get_string(str_);
144 std::string new_name) {
146 get_map().find(new_name) == get_map().end(),
147 "The name is already taken with an existing key or alias");
148 IMP::kernel::internal::get_key_data(ID)
149 .add_alias(new_name, old_key.get_index());
156 "Cannot get index on defaultly constructed Key");
162 static void show_all(std::ostream& out);
188 Key operator+(
int o)
const {
198 template <
unsigned int ID,
bool LA>
199 inline std::ostream& operator<<(std::ostream& out, Key<ID, LA> k) {
204 template <
unsigned int ID,
bool LA>
205 inline bool Key<ID, LA>::is_default()
const {
209 template <
unsigned int ID,
bool LA>
210 inline void Key<ID, LA>::show_all(std::ostream& out) {
212 internal::get_key_data(ID).
show(out);
215 template <
unsigned int ID,
bool LA>
216 base::Vector<std::
string> Key<ID, LA>::get_all_strings() {
217 base::Vector<std::string> str;
219 for (internal::KeyData::Map::const_iterator it = get_map().begin();
220 it != get_map().end(); ++it) {
221 str.push_back(it->first);
227 IMPKERNEL_END_NAMESPACE
Key(std::string c)
Generate a key from the given string.
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Ints get_index(const kernel::ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Various general useful macros for IMP.
static unsigned int get_number_unique()
Get the total number of keys of this type.
#define IMP_FAILURE(message)
A runtime failure for IMP.
#define IMP_HASHABLE_INLINE(name, hashret)
Base for a simple primitive-like type.
#define IMP_INTERNAL_CHECK(expr, message)
An assertion to check for internal errors in IMP. An IMP::ErrorException will be thrown.
Various general useful macros for IMP.
Key()
make a default key in a well-defined null state
Exception definitions and assertions.
void show(Hierarchy h, std::ostream &out=std::cout)
Print out a molecular hierarchy.
const std::string get_string() const
Turn a key into a pretty string.
For backwards compatibility.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
#define IMP_COMPARISONS_1(Name, field)
Implement comparison in a class using field as the variable to compare.
static Key< ID, LazyAdd > add_alias(Key< ID, LazyAdd > old_key, std::string new_name)
Make new_name an alias for old_key.
#define IMP_OMP_PRAGMA(x)