X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/loba.git/blobdiff_plain/c4e7c13743a9d1e8dfa5dc27d4b2fa3aaf1557ab..4096be9a95ef90a463f9721817750ad84f141b0a:/named_object_list.h diff --git a/named_object_list.h b/named_object_list.h index 03bf00d..929a0db 100644 --- a/named_object_list.h +++ b/named_object_list.h @@ -4,6 +4,17 @@ #include #include +// Define an associative container that maps a name with a class and a +// description. All classes must be derived from a same base class. +// +// We can then use the name to create an object of the associated +// class, and to retrieve a pointer to this object. +// +// Furthermore, it is possible to iterate over the elements to get +// their name and their description. + +// I am too lazy to comment the code, which should be obvious... + //===== arity 0 ===== template @@ -65,7 +76,8 @@ public: const std::string& get_descr(iterator& it) const { return it->second->description; } - size_t size() const { return assoc.size(); } + bool exists(const std::string& name) const + { return assoc.find(name) != assoc.end(); } iterator begin() const { return assoc.begin(); } iterator end() const { return assoc.end(); } @@ -73,9 +85,6 @@ public: //===== arity 2 ===== -#include -#include - template class named_object_list2 { protected: @@ -145,6 +154,7 @@ public: //=================== +// "NOL" like in Named_Object_List.... #define NOL_INSERT(name, descr, class) insert(name, new creator(descr)) #endif // !NAMED_OBJECT_LIST_H