]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - include/base.h
Added parameters
[user/henk/code/inspircd.git] / include / base.h
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #ifndef __BASE_H__ 
18 #define __BASE_H__ 
19
20 #include "inspircd_config.h" 
21 #include <time.h>
22 #include <map>
23 #include <string>
24
25 typedef void* VoidPointer;
26  
27 /** The base class for all inspircd classes
28 */ 
29 class classbase
30 {
31  public:
32         /** Time that the object was instantiated (used for TS calculation etc)
33         */
34         time_t age;
35
36         /** Constructor,
37          * Sets the object's time
38          */
39         classbase() { age = time(NULL); }
40         ~classbase() { }
41 };
42
43 /** class Extensible is the parent class of many classes such as userrec and chanrec.
44  * class Extensible implements a system which allows modules to 'extend' the class by attaching data within
45  * a map associated with the object. In this way modules can store their own custom information within user
46  * objects, channel objects and server objects, without breaking other modules (this is more sensible than using
47  * a flags variable, and each module defining bits within the flag as 'theirs' as it is less prone to conflict and
48  * supports arbitary data storage).
49  */
50 class Extensible : public classbase
51 {
52         /** Private data store
53          */
54         std::map<std::string,char*> Extension_Items;
55         
56 public:
57
58         /** Extend an Extensible class.
59          *
60          * @param key The key parameter is an arbitary string which identifies the extension data
61          * @param p This parameter is a pointer to any data you wish to associate with the object
62          *
63          * You must provide a key to store the data as, and a void* to the data (typedef VoidPointer)
64          * The data will be inserted into the map. If the data already exists, you may not insert it
65          * twice, Extensible::Extend will return false in this case.
66          *
67          * @return Returns true on success, false if otherwise
68          */
69         bool Extend(std::string key, char* p);
70
71         /** Shrink an Extensible class.
72          *
73          * @param key The key parameter is an arbitary string which identifies the extension data
74          *
75          * You must provide a key name. The given key name will be removed from the classes data. If
76          * you provide a nonexistent key (case is important) then the function will return false.
77          *
78          * @return Returns true on success.
79          */
80         bool Shrink(std::string key);
81         
82         /** Get an extension item.
83          *
84          * @param key The key parameter is an arbitary string which identifies the extension data
85          *
86          * @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.
87          */
88         char* GetExt(std::string key);
89 };
90
91 #endif
92