diff --git a/src/DataStore/ChatDataStore.h b/src/DataStore/ChatDataStore.h new file mode 100644 index 0000000..84291fc --- /dev/null +++ b/src/DataStore/ChatDataStore.h @@ -0,0 +1,64 @@ +#ifndef DATASTORE_H +#define DATASTORE_H + +using json = nlohmann::json; + +class ChatDataStore +{ + private: + static bool instanced; + static ChatDataStore* instance; + std::map data; + ChatDataStore() + { + + } + + public: + static ChatDataStore* getInstance() + { + if(!ChatDataStore::instanced) + { + ChatDataStore::instanced = true; + ChatDataStore::instance = new ChatDataStore(); + } + + return ChatDataStore::instance; + } + + void clear(); + void setData(QString key, ChatItem value); + ChatItem getData(QString key); + QString dump(); + + ~ChatDataStore() + { + ChatDataStore::instanced = false; + } +}; + +void ChatDataStore::clear() +{ + this->data.clear(); +} + + +void ChatDataStore:setData(QString key, ChatItem value) +{ + this->data[key] = value; +} + +ChatItem ChatDataStore::getData(QString key) +{ + return this->data[key]; +} + +QString ChatDataStore::dump() +{ + return ""; +} + +ChatDataStore* ChatDataStore::instance = nullptr; +bool ChatDataStore::instanced = false; + +#endif \ No newline at end of file diff --git a/src/DataStore/DataStore-deprecated.h b/src/DataStore/DataStore-deprecated.h new file mode 100644 index 0000000..19daa1b --- /dev/null +++ b/src/DataStore/DataStore-deprecated.h @@ -0,0 +1,58 @@ +#ifndef DATASTORE_H +#define DATASTORE_H + +#include +#include + +template +class DataStore +{ + private: + static bool instanced; + static DataStore* instance; + std::map data; + DataStore() + { + + } + + public: + static DataStore* getInstance() + { + if(!DataStore::instanced) + { + DataStore::instanced = true; + DataStore::instance = new DataStore(); + } + + return DataStore::instance; + } + + void clear(); + void setData(QString key, T value); + QString getData(QString key); + + ~DataStore() + { + DataStore::instanced = false; + } +}; + +template +void DataStore::clear() +{ + this->data.clear(); +} + +template +void DataStore::setData(QString key, T value) +{ + this->data[key] = value; +} + +template +QString DataStore::getData(QString key) +{ + return this->data[key]; +} +#endif \ No newline at end of file diff --git a/src/DataStore/DataStore.h b/src/DataStore/DataStore.h index 19daa1b..0aa8a09 100644 --- a/src/DataStore/DataStore.h +++ b/src/DataStore/DataStore.h @@ -1,58 +1,21 @@ #ifndef DATASTORE_H #define DATASTORE_H -#include -#include +#include "SietchDataStore.h" +#include "ChatDataStore.h" -template class DataStore { - private: - static bool instanced; - static DataStore* instance; - std::map data; - DataStore() - { +public: + static SietchDataStore* getSietchDataStore() + { + return SietchDataStore::getInstance(); + } - } - - public: - static DataStore* getInstance() - { - if(!DataStore::instanced) - { - DataStore::instanced = true; - DataStore::instance = new DataStore(); - } - - return DataStore::instance; - } - - void clear(); - void setData(QString key, T value); - QString getData(QString key); - - ~DataStore() - { - DataStore::instanced = false; - } -}; - -template -void DataStore::clear() -{ - this->data.clear(); + static ChatDataStore* getChatDataStore() + { + return ChatDataStore::getInstance(); + } } -template -void DataStore::setData(QString key, T value) -{ - this->data[key] = value; -} - -template -QString DataStore::getData(QString key) -{ - return this->data[key]; -} #endif \ No newline at end of file diff --git a/src/DataStore/SietchDataStore.h b/src/DataStore/SietchDataStore.h new file mode 100644 index 0000000..8739340 --- /dev/null +++ b/src/DataStore/SietchDataStore.h @@ -0,0 +1,63 @@ +#ifndef SietchDataStore_H +#define SietchDataStore_H + +using json = nlohmann::json; + +class SietchDataStore +{ + private: + static bool instanced; + static SietchDataStore* instance; + std::map data; + SietchDataStore() + { + + } + + public: + static SietchDataStore* getInstance() + { + if(!SietchDataStore::instanced) + { + SietchDataStore::instanced = true; + SietchDataStore::instance = new SietchDataStore(); + } + + return SietchDataStore::instance; + } + + void clear(); + void setData(QString key, QString value); + QString getData(QString key); + QString dump(); + + ~ChatDataStore() + { + ChatDataStore::instanced = false; + } +}; + +void SietchDataStore::clear() +{ + this->data.clear(); +} + +void SietchDataStore::setData(QString key, QString value) +{ + this->data[key] = value; +} + +QString SietchDataStore::getData(QString key) +{ + return this->data[key]; +} + +QString ChatDataStore::dump() +{ + return ""; +} + +ChatDataStore* ChatDataStore::instance = nullptr; +bool ChatDataStore::instanced = false; + +#endif \ No newline at end of file diff --git a/src/controller.cpp b/src/controller.cpp index 6ab187d..1228e55 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -97,7 +97,7 @@ void Controller::setConnection(Connection* c) { zrpc->createNewSietchZaddr( [=] (json reply) { QString zdust = QString::fromStdString(reply.get()[0]); - DataStore::getInstance()->setData("Sietch" + QString(i), zdust.toUtf8()); + DataStore::getSietchDataStore()->setData("Sietch" + QString(i), zdust.toUtf8()); }); } } @@ -120,7 +120,7 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) { zrpc->createNewSietchZaddr( [=] (json reply) { QString zdust = QString::fromStdString(reply.get()[0]); - DataStore::getInstance()->setData(QString("Sietch") + QString(i), zdust.toUtf8()); + DataStore::getSietchDataStore()->setData(QString("Sietch") + QString(i), zdust.toUtf8()); } ); } @@ -128,7 +128,7 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx) // Using DataStore singelton, to store the data into the dusts, bing bada boom :D for(uint8_t i = 0; i < 10; i++) { - dust.at(i)["address"] = DataStore::getInstance()->getData(QString("Sietch" + QString(i))).toStdString(); + dust.at(i)["address"] = DataStore::getSietchDataStore()->getData(QString("Sietch" + QString(i))).toStdString(); } DataStore::getInstance()->clear(); // clears the datastore