-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.cpp
83 lines (73 loc) · 1.17 KB
/
Queue.cpp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "pch.h"
#include "framework.h"
#include "NuvoISPLite.h"
#include "Queue.h"
CQueue::CQueue()
{
m_u8Front = 0;
m_u8Rear = 0;
m_pu8Buffer = NULL;
m_u8UsedLength = 0;
}
CQueue::~CQueue()
{
if (m_pu8Buffer != NULL)
{
delete[]m_pu8Buffer;
m_pu8Buffer = NULL;
}
}
void CQueue::Init()
{
m_u8Front = 0;
m_u8Rear = 0;
if (m_pu8Buffer != NULL)
{
delete[]m_pu8Buffer;
m_pu8Buffer = NULL;
}
m_pu8Buffer = new BYTE[RX_BUF_SIZE];
memset(&m_pu8Buffer[0], 0, RX_BUF_SIZE);
m_u8UsedLength = 0;
}
bool CQueue::IsEmpty()
{
if (m_u8Front == m_u8Rear)
{
return true;
}
return false;
}
bool CQueue::IsFull()
{
BYTE u8Temp = (m_u8Rear + 1) % RX_BUF_SIZE;
if (m_u8Front == u8Temp)
{
return true;
}
return false;
}
void CQueue::Flush()
{
m_u8Front = 0;
m_u8Rear = 0;
m_u8UsedLength = 0;
}
void CQueue::Push(BYTE u8Byte)
{
if (m_pu8Buffer != NULL && IsFull() == false)
{
m_u8Rear = (m_u8Rear + 1) % RX_BUF_SIZE;
m_pu8Buffer[m_u8Rear] = u8Byte;
m_u8UsedLength++;
}
}
void CQueue::Pull(BYTE* pu8Byte)
{
if (m_pu8Buffer != NULL && IsEmpty() == false)
{
m_u8Front = (m_u8Front + 1) % RX_BUF_SIZE;
*pu8Byte = m_pu8Buffer[m_u8Front];
m_u8UsedLength--;
}
}