добавил очередь из сущностей

This commit is contained in:
Dmitry Borisenko
2022-01-19 18:03:57 +01:00
parent 629d7b798f
commit 5bdecdda04
6 changed files with 55 additions and 17 deletions

View File

@@ -11,3 +11,4 @@
#include "MqttClient.h"
#include "classes/CommandBuf.h"
#include "classes/QueueBuf.h"
#include "classes/QueueInst.h"

View File

@@ -1,4 +1,5 @@
#pragma once
#include "classes/QueueInst.h"
#include "Global.h"
#include <queue>
#include <iostream>
@@ -12,12 +13,12 @@ class QueueBuf {
QueueBuf();
~QueueBuf();
void push(int element);
void push(QueueInstance instance);
void pop();
int front();
QueueInstance front();
private:
queue<int> queue1;
queue<QueueInstance> queue1;
};
extern QueueBuf* myQueue;
extern QueueBuf* myQueue;

View File

@@ -0,0 +1,19 @@
#pragma once
#include "Global.h"
#include <queue>
#include <iostream>
using namespace std;
class QueueInstance;
class QueueInstance {
public:
QueueInstance(String text);
~QueueInstance();
String get();
private:
String _text;
};

View File

@@ -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");

View File

@@ -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;
QueueBuf* myQueue;

10
src/classes/QueueInst.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "classes/QueueInst.h"
QueueInstance::QueueInstance(String text) {
_text = text;
}
QueueInstance::~QueueInstance() {}
String QueueInstance::get() {
return _text;
}