1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
21 /** The base class for all inspircd classes.
22 * Wherever possible, all classes you create should inherit from this,
23 * giving them the ability to be passed to various core functions
24 * as 'anonymous' classes.
26 class CoreExport classbase
31 virtual ~classbase() { }
34 /** BoolSet is a utility class designed to hold eight bools in a bitmask.
35 * Use BoolSet::Set and BoolSet::Get to set and get bools in the bitmask,
36 * and Unset and Invert for special operations upon them.
38 class CoreExport BoolSet : public classbase
40 /** Actual bit values */
45 /** The default constructor initializes the BoolSet to all values unset.
49 /** This constructor copies the default bitmask from a char
51 BoolSet(char bitmask);
53 /** The Set method sets one bool in the set.
55 * @param number The number of the item to set. This must be between 0 and 7.
59 /** The Get method returns the value of one bool in the set
61 * @param number The number of the item to retrieve. This must be between 0 and 7.
63 * @return True if the item is set, false if it is unset.
67 /** The Unset method unsets one value in the set
69 * @param number The number of the item to set. This must be between 0 and 7.
71 void Unset(int number);
73 /** The Unset method inverts (flips) one value in the set
75 * @param number The number of the item to invert. This must be between 0 and 7.
77 void Invert(int number);
79 /** Compare two BoolSets
81 bool operator==(BoolSet other);
83 /** OR two BoolSets together
85 BoolSet operator|(BoolSet other);
87 /** AND two BoolSets together
89 BoolSet operator&(BoolSet other);
91 /** Assign one BoolSet to another
93 bool operator=(BoolSet other);
96 /** This class can be used on its own to represent an exception, or derived to represent a module-specific exception.
97 * When a module whishes to abort, e.g. within a constructor, it should throw an exception using ModuleException or
98 * a class derived from ModuleException. If a module throws an exception during its constructor, the module will not
99 * be loaded. If this happens, the error message returned by ModuleException::GetReason will be displayed to the user
100 * attempting to load the module, or dumped to the console if the ircd is currently loading for the first time.
102 class CoreExport CoreException : public std::exception
105 /** Holds the error message to be displayed
107 const std::string err;
108 /** Source of the exception
110 const std::string source;
112 /** Default constructor, just uses the error mesage 'Core threw an exception'.
114 CoreException() : err("Core threw an exception"), source("The core") {}
115 /** This constructor can be used to specify an error message before throwing.
117 CoreException(const std::string &message) : err(message), source("The core") {}
118 /** This constructor can be used to specify an error message before throwing,
119 * and to specify the source of the exception.
121 CoreException(const std::string &message, const std::string &src) : err(message), source(src) {}
122 /** This destructor solves world hunger, cancels the world debt, and causes the world to end.
123 * Actually no, it does nothing. Never mind.
126 virtual ~CoreException() throw() {};
127 /** Returns the reason for the exception.
128 * The module should probably put something informative here as the user will see this upon failure.
130 virtual const char* GetReason()
135 virtual const char* GetSource()
137 return source.c_str();
141 class CoreExport ModuleException : public CoreException
144 /** Default constructor, just uses the error mesage 'Module threw an exception'.
146 ModuleException() : CoreException("Module threw an exception", "A Module") {}
148 /** This constructor can be used to specify an error message before throwing.
150 ModuleException(const std::string &message) : CoreException(message, "A Module") {}
151 /** This destructor solves world hunger, cancels the world debt, and causes the world to end.
152 * Actually no, it does nothing. Never mind.
155 virtual ~ModuleException() throw() {};