#ifndef BASE_H #define BASE_H using namespace std; #include <map> #include <string> //! compares two strings, alphanumerically. a < a_1 < a_2 < a_10 < a_20 < b int strcmpn(const char *s1, const char *s2); //! a functor wrapper for the strcmpn function struct numcmp { int operator()(const string &s1, const string &s2) const { return strcmpn(s1.c_str(), s2.c_str())<0; } }; //! a common class for anything that can be passed as a pointer to the vsprintf-like functions. class common { public: virtual ~common()=0; }; //! a simple class to associate strings with either ints or strings. class base : public common { public: map<string, int, numcmp> ints; typedef map<string, int, numcmp>::iterator intit; typedef map<string, int, numcmp>::const_iterator cintit; map<string, string, numcmp> strs; typedef map<string, string, numcmp>::iterator strit; typedef map<string, string, numcmp>::const_iterator cstrit; //! get the integer with key /str/. return -1 by default, which can be overriden. virtual int get_int(const char *str, int def=-1) const; //! get the string with key /str/ or null virtual const char *get(const char *str) const; //! set the string with key /str/ to /n/ virtual void set(const char *str, const char *n); //! set the integer key /str/ to /n/ virtual void set(const char *str, int n); void set(const char *str, const string &n) { set(str, n.c_str()); } //! remove /key/ virtual void unset(const char *key); virtual ~base() { }; }; #endif