blob: 443ab4088b5add149fb94b006008169b8858dbb9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include "XMemQueue.h"
#ifndef SPDLOG_ACTIVE_LEVEL
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
#endif
#include "spdlog/spdlog.h"
using namespace std;
using namespace vagt::queue;
vagt::queue::XMemQueue::XMemQueue(int capacity):capacity_(capacity),size_(0)
{
}
bool vagt::queue::XMemQueue::empty()
{
return 0 == size_;
}
XErrorCode vagt::queue::XMemQueue::push(const std::string & val)
{
if (size_ >= capacity_)
{
queue_.pop();
SPDLOG_WARN("Drop from queue.");
size_--;
}
queue_.push(val);
size_++;
return XErrorOk;
}
void vagt::queue::XMemQueue::pop()
{
//cal empty() before cal pop()
queue_.pop();
size_--;
}
std::string vagt::queue::XMemQueue::front()
{
//cal empty() before cal pop()
return queue_.front();
}
|