mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 14:42:18 +03:00
Добавил три типа очередей: очередь сущностей, очередь структур, и очередь char
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
#include "classes/CommandBuf.h"
|
||||
#include "classes/QueueFromChar.h"
|
||||
|
||||
CommandBuf::CommandBuf() {
|
||||
QueueFromChar::QueueFromChar() {
|
||||
commandList = NULL;
|
||||
commandCount = 0;
|
||||
}
|
||||
CommandBuf::~CommandBuf() {}
|
||||
QueueFromChar::~QueueFromChar() {}
|
||||
|
||||
//добавление команды в буфер
|
||||
void CommandBuf::addCommand(const char* command) {
|
||||
void QueueFromChar::addCommand(const char* command) {
|
||||
commandList = (CharBufferStruct*)realloc(commandList, (commandCount + 1) * sizeof(CharBufferStruct));
|
||||
strncpy(commandList[commandCount].command, command, MAX_COMMAND_LENGTH);
|
||||
Serial.println("command added: " + String(command) + " " + String(commandCount));
|
||||
@@ -15,7 +15,7 @@ void CommandBuf::addCommand(const char* command) {
|
||||
}
|
||||
|
||||
//распечатаем все добавленные команды
|
||||
void CommandBuf::printCommands() {
|
||||
void QueueFromChar::printCommands() {
|
||||
if (commandCount > 0 && commandList != NULL) {
|
||||
for (int i = 0; i < commandCount; i++) {
|
||||
Serial.println(commandList[i].command);
|
||||
@@ -24,7 +24,7 @@ void CommandBuf::printCommands() {
|
||||
}
|
||||
|
||||
//заберем последнюю из положенных в буфер команд
|
||||
String CommandBuf::getLastCommand() {
|
||||
String QueueFromChar::getLastCommand() {
|
||||
String ret = "empty";
|
||||
if (commandList != NULL) {
|
||||
int cnt = commandCount - 1;
|
||||
@@ -40,4 +40,4 @@ String CommandBuf::getLastCommand() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
CommandBuf* myBuf;
|
||||
QueueFromChar* myBuf;
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "classes/QueueBuf.h"
|
||||
#include "classes/QueueFromInstance.h"
|
||||
|
||||
QueueBuf::QueueBuf() {}
|
||||
QueueBuf::~QueueBuf() {}
|
||||
QueueFromInstance::QueueFromInstance() {}
|
||||
QueueFromInstance::~QueueFromInstance() {}
|
||||
|
||||
//добавим элемент в конец очереди
|
||||
void QueueBuf::push(QueueInstance instance) {
|
||||
void QueueFromInstance::push(QueueInstance instance) {
|
||||
queue1.push(instance);
|
||||
}
|
||||
|
||||
//удалим элемент из начала очереди
|
||||
void QueueBuf::pop() {
|
||||
void QueueFromInstance::pop() {
|
||||
if (!queue1.empty()) {
|
||||
queue1.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//вернуть элемент из начала очереди и удалить его
|
||||
QueueInstance QueueBuf::front() {
|
||||
QueueInstance QueueFromInstance::front() {
|
||||
QueueInstance instance("");
|
||||
if (!queue1.empty()) {
|
||||
instance = queue1.front();
|
||||
@@ -25,4 +25,4 @@ QueueInstance QueueBuf::front() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
QueueBuf* myQueue;
|
||||
QueueFromInstance* myQueue;
|
||||
27
src/classes/QueueFromStruct.cpp
Normal file
27
src/classes/QueueFromStruct.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "classes/QueueFromStruct.h"
|
||||
|
||||
QueueFromStruct::QueueFromStruct() {}
|
||||
QueueFromStruct::~QueueFromStruct() {}
|
||||
|
||||
//добавим элемент в конец очереди
|
||||
void QueueFromStruct::push(QueueItems word) {
|
||||
queue1.push(word);
|
||||
}
|
||||
|
||||
//удалим элемент из начала очереди
|
||||
void QueueFromStruct::pop() {
|
||||
if (!queue1.empty()) {
|
||||
queue1.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//вернуть элемент из начала очереди и удалить его
|
||||
QueueItems QueueFromStruct::front() {
|
||||
if (!queue1.empty()) {
|
||||
tmpItem = queue1.front();
|
||||
queue1.pop();
|
||||
}
|
||||
return tmpItem;
|
||||
}
|
||||
|
||||
QueueFromStruct* myQueueStruct;
|
||||
@@ -8,3 +8,15 @@ QueueInstance::~QueueInstance() {}
|
||||
String QueueInstance::get() {
|
||||
return _text;
|
||||
}
|
||||
|
||||
//========проверка очереди из экземпляров======
|
||||
|
||||
// myQueue = new QueueFromInstance;
|
||||
|
||||
// myQueue->push(QueueInstance("text1"));
|
||||
// myQueue->push(QueueInstance("text2"));
|
||||
// myQueue->push(QueueInstance("text3"));
|
||||
|
||||
// Serial.println(myQueue->front().get());
|
||||
// Serial.println(myQueue->front().get());
|
||||
// Serial.println(myQueue->front().get());
|
||||
Reference in New Issue
Block a user