summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorJannis M. Hoffmann <jannis@fehcom.de>2023-10-11 23:26:51 +0200
committerJannis M. Hoffmann <jannis@fehcom.de>2023-10-11 23:26:51 +0200
commit52a9285ca78cb378c1b3c4487049a2d867a45d63 (patch)
treebf4e3882473fde89b84a6aacbc09fb475606eb0f /src/include
parentb33912838f8d86284d5e4efa18bb8d23686106d8 (diff)
use smart pointer types in IOFactory, BrokerFactory and Broker
Diffstat (limited to 'src/include')
-rw-r--r--src/include/broker.h36
-rw-r--r--src/include/imapparser.h12
-rw-r--r--src/include/iofactory.h12
3 files changed, 26 insertions, 34 deletions
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 <map>
+#include <memory>
#include <string>
namespace Binc {
@@ -23,7 +24,7 @@ namespace Binc {
class BrokerFactory {
private:
- std::map<Session::State, Broker *> brokers;
+ std::map<Session::State, Broker> 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<Operator> 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<std::string, Operator *> operators;
- std::map<std::string, bool> deletables;
+ std::map<std::string, std::shared_ptr<Operator>> 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<Operator> 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 &copy);
-
SequenceSet();
SequenceSet(const SequenceSet &copy);
+ SequenceSet &operator=(const SequenceSet &copy);
~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 <map>
+#include <memory>
#include <string>
namespace Binc {
class IOFactory {
- public:
- ~IOFactory();
+ std::map<std::string, std::unique_ptr<IODevice>> devices;
- static void addDevice(IODevice *dev);
+ public:
+ static void addDevice(std::unique_ptr<IODevice> dev);
static IOFactory &getInstance();
static IODevice &getClient();
static IODevice &getLogger();
-
- private:
- IOFactory();
-
- std::map<std::string, IODevice *> devices;
};
}