The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

base.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
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                 /* This will only add an item if it doesnt already exist,
00078                  * the return value is a std::pair of an iterator to the
00079                  * element, and a bool saying if it was actually inserted.
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                 /* This will only add an item if it doesnt already exist,
00098                  * the return value is a std::pair of an iterator to the
00099                  * element, and a bool saying if it was actually inserted.
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); /* Find the item */
00123                 if(iter != this->Extension_Items.end())
00124                 {
00125                         p = (T*)iter->second;   /* Item found */
00126                         return true;
00127                 }
00128                 else
00129                 {
00130                         p = NULL;               /* Item not found */
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