update// added ChatDataStore and SietchDataStore with factory-pattern

This commit is contained in:
Strider
2020-05-08 20:01:57 +02:00
parent 2e8b46c863
commit d0562d2c65
4 changed files with 33 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
#ifndef DATASTORE_H #ifndef CHATDATASTORE_H
#define DATASTORE_H #define CHATDATASTORE_H
using json = nlohmann::json; using json = nlohmann::json;
@@ -15,15 +15,15 @@ class ChatDataStore
} }
public: public:
static ChatDataStore<T>* getInstance() static ChatDataStore* getInstance()
{ {
if(!ChatDataStore<T>::instanced) if(!ChatDataStore::instanced)
{ {
ChatDataStore<T>::instanced = true; ChatDataStore::instanced = true;
ChatDataStore<T>::instance = new ChatDataStore(); ChatDataStore::instance = new ChatDataStore();
} }
return ChatDataStore<ChatItem>::instance; return ChatDataStore::instance;
} }
void clear(); void clear();
@@ -33,7 +33,8 @@ class ChatDataStore
~ChatDataStore() ~ChatDataStore()
{ {
ChatDataStore<T>::instanced = false; ChatDataStore::instanced = false;
ChatDataStore::instance = nullptr;
} }
}; };
@@ -43,7 +44,7 @@ void ChatDataStore::clear()
} }
void ChatDataStore:setData(QString key, ChatItem value) void ChatDataStore::setData(QString key, ChatItem value)
{ {
this->data[key] = value; this->data[key] = value;
} }

View File

@@ -6,16 +6,19 @@
class DataStore class DataStore
{ {
public: public:
static SietchDataStore* getSietchDataStore() static SietchDataStore* getSietchDataStore();
{ static ChatDataStore* getChatDataStore();
return SietchDataStore::getInstance(); };
}
static ChatDataStore* getChatDataStore() SietchDataStore* DataStore::getSietchDataStore()
{ {
return ChatDataStore::getInstance(); return SietchDataStore::getInstance();
} }
ChatDataStore* DataStore::getChatDataStore()
{
return ChatDataStore::getInstance();
} }
#endif #endif

View File

@@ -1,5 +1,5 @@
#ifndef SietchDataStore_H #ifndef SIETCHDATASTORE_H
#define SietchDataStore_H #define SIETCHDATASTORE_H
using json = nlohmann::json; using json = nlohmann::json;
@@ -31,9 +31,10 @@ class SietchDataStore
QString getData(QString key); QString getData(QString key);
QString dump(); QString dump();
~ChatDataStore() ~SietchDataStore()
{ {
ChatDataStore::instanced = false; SietchDataStore::instanced = false;
SietchDataStore::instance = nullptr;
} }
}; };
@@ -52,12 +53,12 @@ QString SietchDataStore::getData(QString key)
return this->data[key]; return this->data[key];
} }
QString ChatDataStore::dump() QString SietchDataStore::dump()
{ {
return ""; return "";
} }
ChatDataStore* ChatDataStore::instance = nullptr; SietchDataStore* SietchDataStore::instance = nullptr;
bool ChatDataStore::instanced = false; bool SietchDataStore::instanced = false;
#endif #endif

View File

@@ -10,10 +10,10 @@
#include "websockets.h" #include "websockets.h"
#include "DataStore/DataStore.h" #include "DataStore/DataStore.h"
template<> /*template<>
DataStore<QString>* DataStore<QString>::instance = nullptr; DataStore<QString>* DataStore<QString>::instance = nullptr;
template<> template<>
bool DataStore<QString>::instanced = false; bool DataStore<QString>::instanced = false;*/
ChatModel *chatModel = new ChatModel(); ChatModel *chatModel = new ChatModel();
ContactModel *contactModel = new ContactModel(); ContactModel *contactModel = new ContactModel();
@@ -131,7 +131,7 @@ void Controller::fillTxJsonParams(json& allRecepients, Tx tx)
dust.at(i)["address"] = DataStore::getSietchDataStore()->getData(QString("Sietch" + QString(i))).toStdString(); dust.at(i)["address"] = DataStore::getSietchDataStore()->getData(QString("Sietch" + QString(i))).toStdString();
} }
DataStore<QString>::getInstance()->clear(); // clears the datastore DataStore::getSietchDataStore()->clear(); // clears the datastore
// Dust amt/memo, construct the JSON // Dust amt/memo, construct the JSON
for(uint8_t i = 0; i < 10; i++) for(uint8_t i = 0; i < 10; i++)