Blame view

src/ai_engine_module/sort/CycleQueue.h 1.53 KB
0b4cd5d5   Hu Chunming   完成轨迹定时抓拍
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  #include <iostream>
  
  using namespace std;
  
  #define MAX_LENGTH 100
  
  typedef struct TRACK_POINT
  {
  	int x;
  	int y;
  }TRACK_POINT;
  
  //template <class T>
  class cycleQueue
  {
  private:
  	unsigned int m_size;
  	int m_front;
  	int m_rear;
  	TRACK_POINT  m_data[MAX_LENGTH];
  
  	bool firstPush;
  	bool full_size;
  
  public:
  
  	cycleQueue() {}
  
  	cycleQueue(unsigned size)
  		:m_size(size),
  		m_front(0),
  		m_rear(0)
  	{
  		//m_data = new TRACK_POINT[size];
  		full_size = false;
  		firstPush = true;
  	}
  
  	void set_param(unsigned size)
  	{
  		m_size = size;
  		//m_data = new TRACK_POINT[size];
  		full_size = false;
  		firstPush = true;
  		m_front = 0;
  		m_rear = 0;
  	}
  
  	~cycleQueue()
  	{
  		//delete[] m_data;
  	}
  
  	bool isEmpty()
  	{
  		return m_front == m_rear;
  	}
  
  	bool isFull()
  	{
  		return m_front == (m_rear + 1) % m_size;
  	}
  
  	int getFront()
  	{
  		return m_front;
  	}
  
  	int getRear()
  	{
  		return m_rear;
  	}
  
  	int size()
  	{
  		if (full_size) return m_size;
  		else if (m_rear == m_front && firstPush == false) return m_size;
  		else return m_rear - m_front;
  	}
  
  	void push(TRACK_POINT ele)throw(bad_exception)
  	{
  		if (m_front == m_rear && firstPush==false)
  		{
  			m_front = (m_front + 1) % m_size;
  			full_size = true;
  			//cout << "full_size" << endl;
  		}
  
  		m_data[m_rear] = ele;
  		m_rear = (m_rear + 1) % m_size;
  		firstPush = false;	
  	}
  
  	TRACK_POINT pop() throw(bad_exception)
  	{
  		if (isEmpty())
  		{
  			throw bad_exception();
  		}
  		TRACK_POINT tmp = m_data[m_front];
  		m_front = (m_front + 1) % m_size;
  		return tmp;
  	}
  
  	TRACK_POINT& get(int i)
  	{
  		//T tmp = m_data[i];
  		return m_data[i];
  	}
  };