добавил класс очереди microsoft

This commit is contained in:
Dmitry Borisenko
2022-01-19 16:32:54 +01:00
parent a4fa6ad389
commit 629d7b798f
4 changed files with 71 additions and 9 deletions

View File

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

View File

@@ -0,0 +1,23 @@
#pragma once
#include "Global.h"
#include <queue>
#include <iostream>
using namespace std;
class QueueBuf;
class QueueBuf {
public:
QueueBuf();
~QueueBuf();
void push(int element);
void pop();
int front();
private:
queue<int> queue1;
};
extern QueueBuf* myQueue;

View File

@@ -41,17 +41,27 @@ void setup() {
sendConfigJson = new SendJson;
sendWigdetsJson = new SendJson;
myBuf = new CommandBuf;
// myBuf = new CommandBuf;
//
// myBuf->addCommand("zero");
// myBuf->addCommand("one");
// myBuf->addCommand("two");
// myBuf->printCommands();
//
// myBuf->getLastCommand();
// myBuf->getLastCommand();
// myBuf->getLastCommand();
// myBuf->printCommands();
myBuf->addCommand("zero");
myBuf->addCommand("one");
myBuf->addCommand("two");
myBuf->printCommands();
myQueue = new QueueBuf;
myBuf->getLastCommand();
myBuf->getLastCommand();
myBuf->getLastCommand();
//myBuf->printCommands();
myQueue->push(10);
myQueue->push(20);
myQueue->push(30);
Serial.println(myQueue->front());
Serial.println(myQueue->front());
Serial.println(myQueue->front());
configure("/config.json");

28
src/classes/QueueBuf.cpp Normal file
View File

@@ -0,0 +1,28 @@
#include "classes/QueueBuf.h"
QueueBuf::QueueBuf() {}
QueueBuf::~QueueBuf() {}
//добавим элемент в конец очереди
void QueueBuf::push(int element) {
queue1.push(element);
}
//удалим элемент из начала очереди
void QueueBuf::pop() {
if (!queue1.empty()) {
queue1.pop();
}
}
//вернуть элемент из начала очереди и удалить его
int QueueBuf::front() {
int ret;
if (!queue1.empty()) {
ret = queue1.front();
queue1.pop();
}
return ret;
}
QueueBuf* myQueue;