diff --git a/include/Main.h b/include/Main.h index 5b716a09..e9727402 100644 --- a/include/Main.h +++ b/include/Main.h @@ -11,3 +11,4 @@ #include "MqttClient.h" #include "classes/CommandBuf.h" #include "classes/QueueBuf.h" +#include "classes/QueueInst.h" diff --git a/include/classes/QueueBuf.h b/include/classes/QueueBuf.h index 6aa60dfe..775fc6a0 100644 --- a/include/classes/QueueBuf.h +++ b/include/classes/QueueBuf.h @@ -1,4 +1,5 @@ #pragma once +#include "classes/QueueInst.h" #include "Global.h" #include #include @@ -12,12 +13,12 @@ class QueueBuf { QueueBuf(); ~QueueBuf(); - void push(int element); + void push(QueueInstance instance); void pop(); - int front(); + QueueInstance front(); private: - queue queue1; + queue queue1; }; -extern QueueBuf* myQueue; \ No newline at end of file +extern QueueBuf* myQueue; diff --git a/include/classes/QueueInst.h b/include/classes/QueueInst.h new file mode 100644 index 00000000..de6e0843 --- /dev/null +++ b/include/classes/QueueInst.h @@ -0,0 +1,19 @@ +#pragma once +#include "Global.h" +#include +#include + +using namespace std; + +class QueueInstance; + +class QueueInstance { + public: + QueueInstance(String text); + ~QueueInstance(); + + String get(); + + private: + String _text; +}; diff --git a/src/Main.cpp b/src/Main.cpp index bc5a7c4f..949a4417 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -55,13 +55,20 @@ void setup() { myQueue = new QueueBuf; - myQueue->push(10); - myQueue->push(20); - myQueue->push(30); + myQueue->push(*new QueueInstance("text1")); + myQueue->push(*new QueueInstance("text2")); + myQueue->push(*new QueueInstance("text3")); - Serial.println(myQueue->front()); - Serial.println(myQueue->front()); - Serial.println(myQueue->front()); + Serial.println(myQueue->front().get()); + Serial.println(myQueue->front().get()); + Serial.println(myQueue->front().get()); + + // myQueue->push(20); + // myQueue->push(30); + // + // Serial.println(myQueue->front()); + // Serial.println(myQueue->front()); + // Serial.println(myQueue->front()); configure("/config.json"); diff --git a/src/classes/QueueBuf.cpp b/src/classes/QueueBuf.cpp index 7c62514e..ceffc4e3 100644 --- a/src/classes/QueueBuf.cpp +++ b/src/classes/QueueBuf.cpp @@ -4,8 +4,8 @@ QueueBuf::QueueBuf() {} QueueBuf::~QueueBuf() {} //добавим элемент в конец очереди -void QueueBuf::push(int element) { - queue1.push(element); +void QueueBuf::push(QueueInstance instance) { + queue1.push(instance); } //удалим элемент из начала очереди @@ -16,13 +16,13 @@ void QueueBuf::pop() { } //вернуть элемент из начала очереди и удалить его -int QueueBuf::front() { - int ret; +QueueInstance QueueBuf::front() { + QueueInstance instance(""); if (!queue1.empty()) { - ret = queue1.front(); + instance = queue1.front(); queue1.pop(); } - return ret; + return instance; } -QueueBuf* myQueue; \ No newline at end of file +QueueBuf* myQueue; diff --git a/src/classes/QueueInst.cpp b/src/classes/QueueInst.cpp new file mode 100644 index 00000000..99a76f17 --- /dev/null +++ b/src/classes/QueueInst.cpp @@ -0,0 +1,10 @@ +#include "classes/QueueInst.h" + +QueueInstance::QueueInstance(String text) { + _text = text; +} +QueueInstance::~QueueInstance() {} + +String QueueInstance::get() { + return _text; +}