From 52a9285ca78cb378c1b3c4487049a2d867a45d63 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Wed, 11 Oct 2023 23:26:51 +0200 Subject: use smart pointer types in IOFactory, BrokerFactory and Broker --- src/include/broker.h | 36 ++++++++++++++++++------------------ src/include/imapparser.h | 12 ++++-------- src/include/iofactory.h | 12 ++++-------- 3 files changed, 26 insertions(+), 34 deletions(-) (limited to 'src/include') diff --git a/src/include/broker.h b/src/include/broker.h index 57c79dc..a6428e1 100644 --- a/src/include/broker.h +++ b/src/include/broker.h @@ -14,6 +14,7 @@ #include "session.h" #include +#include #include namespace Binc { @@ -23,7 +24,7 @@ namespace Binc { class BrokerFactory { private: - std::map brokers; + std::map brokers; BrokerFactory(); @@ -31,40 +32,39 @@ namespace Binc { public: Broker *getBroker(Session::State state); - void assign(const std::string &fname, Operator *o); + void assign(const std::string &fname, std::shared_ptr o); void addCapability(const std::string &c); Operator *getOperator(Session::State state, const std::string &name) const; - inline const std::string &getLastError() const; - inline void setLastError(const std::string &error) const; + const std::string &getLastError() const + { + return lastError; + } - static BrokerFactory &getInstance(); - ~BrokerFactory(); - }; + void setLastError(std::string error) const + { + lastError = std::move(error); + } - const std::string &BrokerFactory::getLastError() const - { - return lastError; - } + static BrokerFactory &getInstance(); - void BrokerFactory::setLastError(const std::string &error) const - { - lastError = error; - } + BrokerFactory(const BrokerFactory &) = delete; + BrokerFactory(const BrokerFactory &&) = delete; + }; class Broker { private: - std::map operators; - std::map deletables; + std::map> operators; public: Parser &parser; Operator *get(const std::string &name) const; - void assign(const std::string &fname, Operator *o, bool deletable = false); + void assign(const std::string &fname, std::shared_ptr o); Parser::ParseResult parseStub(Request &cmd); Broker(Parser &p) : parser(p){}; + Broker(const Broker &) = delete; Broker(Broker &&) = default; }; diff --git a/src/include/imapparser.h b/src/include/imapparser.h index e0daeb2..7d2ac27 100644 --- a/src/include/imapparser.h +++ b/src/include/imapparser.h @@ -28,10 +28,9 @@ namespace Binc { static SequenceSet &null(); - SequenceSet &operator=(const SequenceSet ©); - SequenceSet(); SequenceSet(const SequenceSet ©); + SequenceSet &operator=(const SequenceSet ©); ~SequenceSet(); protected: @@ -66,8 +65,7 @@ namespace Binc { std::string toString(); }; - class BincImapParserSearchKey { - public: + struct BincImapParserSearchKey { std::string name; std::string date; std::string astring; @@ -85,13 +83,11 @@ namespace Binc { BincImapParserSearchKey(); }; - class BincImapParserData { - public: - virtual ~BincImapParserData() {} + struct BincImapParserData { + virtual ~BincImapParserData() = default; }; class Request { - private: std::string tag; std::string name; std::string mode; diff --git a/src/include/iofactory.h b/src/include/iofactory.h index 24dfe9f..e19688a 100644 --- a/src/include/iofactory.h +++ b/src/include/iofactory.h @@ -11,22 +11,18 @@ #include "iodevice.h" #include +#include #include namespace Binc { class IOFactory { - public: - ~IOFactory(); + std::map> devices; - static void addDevice(IODevice *dev); + public: + static void addDevice(std::unique_ptr dev); static IOFactory &getInstance(); static IODevice &getClient(); static IODevice &getLogger(); - - private: - IOFactory(); - - std::map devices; }; } -- cgit v1.2.3