summaryrefslogtreecommitdiff
path: root/include/base.h
diff options
context:
space:
mode:
authorom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-04-10 19:30:48 +0000
committerom <om@e03df62e-2008-0410-955e-edbf42e46eb7>2006-04-10 19:30:48 +0000
commit5fb54ac29a36131d2e49991095ef9741abb5f94e (patch)
treeac0bdf4a48e484e847d7685ced77a28bd879169c /include/base.h
parent3c272bcc1f53c2a8ebbf5b399118d33b5640cf9b (diff)
Assorted changes here, Extend() is not templated so you can pass it any pointer type and it will automatically be cast to char* for you. Also some speedups, store an iterator rather than calling find() once to check if it exists and again to access the value.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3864 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'include/base.h')
-rw-r--r--include/base.h14
1 files changed, 11 insertions, 3 deletions
diff --git a/include/base.h b/include/base.h
index 43a3101bd..d3cc77e05 100644
--- a/include/base.h
+++ b/include/base.h
@@ -17,13 +17,14 @@
#ifndef __BASE_H__
#define __BASE_H__
-#include "inspircd_config.h"
+#include "inspircd_config.h"
#include <time.h>
#include <map>
#include <deque>
#include <string>
typedef void* VoidPointer;
+typedef std::map<std::string,char*> ExtensibleStore;
/** The base class for all inspircd classes
*/
@@ -52,7 +53,7 @@ class Extensible : public classbase
{
/** Private data store
*/
- std::map<std::string,char*> Extension_Items;
+ ExtensibleStore Extension_Items;
public:
@@ -67,7 +68,14 @@ public:
*
* @return Returns true on success, false if otherwise
*/
- bool Extend(const std::string &key, char* p);
+ template<typename T> bool Extend(const std::string &key, T* p)
+ {
+ /* This will only add an item if it doesnt already exist,
+ * the return value is a std::pair of an iterator to the
+ * element, and a bool saying if it was actually inserted.
+ */
+ return this->Extension_Items.insert(std::make_pair(key, (char*)p)).second;
+ }
/** Shrink an Extensible class.
*