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>
50 static const internal::KeyData::Map& get_map()
52 return IMP::kernel::internal::get_key_data(ID).get_map();
54 static const internal::KeyData::RMap& get_rmap() {
55 return IMP::kernel::internal::get_key_data(ID).get_rmap();
59 static unsigned int find_index(std::string sc) {
61 "Can't create a key with an empty name");
65 if (get_map().find(sc) == get_map().end()) {
68 val= IMP::kernel::internal::get_key_data(ID).add_key(sc);
70 val= get_map().find(sc)->second;
76 bool is_default()
const;
78 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
79 static unsigned int get_ID() {
83 static const std::string get_string(
int i)
88 if (static_cast<unsigned int>(i)
89 < get_rmap().size()) {
94 IMP_FAILURE(
"Corrupted Key Table asking for key " << i
95 <<
" with a table of size " << get_rmap().size());
106 explicit Key(std::string c): str_(find_index(c)) {
110 #if !defined(IMP_DOXYGEN)
111 explicit Key(
unsigned int i): str_(i) {
117 static unsigned int add_key(std::string sc) {
119 "Can't create a key with an empty name");
122 val= IMP::kernel::internal::get_key_data(ID).add_key(sc);
127 static
bool get_key_exists(std::
string sc) {
130 val= get_map().find(sc) != get_map().end();
136 if (is_default())
return std::string(
"nullptr");
138 val= get_string(str_);
155 std::string new_name) {
157 "The name is already taken with an existing key or alias");
158 IMP::kernel::internal::get_key_data(ID).add_alias(new_name,
159 old_key.get_index());
166 "Cannot get index on defaultly constructed Key");
172 static void show_all(std::ostream &out);
186 return get_rmap().size();
200 Key operator+(
int o)
const {
210 template <
unsigned int ID,
bool LA>
211 inline std::ostream &operator<<(std::ostream &out, Key<ID, LA> k) {
216 template <
unsigned int ID,
bool LA>
217 inline bool Key<ID, LA>::is_default()
const
223 template <
unsigned int ID,
bool LA>
224 inline void Key<ID, LA>::show_all(std::ostream &out)
227 internal::get_key_data(ID).
show(out);
230 template <
unsigned int ID,
bool LA>
231 base::Vector<std::
string> Key<ID, LA>::get_all_strings()
233 base::Vector<std::string> str;
235 for (internal::KeyData::Map::const_iterator it= get_map().begin();
236 it != get_map().end(); ++it) {
237 str.push_back(it->first);
243 IMPKERNEL_END_NAMESPACE