summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-11-22 00:50:33 -0500
committerAdam <Adam@anope.org>2012-11-22 00:50:33 -0500
commitd33a0f75a5c0c584fbb7cc0076da36d494f39494 (patch)
tree7b2274cc833c793c0f5595660cbd4d715de52ffd /include
parent368d469631763e9c8bf399980d0ac7c5b5664d39 (diff)
Pretty large coding style cleanup, in source doc
cleanup, and allow protocol mods to depend on each other
Diffstat (limited to 'include')
-rw-r--r--include/access.h78
-rw-r--r--include/account.h178
-rw-r--r--include/anope.h224
-rw-r--r--include/base.h38
-rw-r--r--include/bots.h44
-rw-r--r--include/botserv.h79
-rw-r--r--include/channels.h147
-rw-r--r--include/commands.h24
-rw-r--r--include/config.h28
-rw-r--r--include/defs.h8
-rw-r--r--include/dns.h481
-rw-r--r--include/extensible.h22
-rw-r--r--include/extern.h108
-rw-r--r--include/hashcomp.h30
-rw-r--r--include/language.h58
-rw-r--r--include/lists.h11
-rw-r--r--include/logger.h52
-rw-r--r--include/mail.h57
-rw-r--r--include/memo.h19
-rw-r--r--include/messages.h277
-rw-r--r--include/modes.h216
-rw-r--r--include/module.h8
-rw-r--r--include/modules.h74
-rw-r--r--include/opertype.h10
-rw-r--r--include/protocol.h144
-rw-r--r--include/regchannel.h180
-rw-r--r--include/serialize.h172
-rw-r--r--include/servers.h52
-rw-r--r--include/service.h84
-rw-r--r--include/services.h10
-rw-r--r--include/signals.h1
-rw-r--r--include/socketengine.h3
-rw-r--r--include/sockets.h61
-rw-r--r--include/threadengine.h14
-rw-r--r--include/timers.h14
-rw-r--r--include/uplink.h11
-rw-r--r--include/users.h141
-rw-r--r--include/xline.h (renamed from include/oper.h)31
38 files changed, 1871 insertions, 1318 deletions
diff --git a/include/access.h b/include/access.h
index 558dbeb5c..918dd7be6 100644
--- a/include/access.h
+++ b/include/access.h
@@ -8,7 +8,6 @@
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*
- *
*/
#ifndef ACCESS_H
@@ -25,19 +24,25 @@ enum
ACCESS_FOUNDER = 10001
};
+/* A privilege, probably configured using a privilege{} block. Most
+ * commands require specific privileges to be executed. The AccessProvider
+ * backing each ChanAccess determines whether that ChanAccess has a given
+ * privilege.
+ */
struct CoreExport Privilege
{
Anope::string name;
Anope::string desc;
+ /* Rank relative to other privileges */
int rank;
- Privilege(const Anope::string &n, const Anope::string &d, int r);
+ Privilege(const Anope::string &name, const Anope::string &desc, int rank);
bool operator==(const Privilege &other) const;
};
class CoreExport PrivilegeManager
{
- static std::vector<Privilege> privs;
+ static std::vector<Privilege> Privileges;
public:
static void AddPrivilege(Privilege p);
static void RemovePrivilege(Privilege &p);
@@ -46,25 +51,34 @@ class CoreExport PrivilegeManager
static void ClearPrivileges();
};
-
+/* A provider of access. Only used for creating ChanAccesses, as
+ * they contain pure virtual functions.
+ */
class CoreExport AccessProvider : public Service
{
public:
- AccessProvider(Module *o, const Anope::string &n);
+ AccessProvider(Module *owner, const Anope::string &name);
virtual ~AccessProvider();
+
+ /** Creates a new ChanAccess entry using this provider.
+ * @return The new entry
+ */
virtual ChanAccess *Create() = 0;
private:
- static std::list<AccessProvider *> providers;
+ static std::list<AccessProvider *> Providers;
public:
static const std::list<AccessProvider *>& GetProviders();
};
+/* Represents one entry of an access list on a channel. */
class CoreExport ChanAccess : public Serializable
{
public:
+ /* The provider that created this access entry */
AccessProvider *provider;
- serialize_obj<ChannelInfo> ci;
+ /* Channel this access entry is on */
+ Serialize::Reference<ChannelInfo> ci;
Anope::string mask;
Anope::string creator;
time_t last_seen;
@@ -73,29 +87,69 @@ class CoreExport ChanAccess : public Serializable
ChanAccess(AccessProvider *p);
virtual ~ChanAccess();
- Serialize::Data serialize() const anope_override;
- static Serializable* unserialize(Serializable *obj, Serialize::Data &);
+ Serialize::Data Serialize() const anope_override;
+ static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+ /** Check if this access entry matches the given user or account
+ * @param u The user
+ * @param nc The account
+ */
virtual bool Matches(const User *u, const NickCore *nc) const;
+
+ /** Check if this access entry has the given privilege.
+ * @param name The privilege name
+ */
virtual bool HasPriv(const Anope::string &name) const = 0;
- virtual Anope::string Serialize() const = 0;
- virtual void Unserialize(const Anope::string &data) = 0;
+ /** Serialize the access given by this access entry into a human
+ * readable form. chanserv/access will return a number, chanserv/xop
+ * will be AOP, SOP, etc.
+ */
+ virtual Anope::string AccessSerialize() const = 0;
+
+ /** Unserialize this access entry from the given data. This data
+ * will be fetched from AccessSerialize.
+ */
+ virtual void AccessUnserialize(const Anope::string &data) = 0;
+
+ /* Comparison operators to other Access entries */
bool operator>(const ChanAccess &other) const;
bool operator<(const ChanAccess &other) const;
bool operator>=(const ChanAccess &other) const;
bool operator<=(const ChanAccess &other) const;
};
+/* A group of access entries. This is used commonly, for example with ChannelInfo::AccessFor,
+ * to show what access a user has on a channel because users can match multiple access entries.
+ */
class CoreExport AccessGroup : public std::vector<ChanAccess *>
{
public:
+ /* Channel these access entries are on */
const ChannelInfo *ci;
+ /* Account these entries affect, if any */
const NickCore *nc;
- bool SuperAdmin, Founder;
+ /* super_admin always gets all privs. founder is a special case where ci->founder == nc */
+ bool super_admin, founder;
+
AccessGroup();
+
+ /** Check if this access group has a certain privilege. Eg, it
+ * will check every ChanAccess entry of this group for any that
+ * has the given privilege.
+ * @param priv The privilege
+ * @return true if any entry has the given privilege
+ */
bool HasPriv(const Anope::string &priv) const;
+
+ /** Get the "highest" access entry from this group of entries.
+ * The highest entry is determined by the entry that has the privilege
+ * with the highest rank (see Privilege::rank).
+ * @return The "highest" entry
+ */
const ChanAccess *Highest() const;
+
+ /* Comparison operators to other AccessGroups */
bool operator>(const AccessGroup &other) const;
bool operator<(const AccessGroup &other) const;
bool operator>=(const AccessGroup &other) const;
diff --git a/include/account.h b/include/account.h
index 8ed1f06a4..a45bf8c90 100644
--- a/include/account.h
+++ b/include/account.h
@@ -7,8 +7,7 @@
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
- *
- *
+ *
*/
#ifndef ACCOUNT_H
@@ -23,10 +22,8 @@
typedef Anope::hash_map<NickAlias *> nickalias_map;
typedef Anope::hash_map<NickCore *> nickcore_map;
-extern CoreExport serialize_checker<nickalias_map> NickAliasList;
-extern CoreExport serialize_checker<nickcore_map> NickCoreList;
-
-/* NickServ nickname structures. */
+extern CoreExport Serialize::Checker<nickalias_map> NickAliasList;
+extern CoreExport Serialize::Checker<nickcore_map> NickCoreList;
/** Flags set on NickAliases
*/
@@ -50,10 +47,6 @@ enum NickNameFlag
NS_END
};
-const Anope::string NickNameFlagStrings[] = {
- "BEGIN", "NO_EXPIRE", "HELD", "COLLIDED", ""
-};
-
/** Flags set on NickCores
*/
enum NickCoreFlag
@@ -101,40 +94,36 @@ enum NickCoreFlag
NI_END
};
-const Anope::string NickCoreFlagStrings[] = {
- "BEGIN", "KILLPROTECT", "SECURE", "MSG", "MEMO_HARDMAX", "MEMO_SIGNON", "MEMO_RECEIVE",
- "PRIVATE", "HIDE_EMAIL", "HIDE_MASK", "HIDE_QUIT", "KILL_QUICK", "KILL_IMMED",
- "MEMO_MAIL", "HIDE_STATUS", "SUSPENDED", "AUTOOP", "UNCONFIRMED", "STATS", ""
-};
-
-/* It matters that Base is here before Extensible (it is inherited by Serializable) */
-class CoreExport NickAlias : public Serializable, public Extensible, public Flags<NickNameFlag, NS_END>
+/* A registered nickname.
+ * It matters that Base is here before Extensible (it is inherited by Serializable)
+ */
+class CoreExport NickAlias : public Serializable, public Extensible, public Flags<NickNameFlag>
{
Anope::string vhost_ident, vhost_host, vhost_creator;
time_t vhost_created;
public:
- /** Default constructor
+ Anope::string nick;
+ Anope::string last_quit;
+ Anope::string last_realname;
+ /* Last usermask this nick was seen on, eg user@host */
+ Anope::string last_usermask;
+ /* Last uncloaked usermask, requires nickserv/auspex to see */
+ Anope::string last_realhost;
+ time_t time_registered;
+ time_t last_seen;
+ /* Account this nick is tied to. Multiple nicks can be tied to a single account. */
+ Serialize::Reference<NickCore> nc;
+
+ /** Constructor
* @param nickname The nick
* @param nickcore The nickcore for this nick
*/
NickAlias(const Anope::string &nickname, NickCore *nickcore);
-
- /** Default destructor
- */
~NickAlias();
- Anope::string nick; /* Nickname */
- Anope::string last_quit; /* Last quit message */
- Anope::string last_realname; /* Last realname */
- Anope::string last_usermask; /* Last usermask */
- Anope::string last_realhost; /* Last uncloaked usermask, requires nickserv/auspex to see */
- time_t time_registered; /* When the nick was registered */
- time_t last_seen; /* When it was seen online for the last time */
- serialize_obj<NickCore> nc; /* I'm an alias of this */
-
- Serialize::Data serialize() const anope_override;
- static Serializable* unserialize(Serializable *obj, Serialize::Data &);
+ Serialize::Data Serialize() const anope_override;
+ static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
/** Release a nick
* See the comment in users.cpp
@@ -184,41 +173,67 @@ class CoreExport NickAlias : public Serializable, public Extensible, public Flag
* @return the time it was created
*/
time_t GetVhostCreated() const;
+
+ /** Finds a registered nick
+ * @param nick The nick to lookup
+ * @return the nick, if found
+ */
+ static NickAlias *Find(const Anope::string &nick);
};
-/* It matters that Base is here before Extensible (it is inherited by Serializable) */
-class CoreExport NickCore : public Serializable, public Extensible, public Flags<NickCoreFlag, NI_END>
+/* A registered account. Each account must have a NickAlias with the same nick as the
+ * account's display.
+ * It matters that Base is here before Extensible (it is inherited by Serializable)
+ */
+class CoreExport NickCore : public Serializable, public Extensible, public Flags<NickCoreFlag>
{
public:
- /** Default constructor
- * @param display The display nick
- */
- NickCore(const Anope::string &nickdisplay);
+ /* Name of the account. Find(display)->nc == this. */
+ Anope::string display;
+ /* User password in form of hashm:data */
+ Anope::string pass;
+ Anope::string email;
+ /* Greet associated with the account, sometimes sent when the user joins a channel */
+ Anope::string greet;
+ /* Locale name of the language of the user. Empty means default language */
+ Anope::string language;
+ /* Access list, contains user@host masks of users who get certain privileges based
+ * on if NI_SECURE is set and what (if any) kill protection is enabled. */
+ std::vector<Anope::string> access;
+ /* SSL certificate list. Users who have a matching certificate may be automatically logged in */
+ std::vector<Anope::string> cert;
+ MemoInfo memos;
- /** Default destructor
+ /* Nicknames registered that are grouped to this account.
+ * for n in aliases, n->nc == this.
*/
- ~NickCore();
-
- std::list<User *> Users;
-
- Anope::string display; /* How the nick is displayed */
- Anope::string pass; /* Password of the nicks */
- Anope::string email; /* E-mail associated to the nick */
- Anope::string greet; /* Greet associated to the nick */
- Anope::string language; /* Language name */
- std::vector<Anope::string> access; /* Access list, vector of strings */
- std::vector<Anope::string> cert; /* ssl certificate list, vector of strings */
- MemoInfo memos;
+ std::list<Serialize::Reference<NickAlias> > aliases;
+ /* Set if this user is a services operattor. o->ot must exist. */
Oper *o;
/* Unsaved data */
- uint16_t channelcount; /* Number of channels currently registered */
- time_t lastmail; /* Last time this nick record got a mail */
- std::list<serialize_obj<NickAlias> > aliases; /* List of aliases */
- Serialize::Data serialize() const anope_override;
- static Serializable* unserialize(Serializable *obj, Serialize::Data &);
+ /* Number of channels registered by this account */
+ uint16_t channelcount;
+ /* Last time an email was sent to this user */
+ time_t lastmail;
+ /* Users online now logged into this account */
+ std::list<User *> users;
+
+ /** Constructor
+ * @param display The display nick
+ */
+ NickCore(const Anope::string &nickdisplay);
+ ~NickCore();
+
+ Serialize::Data Serialize() const anope_override;
+ static Serializable* Unserialize(Serializable *obj, Serialize::Data &);
+
+ /** Changes the display for this account
+ * @param na The new display, must be grouped to this account.
+ */
+ void SetDisplay(const NickAlias *na);
/** Checks whether this account is a services oper or not.
* @return True if this account is a services oper, false otherwise.
@@ -265,6 +280,14 @@ class CoreExport NickCore : public Serializable, public Extensible, public Flags
*/
void ClearAccess();
+ /** Is the given user on this accounts access list?
+ *
+ * @param u The user
+ *
+ * @return true if the user is on the access list
+ */
+ bool IsOnAccess(const User *u) const;
+
/** Add an entry to the nick's certificate list
*
* @param entry The fingerprint to add to the cert list
@@ -304,10 +327,21 @@ class CoreExport NickCore : public Serializable, public Extensible, public Flags
* Deletes all the memory allocated in the certificate list vector and then clears the vector.
*/
void ClearCert();
+
+ /** Finds an account
+ * @param nick The account name to find
+ * @return The account, if it exists
+ */
+ static NickCore* Find(const Anope::string &nick);
};
+/* A request to check if an account/password is valid. These can exist for
+ * extended periods of time due to some authentication modules take.
+ */
class CoreExport IdentifyRequest
{
+ /* Owner of this request, used to cleanup requests if a module is unloaded
+ * while a reqyest us pending */
Module *owner;
Anope::string account;
Anope::string password;
@@ -316,35 +350,47 @@ class CoreExport IdentifyRequest
bool dispatched;
bool success;
- static std::set<IdentifyRequest *> requests;
+ static std::set<IdentifyRequest *> Requests;
protected:
IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass);
virtual ~IdentifyRequest();
public:
+ /* One of these is called when the request goes through */
virtual void OnSuccess() = 0;
virtual void OnFail() = 0;
const Anope::string &GetAccount() const { return account; }
const Anope::string &GetPassword() const { return password; }
- /* Hold this request. Once held it must be Release()d later on */
+ /* Holds this request. When a request is held it must be Released later
+ * for the request to complete. Multiple modules may hold a request at any time,
+ * but the request is not complete until every module has released it. If you do not
+ * require holding this (eg, your password check is done in this thread and immediately)
+ * then you don't need to hold the request before Successing it.
+ * @param m The module holding this request
+ */
void Hold(Module *m);
+
+ /** Releases a held request
+ * @param m The module releaseing the hold
+ */
void Release(Module *m);
+ /** Called by modules when this IdentifyRequest has successeded successfully.
+ * If this request is behind held it must still be Released after calling this.
+ * @param m The module confirming authentication
+ */
void Success(Module *m);
+ /** Used to either finalize this request or marks
+ * it as dispatched and begins waiting for the module(s)
+ * that have holds to finish.
+ */
void Dispatch();
static void ModuleUnload(Module *m);
};
-extern CoreExport void change_core_display(NickCore *nc);
-extern CoreExport void change_core_display(NickCore *nc, const Anope::string &newdisplay);
-
-extern CoreExport NickAlias *findnick(const Anope::string &nick);
-extern CoreExport NickCore *findcore(const Anope::string &nick);
-extern CoreExport bool is_on_access(const User *u, const NickCore *nc);
-
#endif // ACCOUNT_H
diff --git a/include/anope.h b/include/anope.h
index b6033b15c..2dda6cf76 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -1,4 +1,5 @@
/*
+ *
* (C) 2003-2012 Anope Team
* Contact us at team@anope.org
*
@@ -6,6 +7,7 @@
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
+ *
*/
#ifndef ANOPE_H
@@ -304,11 +306,52 @@ namespace Anope
static const char *const compiled = __TIME__ " " __DATE__;
+ /** The time Anope started.
+ */
+ extern time_t StartTime;
+
+ /** The value to return from main()
+ */
+ extern int ReturnValue;
+ extern bool Quitting;
+ extern bool Restarting;
+ extern Anope::string QuitReason;
+
/** The current system time, which is pretty close to being accurate.
* Use this unless you need very specific time checks
*/
extern CoreExport time_t CurTime;
+ /** The debug level we are running at.
+ */
+ extern int Debug;
+
+ /** Other comand line options.
+ */
+ extern bool ReadOnly, NoFork, NoThird, NoExpire, ProtocolDebug;
+
+ /** The root of the services installation. Usually ~/services
+ */
+ extern Anope::string ServicesDir;
+
+ /** Services binary name (eg services)
+ */
+ extern Anope::string ServicesBin;
+
+ /** Various directory paths. These can be set at runtime by command line args
+ */
+ extern Anope::string ConfigDir;
+ extern Anope::string DataDir;
+ extern Anope::string ModuleDir;
+ extern Anope::string LocaleDir;
+ extern Anope::string LogDir;
+
+ /** The uplink we are currently connected to
+ */
+ extern int CurrentUplink;
+
+ /** Various methods to determine the Anope version running
+ */
extern CoreExport string Version();
extern CoreExport string VersionShort();
extern CoreExport string VersionBuildString();
@@ -316,6 +359,29 @@ namespace Anope
extern CoreExport int VersionMinor();
extern CoreExport int VersionPatch();
+ /** Determines if we are still attached to the terminal, and can print
+ * messages to the user via stderr/stdout.
+ * @return true if still attached
+ */
+ extern bool AtTerm();
+
+ /** Used to "fork" the process and go into the background during initial startup
+ * while we are AtTerm(). The actual fork is not done here, but earlier, and this
+ * simply notifys the parent via kill() to exit().
+ */
+ extern void Fork();
+
+ /** One of the first functions called, does general initialization such as reading
+ * command line args, loading the configuration, doing the initial fork() if necessary,
+ * initializating language support, loading modules, and loading databases.
+ * @throws CoreException if something bad went wrong
+ */
+ extern void Init(int ac, char **av);
+
+ /** Calls the save database event
+ */
+ extern void SaveDatabases();
+
/** Check whether two strings match.
* @param str The string to check against the pattern (e.g. foobar)
* @param mask The pattern to check (e.g. foo*bar)
@@ -350,6 +416,20 @@ namespace Anope
*/
extern CoreExport void B64Decode(const string &src, string &target);
+ /** Encrypts what is in 'src' to 'dest'
+ * @param src The source string to encrypt
+ * @param dest The destination where the encrypted string is placed
+ */
+ extern void Encrypt(const Anope::string &src, Anope::string &dest);
+
+ /** Decrypts what is in 'src' to 'dest'.
+ * @param src The source string to decrypt
+ * @param dest The destination where the decrypted string is placed
+ * @return true if decryption was successful. This is usually not the case
+ * as most encryption methods we use are one way.
+ */
+ extern bool Decrypt(const Anope::string &src, Anope::string &dest);
+
/** Returns a sequence of data formatted as the format argument specifies.
** After the format parameter, the function expects at least as many
** additional arguments as specified in format.
@@ -368,6 +448,48 @@ namespace Anope
* @return An error message
*/
extern CoreExport const string LastError();
+
+ /** Determines if a path is a file
+ */
+ extern bool IsFile(const Anope::string &file);
+
+ /** Converts a string into seconds
+ * @param s The string, eg 3d
+ * @return The time represented by the string, eg 259,200
+ */
+ extern time_t DoTime(const Anope::string &s);
+
+ /** Retrieves a human readable string representing the time in seconds
+ * @param seconds The time on seconds, eg 60
+ * @param nc The account to use langauge settings for to translate this string, if applicable
+ * @return A human readable string, eg "1 minute"
+ */
+ extern Anope::string Duration(time_t seconds, const NickCore *nc = NULL);
+
+ /** Generates a human readable string of type "expires in ..."
+ * @param expires time in seconds
+ * @param nc The account to use langauge settings for to translate this string, if applicable
+ * @return A human readable string, eg "expires in 5 days"
+ */
+ extern Anope::string Expires(time_t seconds, const NickCore *nc = NULL);
+
+ /** Converts a time in seconds (epoch) to a human readable format.
+ * @param t The time
+ * @param nc The account to use langauge settings for to translate this string, if applicable
+ * @param short_output If true, the output is just a date (eg, "Apr 12 20:18:22 2009 MSD"), else it includes the date and how long ago/from now that date is, (eg "Apr 12 20:18:22 2009 MSD (1313 days, 9 hours, 32 minutes ago)"
+ */
+ extern Anope::string strftime(time_t t, const NickCore *nc = NULL, bool short_output = false);
+
+ /** Normalize buffer, stripping control characters and colors
+ * @param A string to be parsed for control and color codes
+ * @return A string stripped of control and color codes
+ */
+ extern Anope::string NormalizeBuffer(const Anope::string &);
+
+ /** Main processing routine. Parses the message and takes the appropriate action.
+ * @param Raw message from the uplink
+ */
+ extern void Process(const Anope::string &);
}
/** sepstream allows for splitting token seperated lists.
@@ -394,23 +516,52 @@ class CoreExport sepstream
/** Create a sepstream and fill it with the provided data
*/
sepstream(const Anope::string &source, char seperator);
- virtual ~sepstream() { }
/** Fetch the next token from the stream
* @param token The next token from the stream is placed here
* @return True if tokens still remain, false if there are none left
*/
- virtual bool GetToken(Anope::string &token);
+ bool GetToken(Anope::string &token);
+
+ /** Gets token number 'num' from the stream
+ * @param token The token is placed here
+ * @param num The token number to featch
+ * @return True if the token was able to be detched
+ */
+ bool GetToken(Anope::string &token, int num);
+
+ /** Gets every token from this stream
+ * @param token Tokens are pushed back here
+ */
+ template<typename T> void GetTokens(T& token)
+ {
+ token.clear();
+ Anope::string t;
+ while (this->GetToken(t))
+ token.push_back(t);
+ }
+
+ /** Gets token number 'num' from the stream and all remaining tokens.
+ * @param token The token is placed here
+ * @param num The token number to featch
+ * @return True if the token was able to be detched
+ */
+ bool GetTokenRemainder(Anope::string &token, int num);
+
+ /** Determines the number of tokens in this stream.
+ * @return The number of tokens in this stream
+ */
+ int NumTokens();
/** Fetch the entire remaining stream, without tokenizing
* @return The remaining part of the stream
*/
- virtual const Anope::string GetRemaining();
+ const Anope::string GetRemaining();
/** Returns true if the end of the stream has been reached
* @return True if the end of the stream has been reached, otherwise false
*/
- virtual bool StreamEnd();
+ bool StreamEnd();
};
/** A derived form of sepstream, which seperates on commas
@@ -478,14 +629,6 @@ class CoreException : public std::exception
}
};
-class FatalException : public CoreException
-{
- public:
- FatalException(const Anope::string &reason = "") : CoreException(reason) { }
-
- virtual ~FatalException() throw() { }
-};
-
class ModuleException : public CoreException
{
public:
@@ -600,39 +743,43 @@ template<typename T, typename O> inline T anope_dynamic_reinterpret_cast(O ptr)
/** Class with the ability to keep flags on items, they should extend from this
* where T is an enum.
*/
-template<typename T, size_t Size = 32> class Flags
+template<typename T> class Flags
{
- protected:
- std::bitset<Size> Flag_Values;
- const Anope::string *Flag_Strings;
+ std::vector<bool> flags_values;
+ static const Anope::string *flags_strings;
public:
- Flags() : Flag_Strings(NULL) { }
- Flags(const Anope::string *flag_strings) : Flag_Strings(flag_strings) { }
-
/** Add a flag to this item
- * @param Value The flag
+ * @param value The flag
*/
- void SetFlag(T Value)
+ void SetFlag(T value)
{
- Flag_Values[Value] = true;
+ if (value < 0)
+ return;
+
+ if (static_cast<unsigned>(value) >= flags_values.size())
+ flags_values.resize(value + 1);
+ flags_values[value] = true;
}
/** Remove a flag from this item
- * @param Value The flag
+ * @param value The flag
*/
- void UnsetFlag(T Value)
+ void UnsetFlag(T value)
{
- Flag_Values[Value] = false;
+ if (value >= 0 && static_cast<unsigned>(value) < flags_values.size())
+ flags_values[value] = false;
}
/** Check if this item has a flag
- * @param Value The flag
+ * @param value The flag
* @return true or false
*/
- bool HasFlag(T Value) const
+ bool HasFlag(T value) const
{
- return Flag_Values.test(Value);
+ if (value >= 0 && static_cast<unsigned>(value) < flags_values.size())
+ return flags_values[value];
+ return false;
}
/** Check how many flags are set
@@ -640,14 +787,23 @@ template<typename T, size_t Size = 32> class Flags
*/
size_t FlagCount() const
{
- return Flag_Values.count();
+ size_t c = 0;
+ for (unsigned i = 0; i < flags_values.size(); ++i)
+ if (flags_values[i])
+ ++c;
+ return c;
}
/** Unset all of the flags
*/
void ClearFlags()
{
- Flag_Values.reset();
+ flags_values.clear();
+ }
+
+ static const Anope::string* GetFlagStrings()
+ {
+ return flags_strings;
}
Anope::string ToString() const
@@ -675,9 +831,9 @@ template<typename T, size_t Size = 32> class Flags
std::vector<Anope::string> ToVector() const
{
std::vector<Anope::string> ret;
- for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i)
+ for (unsigned i = 0; this->flags_strings && !this->flags_strings[i].empty(); ++i)
if (this->HasFlag(static_cast<T>(i)))
- ret.push_back(this->Flag_Strings[i]);
+ ret.push_back(this->flags_strings[i]);
return ret;