mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
добавил очередь из сущностей
This commit is contained in:
@@ -11,3 +11,4 @@
|
|||||||
#include "MqttClient.h"
|
#include "MqttClient.h"
|
||||||
#include "classes/CommandBuf.h"
|
#include "classes/CommandBuf.h"
|
||||||
#include "classes/QueueBuf.h"
|
#include "classes/QueueBuf.h"
|
||||||
|
#include "classes/QueueInst.h"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "classes/QueueInst.h"
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -12,12 +13,12 @@ class QueueBuf {
|
|||||||
QueueBuf();
|
QueueBuf();
|
||||||
~QueueBuf();
|
~QueueBuf();
|
||||||
|
|
||||||
void push(int element);
|
void push(QueueInstance instance);
|
||||||
void pop();
|
void pop();
|
||||||
int front();
|
QueueInstance front();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
queue<int> queue1;
|
queue<QueueInstance> queue1;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern QueueBuf* myQueue;
|
extern QueueBuf* myQueue;
|
||||||
|
|||||||
19
include/classes/QueueInst.h
Normal file
19
include/classes/QueueInst.h
Normal 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;
|
||||||
|
};
|
||||||
19
src/Main.cpp
19
src/Main.cpp
@@ -55,13 +55,20 @@ void setup() {
|
|||||||
|
|
||||||
myQueue = new QueueBuf;
|
myQueue = new QueueBuf;
|
||||||
|
|
||||||
myQueue->push(10);
|
myQueue->push(*new QueueInstance("text1"));
|
||||||
myQueue->push(20);
|
myQueue->push(*new QueueInstance("text2"));
|
||||||
myQueue->push(30);
|
myQueue->push(*new QueueInstance("text3"));
|
||||||
|
|
||||||
Serial.println(myQueue->front());
|
Serial.println(myQueue->front().get());
|
||||||
Serial.println(myQueue->front());
|
Serial.println(myQueue->front().get());
|
||||||
Serial.println(myQueue->front());
|
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");
|
configure("/config.json");
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ QueueBuf::QueueBuf() {}
|
|||||||
QueueBuf::~QueueBuf() {}
|
QueueBuf::~QueueBuf() {}
|
||||||
|
|
||||||
//добавим элемент в конец очереди
|
//добавим элемент в конец очереди
|
||||||
void QueueBuf::push(int element) {
|
void QueueBuf::push(QueueInstance instance) {
|
||||||
queue1.push(element);
|
queue1.push(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
//удалим элемент из начала очереди
|
//удалим элемент из начала очереди
|
||||||
@@ -16,13 +16,13 @@ void QueueBuf::pop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//вернуть элемент из начала очереди и удалить его
|
//вернуть элемент из начала очереди и удалить его
|
||||||
int QueueBuf::front() {
|
QueueInstance QueueBuf::front() {
|
||||||
int ret;
|
QueueInstance instance("");
|
||||||
if (!queue1.empty()) {
|
if (!queue1.empty()) {
|
||||||
ret = queue1.front();
|
instance = queue1.front();
|
||||||
queue1.pop();
|
queue1.pop();
|
||||||
}
|
}
|
||||||
return ret;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
QueueBuf* myQueue;
|
QueueBuf* myQueue;
|
||||||
|
|||||||
10
src/classes/QueueInst.cpp
Normal file
10
src/classes/QueueInst.cpp
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#include "classes/QueueInst.h"
|
||||||
|
|
||||||
|
QueueInstance::QueueInstance(String text) {
|
||||||
|
_text = text;
|
||||||
|
}
|
||||||
|
QueueInstance::~QueueInstance() {}
|
||||||
|
|
||||||
|
String QueueInstance::get() {
|
||||||
|
return _text;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user