mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
проверка
This commit is contained in:
46
training/QueueFromChar.cpp
Normal file
46
training/QueueFromChar.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifdef QUEUE_FROM_CHAR
|
||||
#include "classes/QueueFromChar.h"
|
||||
|
||||
QueueFromChar::QueueFromChar() {
|
||||
commandList = NULL;
|
||||
commandCount = 0;
|
||||
}
|
||||
QueueFromChar::~QueueFromChar() {}
|
||||
|
||||
//добавление команды в буфер
|
||||
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));
|
||||
commandCount++;
|
||||
}
|
||||
|
||||
//распечатаем все добавленные команды
|
||||
void QueueFromChar::printCommands() {
|
||||
if (commandCount > 0 && commandList != NULL) {
|
||||
for (int i = 0; i < commandCount; i++) {
|
||||
Serial.println(commandList[i].command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//заберем последнюю из положенных в буфер команд
|
||||
String QueueFromChar::getLastCommand() {
|
||||
String ret = "empty";
|
||||
if (commandList != NULL) {
|
||||
int cnt = commandCount - 1;
|
||||
ret = commandList[cnt].command;
|
||||
if (cnt > 0) {
|
||||
delete commandList[cnt].command;
|
||||
} else if (cnt == 0) {
|
||||
commandList = NULL;
|
||||
}
|
||||
Serial.println("command deleted: " + ret + " " + String(cnt));
|
||||
commandCount--;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// QueueFromChar* myBuf;
|
||||
|
||||
#endif
|
||||
42
training/QueueFromChar.h
Normal file
42
training/QueueFromChar.h
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#ifdef QUEUE_FROM_CHAR
|
||||
|
||||
#define MAX_COMMAND_LENGTH 16
|
||||
#define BUFFER 128
|
||||
|
||||
class QueueFromChar;
|
||||
|
||||
class QueueFromChar {
|
||||
public:
|
||||
QueueFromChar();
|
||||
~QueueFromChar();
|
||||
|
||||
void addCommand(const char* command);
|
||||
|
||||
void printCommands();
|
||||
|
||||
String getLastCommand();
|
||||
|
||||
private:
|
||||
struct CharBufferStruct {
|
||||
char command[MAX_COMMAND_LENGTH + 1];
|
||||
};
|
||||
CharBufferStruct* commandList;
|
||||
int commandCount = 0;
|
||||
};
|
||||
|
||||
// extern QueueFromChar* myBuf;
|
||||
|
||||
//========проверка очереди=====================
|
||||
// myBuf = new QueueFromChar;
|
||||
// myBuf->addCommand("zero");
|
||||
// myBuf->addCommand("one");
|
||||
// myBuf->addCommand("two");
|
||||
// myBuf->printCommands();
|
||||
// myBuf->getLastCommand();
|
||||
// myBuf->getLastCommand();
|
||||
// myBuf->getLastCommand();
|
||||
// myBuf->printCommands();
|
||||
|
||||
#endif
|
||||
30
training/QueueFromInstance.cpp
Normal file
30
training/QueueFromInstance.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifdef QUEUE_FROM_INST
|
||||
#include "classes/QueueFromInstance.h"
|
||||
|
||||
QueueFromInstance::QueueFromInstance() {}
|
||||
QueueFromInstance::~QueueFromInstance() {}
|
||||
|
||||
//добавим элемент в конец очереди
|
||||
void QueueFromInstance::push(QueueInstance instance) {
|
||||
queue1.push(instance);
|
||||
}
|
||||
|
||||
//удалим элемент из начала очереди
|
||||
void QueueFromInstance::pop() {
|
||||
if (!queue1.empty()) {
|
||||
queue1.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//вернуть элемент из начала очереди и удалить его
|
||||
QueueInstance QueueFromInstance::front() {
|
||||
QueueInstance instance("");
|
||||
if (!queue1.empty()) {
|
||||
instance = queue1.front();
|
||||
queue1.pop();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
// QueueFromInstance* myQueue;
|
||||
#endif
|
||||
26
training/QueueFromInstance.h
Normal file
26
training/QueueFromInstance.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#ifdef QUEUE_FROM_INST
|
||||
#include "classes/QueueInst.h"
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class QueueFromInstance;
|
||||
|
||||
class QueueFromInstance {
|
||||
public:
|
||||
QueueFromInstance();
|
||||
~QueueFromInstance();
|
||||
|
||||
void push(QueueInstance instance);
|
||||
void pop();
|
||||
QueueInstance front();
|
||||
|
||||
private:
|
||||
queue<QueueInstance> queue1;
|
||||
};
|
||||
|
||||
// extern QueueFromInstance* myQueue;
|
||||
#endif
|
||||
24
training/QueueInst.cpp
Normal file
24
training/QueueInst.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifdef QUEUE_FROM_INST
|
||||
#include "queue/QueueInst.h"
|
||||
|
||||
QueueInstance::QueueInstance(String text) {
|
||||
_text = text;
|
||||
}
|
||||
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());
|
||||
#endif
|
||||
21
training/QueueInst.h
Normal file
21
training/QueueInst.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#ifdef QUEUE_FROM_INST
|
||||
#include <queue>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class QueueInstance;
|
||||
|
||||
class QueueInstance {
|
||||
public:
|
||||
QueueInstance(String text);
|
||||
~QueueInstance();
|
||||
|
||||
String get();
|
||||
|
||||
private:
|
||||
String _text;
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user