1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
20 #include "inspircd_config.h"
26 typedef void* VoidPointer;
27 typedef std::map<std::string,char*> ExtensibleStore;
29 /** The base class for all inspircd classes
34 /** Time that the object was instantiated (used for TS calculation etc)
39 * Sets the object's time
41 classbase() { age = time(NULL); }
45 /** class Extensible is the parent class of many classes such as userrec and chanrec.
46 * class Extensible implements a system which allows modules to 'extend' the class by attaching data within
47 * a map associated with the object. In this way modules can store their own custom information within user
48 * objects, channel objects and server objects, without breaking other modules (this is more sensible than using
49 * a flags variable, and each module defining bits within the flag as 'theirs' as it is less prone to conflict and
50 * supports arbitary data storage).
52 class Extensible : public classbase
54 /** Private data store
56 ExtensibleStore Extension_Items;
60 /** Extend an Extensible class.
62 * @param key The key parameter is an arbitary string which identifies the extension data
63 * @param p This parameter is a pointer to any data you wish to associate with the object
65 * You must provide a key to store the data as, and a void* to the data (typedef VoidPointer)
66 * The data will be inserted into the map. If the data already exists, you may not insert it
67 * twice, Extensible::Extend will return false in this case.
69 * @return Returns true on success, false if otherwise
71 template<typename T> bool Extend(const std::string &key, T* p)
73 /* This will only add an item if it doesnt already exist,
74 * the return value is a std::pair of an iterator to the
75 * element, and a bool saying if it was actually inserted.
77 return this->Extension_Items.insert(std::make_pair(key, (char*)p)).second;
80 /** Shrink an Extensible class.
82 * @param key The key parameter is an arbitary string which identifies the extension data
84 * You must provide a key name. The given key name will be removed from the classes data. If
85 * you provide a nonexistent key (case is important) then the function will return false.
86 * @return Returns true on success.
88 bool Shrink(const std::string &key);
90 /** Get an extension item.
92 * @param key The key parameter is an arbitary string which identifies the extension data
93 * @return If you provide a non-existent key name, the function returns NULL, otherwise a pointer to the item referenced by the key is returned.
95 template<typename T> bool GetExt(const std::string &key, T* &p)
97 ExtensibleStore::iterator iter = this->Extension_Items.find(key);
98 if(iter != this->Extension_Items.end())
100 p = (T*)iter->second;
110 /** Get a list of all extension items names.
111 * @param list A deque of strings to receive the list
112 * @return This function writes a list of all extension items stored in this object by name into the given deque and returns void.
114 void GetExtList(std::deque<std::string> &list);
117 /** BoolSet is a utility class designed to hold eight bools in a bitmask.
118 * Use BoolSet::Set and BoolSet::Get to set and get bools in the bitmask,
119 * and Unset and Invert for special operations upon them.
121 class BoolSet : public classbase
127 /** The default constructor initializes the BoolSet to all values unset.
131 /** This constructor copies the default bitmask from a char
133 BoolSet(char bitmask);
135 /** The Set method sets one bool in the set.
137 * @param number The number of the item to set. This must be between 0 and 7.
139 void Set(int number);
141 /** The Get method returns the value of one bool in the set
143 * @param number The number of the item to retrieve. This must be between 0 and 7.
145 * @return True if the item is set, false if it is unset.
147 bool Get(int number);
149 /** The Unset method unsets one value in the set
151 * @param number The number of the item to set. This must be between 0 and 7.
153 void Unset(int number);
155 /** The Unset method inverts (flips) one value in the set
157 * @param number The number of the item to invert. This must be between 0 and 7.
159 void Invert(int number);
161 /** Compare two BoolSets
163 bool operator==(BoolSet other);
165 /** OR two BoolSets together
167 BoolSet operator|(BoolSet other);
169 /** AND two BoolSets together
171 BoolSet operator&(BoolSet other);
173 /** Assign one BoolSet to another
175 bool operator=(BoolSet other);