+ mutable unsigned int usecount;
+ public:
+ usecountbase() : usecount(0) { }
+ ~usecountbase();
+ inline unsigned int GetUseCount() const { return usecount; }
+ inline void refcount_inc() const { usecount++; }
+ inline bool refcount_dec() const { usecount--; return false; }
+ private:
+ // uncopyable
+ usecountbase(const usecountbase&);
+ void operator=(const usecountbase&);
+};
+
+template <typename T>
+class CoreExport reference
+{
+ T* value;
+ public:
+ reference() : value(0) { }
+ reference(T* v) : value(v) { if (value) value->refcount_inc(); }
+ reference(const reference<T>& v) : value(v.value) { if (value) value->refcount_inc(); }
+ reference<T>& operator=(const reference<T>& other)
+ {
+ if (other.value)
+ other.value->refcount_inc();
+ this->reference::~reference();
+ value = other.value;
+ return *this;
+ }
+
+ ~reference()
+ {
+ if (value && value->refcount_dec())
+ delete value;
+ }
+
+ inline reference<T>& operator=(T* other)
+ {
+ if (value != other)
+ {
+ if (value && value->refcount_dec())
+ delete value;
+ value = other;
+ if (value)
+ value->refcount_inc();
+ }
+
+ return *this;
+ }
+
+ inline operator bool() const { return (value != NULL); }
+ inline operator T*() const { return value; }
+ inline T* operator->() const { return value; }
+ inline T& operator*() const { return *value; }
+ inline bool operator<(const reference<T>& other) const { return value < other.value; }
+ inline bool operator>(const reference<T>& other) const { return value > other.value; }
+ static inline void* operator new(size_t, void* m) { return m; }
+ private:
+#ifndef _WIN32
+ static void* operator new(size_t);
+ static void operator delete(void*);
+#endif
+};
+
+/** This class can be used on its own to represent an exception, or derived to represent a module-specific exception.
+ * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or
+ * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not
+ * be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user
+ * attempting to load the module, or dumped to the console if the ircd is currently loading for the first time.
+ */
+class CoreExport CoreException : public std::exception
+{
+ public:
+ /** Holds the error message to be displayed
+ */
+ const std::string err;
+ /** Source of the exception