libcdos-fw
CFList.h
1 #ifndef __CF_LIST_H__
2 #define __CF_LIST_H__
3 
4 #include <Core/CFTypes.h>
5 
6 #include <vector>
7 
14 template<typename T>
15 class CFList {
16 public:
21  : m_vector(std::vector<T>()) {
22 
23  }
24 
29  CFList(const CFList<T>& other)
30  : m_vector(other.m_vector) {
31 
32  }
33 
39  ~CFList() {
40 
41  }
42 
50  bool isEmpty() const {
51  return m_vector.empty();
52  }
53 
60  void append(T data) {
61  insert(data, -1);
62  }
63 
71  void insert(T data, CFInt pos) {
72  CFInt vsize = m_vector.size();
73  if (0 <= pos && vsize > pos) {
74  m_vector.insert(m_vector.begin() + pos, data);
75  } else {
76  m_vector.push_back(data);
77  }
78  }
79 
85  void remove(CFInt pos) {
86  CFInt vsize = m_vector.size();
87  if (0 <= pos && vsize > pos) {
88  m_vector.remove(m_vector.begin() + pos);
89  } else {
90  // Do nothing
91  }
92  }
93 
98  void clear() {
99  m_vector.clear();
100  }
101 
108  T first() {
109  return m_vector.front();
110  }
111 
118  T last() {
119  return m_vector.back();
120  }
121 
127  T at(CFInt pos) {
128  CFInt vsize = m_vector.size();
129  if (0 <= pos && vsize > pos) {
130  return m_vector.at(pos);
131  }
132  return T();
133  }
134 
140  CFInt size() {
141  return m_vector.size();
142  }
143 
150  T operator[] (CFInt pos) {
151  return at(pos);
152  }
153 
160  CFList<T>& operator=(const CFList<T>& other) {
161  this->m_vector = other.m_vector;
162  return *this;
163  }
164 
165 private:
166  std::vector<T> m_vector;
167 };
168 
169 #endif // __CF_LIST_H__
CFList 容器类.
Definition: CFList.h:15
void insert(T data, CFInt pos)
将数据添加到列表中,指定的位置。
Definition: CFList.h:71
CFList< T > & operator=(const CFList< T > &other)
重载赋值运算符。
Definition: CFList.h:160
bool isEmpty() const
判断该列表是否为空。
Definition: CFList.h:50
CFInt size()
获取列表中数据的个数。
Definition: CFList.h:140
void clear()
清除列表中储存的所有内容。
Definition: CFList.h:98
结构与枚举类型定义.
void append(T data)
将数据添加到列表的最后一位。
Definition: CFList.h:60
~CFList()
析构函数.
Definition: CFList.h:39
T operator[](CFInt pos)
获取列表中指定位置的数据。
Definition: CFList.h:150
CFList()
默认构造函数.
Definition: CFList.h:20
T at(CFInt pos)
获取列表中指定位置的数据。
Definition: CFList.h:127
T last()
获取列表中末位置的数据。
Definition: CFList.h:118
CFList(const CFList< T > &other)
拷贝构造函数.
Definition: CFList.h:29
T first()
获取列表中首位置的数据。
Definition: CFList.h:108