diff options
Diffstat (limited to 'include/modules/sql.h')
| -rw-r--r-- | include/modules/sql.h | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/include/modules/sql.h b/include/modules/sql.h index ded168a52..1fe87b5f1 100644 --- a/include/modules/sql.h +++ b/include/modules/sql.h @@ -6,12 +6,15 @@ * Please read COPYING and README for further details. */ +#pragma once + namespace SQL { - class Data : public Serialize::Data + class Data final + : public Serialize::Data { - public: + public: typedef std::map<Anope::string, std::stringstream *> Map; Map data; std::map<Anope::string, Type> types; @@ -21,7 +24,7 @@ namespace SQL Clear(); } - std::iostream& operator[](const Anope::string &key) anope_override + std::iostream &operator[](const Anope::string &key) override { std::stringstream *&ss = data[key]; if (!ss) @@ -29,44 +32,46 @@ namespace SQL return *ss; } - std::set<Anope::string> KeySet() const anope_override + std::set<Anope::string> KeySet() const override { std::set<Anope::string> keys; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - keys.insert(it->first); + for (const auto &[key, _] : this->data) + keys.insert(key); return keys; } - size_t Hash() const anope_override + size_t Hash() const override { size_t hash = 0; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - if (!it->second->str().empty()) - hash ^= Anope::hash_cs()(it->second->str()); + for (const auto &[_, value] : this->data) + { + if (!value->str().empty()) + hash ^= Anope::hash_cs()(value->str()); + } return hash; } std::map<Anope::string, std::iostream *> GetData() const { std::map<Anope::string, std::iostream *> d; - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - d[it->first] = it->second; + for (const auto &[key, value] : this->data) + d[key] = value; return d; } void Clear() { - for (Map::const_iterator it = this->data.begin(), it_end = this->data.end(); it != it_end; ++it) - delete it->second; + for (const auto &[_, value] : this->data) + delete value; this->data.clear(); } - void SetType(const Anope::string &key, Type t) anope_override + void SetType(const Anope::string &key, Type t) override { this->types[key] = t; } - Type GetType(const Anope::string &key) const anope_override + Type GetType(const Anope::string &key) const override { std::map<Anope::string, Type>::const_iterator it = this->types.find(key); if (it != this->types.end()) @@ -77,24 +82,24 @@ namespace SQL /** A SQL exception, can be thrown at various points */ - class Exception : public ModuleException + class DllExport Exception : public ModuleException { - public: + public: Exception(const Anope::string &reason) : ModuleException(reason) { } - virtual ~Exception() throw() { } + virtual ~Exception() noexcept = default; }; /** A SQL query */ - struct QueryData + struct QueryData final { Anope::string data; bool escape; }; - struct Query + struct Query final { Anope::string query; std::map<Anope::string, QueryData> parameters; @@ -102,7 +107,7 @@ namespace SQL Query() { } Query(const Anope::string &q) : query(q) { } - Query& operator=(const Anope::string &q) + Query &operator=(const Anope::string &q) { this->query = q; this->parameters.clear(); @@ -119,7 +124,7 @@ namespace SQL return !(*this == other); } - template<typename T> void SetValue(const Anope::string &key, const T& value, bool escape = true) + template<typename T> void SetValue(const Anope::string &key, const T &value, bool escape = true) { try { @@ -135,16 +140,16 @@ namespace SQL */ class Result { - protected: + protected: /* Rows, column, item */ std::vector<std::map<Anope::string, Anope::string> > entries; Query query; Anope::string error; - public: - unsigned int id; + public: + unsigned int id = 0; Anope::string finished_query; - Result() : id(0) { } + Result() = default; Result(unsigned int i, const Query &q, const Anope::string &fq, const Anope::string &err = "") : query(q), error(err), id(i), finished_query(fq) { } inline operator bool() const { return this->error.empty(); } @@ -183,11 +188,11 @@ namespace SQL */ class Interface { - public: + public: Module *owner; Interface(Module *m) : owner(m) { } - virtual ~Interface() { } + virtual ~Interface() = default; virtual void OnResult(const Result &r) = 0; virtual void OnError(const Result &r) = 0; @@ -195,9 +200,10 @@ namespace SQL /** Class providing the SQL service, modules call this to execute queries */ - class Provider : public Service + class Provider + : public Service { - public: + public: Provider(Module *c, const Anope::string &n) : Service(c, "SQL::Provider", n) { } virtual void Run(Interface *i, const Query &query) = 0; |
