]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/base.h
Added Extensible classes
[user/henk/code/inspircd.git] / include / base.h
1 /*
2 Defines the base classes used by InspIRCd
3 */
4
5 #ifndef __BASE_H__ 
6 #define __BASE_H__ 
7
8 #include "inspircd_config.h" 
9 #include <time.h>
10 #include <map>
11 #include <string>
12
13 typedef void* VoidPointer;
14  
15 /** The base class for all inspircd classes
16 */ 
17 class classbase
18 {
19  public:
20         /** Time that the object was instantiated (used for TS calculation etc)
21         */
22         time_t age;
23
24         /** Constructor,
25          * Sets the object's time
26          */
27         classbase() { age = time(NULL); }
28         ~classbase() { }
29 };
30
31 /** class Extensible is the parent class of many classes such as userrec and chanrec.
32  * class Extensible implements a system which allows modules to 'extend' the class by attaching data within
33  * a map associated with the object. In this way modules can store their own custom information within user
34  * objects, channel objects and server objects, without breaking other modules (this is more sensible than using
35  * a flags variable, and each module defining bits within the flag as 'theirs' as it is less prone to conflict and
36  * supports arbitary data storage).
37  */
38 class Extensible : public classbase
39 {
40         /** Private data store
41          */
42         std::map<std::string,VoidPointer> Extension_Items;
43         
44 public:
45
46         /** Extend an Extensible class.
47          * You must provide a key to store the data as, and a void* to the data (typedef VoidPointer)
48          * The data will be inserted into the map. If the data already exists, you may not insert it
49          * twice, Extensible::Extend will return false in this case.
50          * On successful extension, Extend returns true.
51          */
52         bool Extend(std::string key, VoidPointer p);
53
54         /** Shrink an Extensible class.
55          * You must provide a key name. The given key name will be removed from the classes data. If
56          * you provide a nonexistent key (case is important) then the function will return false.
57          * Returns true on success.
58          */
59         bool Shrink(std::string key);
60         
61         /** Get an extension item.
62          * You must provide a key name, which is case sensitive. If you provide a non-existent key name,
63          * the function returns NULL, otherwise a pointer to the item referenced by the key is returned.
64          */
65         VoidPointer GetExt(std::string key);
66 };
67
68 #endif
69