From 9ba719688161499f01c168b1aed84a563bcb5953 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 15 Sep 2012 10:11:31 -0400 Subject: Make CommandSource use references, sometimes we hold them for awhile --- include/base.h | 7 +++++++ include/commands.h | 21 +++++++++++---------- include/logger.h | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/base.h b/include/base.h index 9ea0dc630..c09b97400 100644 --- a/include/base.h +++ b/include/base.h @@ -88,6 +88,13 @@ class dynamic_reference : public dynamic_reference_base return NULL; } + inline T* operator*() + { + if (operator bool()) + return this->ref; + return NULL; + } + inline void operator=(T *newref) { if (operator bool()) diff --git a/include/commands.h b/include/commands.h index c3a412624..45b122247 100644 --- a/include/commands.h +++ b/include/commands.h @@ -44,18 +44,18 @@ class CoreExport CommandSource /* The nick executing the command */ Anope::string nick; /* User executing the command, may be NULL */ - User *u; + dynamic_reference u; public: /* The account executing the command */ - NickCore *nc; + dynamic_reference nc; /* Where the reply should go */ CommandReply *reply; /* Channel the command was executed on (fantasy) */ - Channel *c; + dynamic_reference c; /* The service this command is on */ - BotInfo *owner; + dynamic_reference owner; /* The service the reply should come from, *not* necessarily the service the command is on */ - BotInfo *service; + dynamic_reference service; /* The actual name of the command being executed */ Anope::string command; /* The permission of the command being executed */ @@ -64,17 +64,18 @@ class CoreExport CommandSource CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *reply); const Anope::string &GetNick() const; - User *GetUser() const; - AccessGroup AccessFor(ChannelInfo *ci) const; - bool IsFounder(ChannelInfo *ci) const; + User *GetUser(); + NickCore *GetAccount(); + AccessGroup AccessFor(ChannelInfo *ci); + bool IsFounder(ChannelInfo *ci); void Reply(const char *message, ...); void Reply(const Anope::string &message); bool HasCommand(const Anope::string &cmd); bool HasPriv(const Anope::string &cmd); - bool IsServicesOper() const; - bool IsOper() const; + bool IsServicesOper(); + bool IsOper(); }; /** Every services command is a class, inheriting from Command. diff --git a/include/logger.h b/include/logger.h index eea86f890..9b3658e94 100644 --- a/include/logger.h +++ b/include/logger.h @@ -65,7 +65,7 @@ class CoreExport Log Log(LogType type = LOG_NORMAL, const Anope::string &category = "", const BotInfo *bi = NULL); /* LOG_COMMAND/OVERRIDE/ADMIN */ - Log(LogType type, const CommandSource &source, Command *c, const ChannelInfo *ci = NULL); + Log(LogType type, CommandSource &source, Command *c, const ChannelInfo *ci = NULL); /* LOG_CHANNEL */ Log(const User *u, Channel *c, const Anope::string &category = ""); -- cgit