base.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __BASE_H__
00015 #define __BASE_H__
00016
00017 #include <map>
00018 #include <deque>
00019 #include <string>
00020
00022 typedef std::map<std::string,char*> ExtensibleStore;
00023
00029 class CoreExport classbase
00030 {
00031 public:
00034 time_t age;
00035
00039 classbase();
00040
00044 virtual ~classbase() { }
00045 };
00046
00054 class CoreExport Extensible : public classbase
00055 {
00059 ExtensibleStore Extension_Items;
00060
00061 public:
00062
00075 template<typename T> bool Extend(const std::string &key, T* p)
00076 {
00077
00078
00079
00080
00081 return this->Extension_Items.insert(std::make_pair(key, (char*)p)).second;
00082 }
00083
00095 bool Extend(const std::string &key)
00096 {
00097
00098
00099
00100
00101 return this->Extension_Items.insert(std::make_pair(key, (char*)NULL)).second;
00102 }
00103
00112 bool Shrink(const std::string &key);
00113
00120 template<typename T> bool GetExt(const std::string &key, T* &p)
00121 {
00122 ExtensibleStore::iterator iter = this->Extension_Items.find(key);
00123 if(iter != this->Extension_Items.end())
00124 {
00125 p = (T*)iter->second;
00126 return true;
00127 }
00128 else
00129 {
00130 p = NULL;
00131 return false;
00132 }
00133 }
00134
00144 bool GetExt(const std::string &key)
00145 {
00146 return (this->Extension_Items.find(key) != this->Extension_Items.end());
00147 }
00148
00153 void GetExtList(std::deque<std::string> &list);
00154 };
00155
00160 class CoreExport BoolSet : public classbase
00161 {
00163 char bits;
00164
00165 public:
00166
00169 BoolSet();
00170
00173 BoolSet(char bitmask);
00174
00179 void Set(int number);
00180
00187 bool Get(int number);
00188
00193 void Unset(int number);
00194
00199 void Invert(int number);
00200
00203 bool operator==(BoolSet other);
00204
00207 BoolSet operator|(BoolSet other);
00208
00211 BoolSet operator&(BoolSet other);
00212
00215 bool operator=(BoolSet other);
00216 };
00217
00224 class CoreExport CoreException : public std::exception
00225 {
00226 protected:
00229 const std::string err;
00232 const std::string source;
00233 public:
00236 CoreException() : err("Core threw an exception"), source("The core") {}
00239 CoreException(const std::string &message) : err(message), source("The core") {}
00243 CoreException(const std::string &message, const std::string &src) : err(message), source(src) {}
00248 virtual ~CoreException() throw() {};
00252 virtual const char* GetReason()
00253 {
00254 return err.c_str();
00255 }
00256
00257 virtual const char* GetSource()
00258 {
00259 return source.c_str();
00260 }
00261 };
00262
00263 class CoreExport ModuleException : public CoreException
00264 {
00265 public:
00268 ModuleException() : CoreException("Module threw an exception", "A Module") {}
00269
00272 ModuleException(const std::string &message) : CoreException(message, "A Module") {}
00277 virtual ~ModuleException() throw() {};
00278 };
00279
00280 #endif