| |
3 |
3 |
|
| |
4 |
4 |
|
| |
5 |
5 |
|
| |
6 |
6 |
|
| |
7 |
7 |
|
| |
8 |
8 |
|
| |
9 |
9 |
|
| |
10 |
10 |
|
| |
11 |
11 |
|
| |
12 |
12 |
|
| |
13 |
13 |
|
| |
14 |
14 |
|
| |
15 |
15 |
|
| |
16 |
16 |
|
| |
17 |
17 |
|
| |
18 |
18 |
|
| |
19 |
19 |
#ifndef __RANDOMACCESSCONTAINERWRAPPER_H__ |
| |
20 |
20 |
#define __RANDOMACCESSCONTAINERWRAPPER_H__ |
| |
21 |
21 |
|
| |
22 |
22 |
#include "RandomAccessIterators.h" |
| |
|
23 |
#include <boost/type_traits/has_operator.hpp> |
| |
23 |
24 |
|
| |
24 |
25 |
template<class T> |
| |
25 |
26 |
class RandomAccessContainerWrapper |
| |
26 |
27 |
{ |
| |
27 |
28 |
public: |
| |
28 |
29 |
using iterator = RandomAccessIteratorWrapper<T>; |
| |
29 |
30 |
using const_iterator = RandomAccessConstIteratorWrapper<T>; |
| |
30 |
31 |
|
| |
31 |
32 |
public: |
| |
32 |
33 |
virtual ~RandomAccessContainerWrapper(); |
| |
33 |
34 |
|
| |
34 |
|
bool operator==(const RandomAccessContainerWrapper& rSrc) const; |
| |
35 |
|
bool operator!=(const RandomAccessContainerWrapper& rSrc) const; |
| |
|
35 |
template <typename U = T> |
| |
|
36 |
typename std::enable_if<boost::has_equal_to<U>::value, bool>::type operator==(const RandomAccessContainerWrapper& rSrc) const |
| |
|
37 |
{ |
| |
|
38 |
if(rSrc.GetCount() != GetCount()) |
| |
|
39 |
return false; |
| |
36 |
40 |
|
| |
|
41 |
size_t stCount = GetCount(); |
| |
|
42 |
while(stCount-- > 0) |
| |
|
43 |
{ |
| |
|
44 |
if(m_vItems[ stCount ] != rSrc.m_vItems[ stCount ]) |
| |
|
45 |
return false; |
| |
|
46 |
} |
| |
|
47 |
|
| |
|
48 |
return true; |
| |
|
49 |
} |
| |
|
50 |
|
| |
|
51 |
template <typename U = T> |
| |
|
52 |
typename std::enable_if<boost::has_not_equal_to<U>::value, bool>::type operator!=(const RandomAccessContainerWrapper& rSrc) const |
| |
|
53 |
{ |
| |
|
54 |
if(rSrc.GetCount() != GetCount()) |
| |
|
55 |
return true; |
| |
|
56 |
|
| |
|
57 |
size_t stCount = GetCount(); |
| |
|
58 |
while(stCount-- > 0) |
| |
|
59 |
{ |
| |
|
60 |
if(m_vItems[ stCount ] != rSrc.m_vItems[ stCount ]) |
| |
|
61 |
return true; |
| |
|
62 |
} |
| |
|
63 |
|
| |
|
64 |
return false; |
| |
|
65 |
} |
| |
|
66 |
|
| |
37 |
67 |
void Add(const T& str); |
| |
38 |
68 |
void InsertAt(size_t stIndex, const T& str); |
| |
39 |
69 |
void SetAt(size_t stIndex, const T& str); |
| |
40 |
70 |
void RemoveAt(size_t stIndex); |
| |
41 |
71 |
void Clear(); |
| |
42 |
72 |
|
| |
43 |
73 |
const T& GetAt(size_t stIndex) const; |
| |
|
74 |
T& GetAt(size_t stIndex); |
| |
44 |
75 |
|
| |
45 |
76 |
bool IsEmpty() const; |
| |
46 |
77 |
size_t GetCount() const; |
| |
47 |
78 |
|
| |
48 |
79 |
void Append(const RandomAccessContainerWrapper& rSrc); |
| |
49 |
80 |
|
| |
50 |
81 |
iterator begin(); |
| |
51 |
82 |
iterator end(); |
| |
52 |
83 |
const_iterator begin() const; |
| |
53 |
84 |
const_iterator end() const; |
| |
54 |
85 |
const_iterator cbegin() const; |
| |
55 |
86 |
const_iterator cend() const; |
| |
56 |
87 |
|
| |
57 |
88 |
protected: |
| |
58 |
89 |
#pragma warning(push) |
| |
59 |
90 |
#pragma warning(disable: 4251) |
| |
60 |
91 |
std::vector<T> m_vItems; |
| |
61 |
92 |
#pragma warning(pop) |
| |
62 |
93 |
}; |
| |
63 |
94 |
|
|
| |
98 |
129 |
|
| |
99 |
130 |
m_vItems.erase(m_vItems.begin() + stIndex); |
| |
100 |
131 |
} |
| |
101 |
132 |
|
| |
102 |
133 |
template<class T> |
| |
103 |
134 |
void RandomAccessContainerWrapper<T>::Clear() |
| |
104 |
135 |
{ |
| |
105 |
136 |
m_vItems.clear(); |
| |
106 |
137 |
} |
| |
107 |
138 |
|
| |
108 |
139 |
template<class T> |
| |
109 |
140 |
const T& RandomAccessContainerWrapper<T>::GetAt(size_t stIndex) const |
| |
110 |
141 |
{ |
| |
111 |
142 |
if (stIndex >= m_vItems.size()) |
| |
112 |
143 |
throw std::out_of_range("stIndex out of bounds"); |
| |
113 |
144 |
|
| |
114 |
145 |
return m_vItems.at(stIndex); |
| |
115 |
146 |
} |
| |
116 |
147 |
|
| |
117 |
148 |
template<class T> |
| |
|
149 |
T& RandomAccessContainerWrapper<T>::GetAt(size_t stIndex) |
| |
|
150 |
{ |
| |
|
151 |
if (stIndex >= m_vItems.size()) |
| |
|
152 |
throw std::out_of_range("stIndex out of bounds"); |
| |
|
153 |
|
| |
|
154 |
return m_vItems.at(stIndex); |
| |
|
155 |
} |
| |
|
156 |
|
| |
|
157 |
template<class T> |
| |
118 |
158 |
bool RandomAccessContainerWrapper<T>::IsEmpty() const |
| |
119 |
159 |
{ |
| |
120 |
160 |
return m_vItems.empty(); |
| |
121 |
161 |
} |
| |
122 |
162 |
|
| |
123 |
163 |
template<class T> |
| |
124 |
164 |
size_t RandomAccessContainerWrapper<T>::GetCount() const |
| |
125 |
165 |
{ |
| |
126 |
166 |
return m_vItems.size(); |
| |
127 |
167 |
} |
| |
128 |
168 |
|
| |
129 |
169 |
template<class T> |
| |
130 |
170 |
void RandomAccessContainerWrapper<T>::Append(const RandomAccessContainerWrapper& rSrc) |
| |
131 |
171 |
{ |
| |
132 |
172 |
m_vItems.insert(m_vItems.end(), rSrc.m_vItems.begin(), rSrc.m_vItems.end()); |
| |
133 |
173 |
} |
| |
134 |
174 |
|
| |
135 |
175 |
template<class T> |
| |
136 |
176 |
typename RandomAccessContainerWrapper<T>::iterator RandomAccessContainerWrapper<T>::begin() |
| |
137 |
177 |
{ |
|
| |
151 |
191 |
} |
| |
152 |
192 |
|
| |
153 |
193 |
template<class T> |
| |
154 |
194 |
typename RandomAccessContainerWrapper<T>::const_iterator RandomAccessContainerWrapper<T>::end() const |
| |
155 |
195 |
{ |
| |
156 |
196 |
return const_iterator(m_vItems.end()); |
| |
157 |
197 |
} |
| |
158 |
198 |
|
| |
159 |
199 |
template<class T> |
| |
160 |
200 |
typename RandomAccessContainerWrapper<T>::const_iterator RandomAccessContainerWrapper<T>::cbegin() const |
| |
161 |
201 |
{ |
| |
162 |
202 |
return const_iterator(m_vItems.cbegin()); |
| |
163 |
203 |
} |
| |
164 |
204 |
|
| |
165 |
205 |
template<class T> |
| |
166 |
206 |
typename RandomAccessContainerWrapper<T>::const_iterator RandomAccessContainerWrapper<T>::cend() const |
| |
167 |
207 |
{ |
| |
168 |
208 |
return const_iterator(m_vItems.cend()); |
| |
169 |
209 |
} |
| |
170 |
210 |
|
| |
171 |
|
template<class T> |
| |
172 |
|
bool RandomAccessContainerWrapper<T>::operator==(const RandomAccessContainerWrapper& rSrc) const |
| |
173 |
|
{ |
| |
174 |
|
if (rSrc.GetCount() != GetCount()) |
| |
175 |
|
return false; |
| |
176 |
|
|
| |
177 |
|
size_t stCount = GetCount(); |
| |
178 |
|
while (stCount-- > 0) |
| |
179 |
|
{ |
| |
180 |
|
if (m_vItems[stCount] != rSrc.m_vItems[stCount]) |
| |
181 |
|
return false; |
| |
182 |
|
} |
| |
183 |
|
|
| |
184 |
|
return true; |
| |
185 |
|
} |
| |
186 |
|
|
| |
187 |
|
template<class T> |
| |
188 |
|
bool RandomAccessContainerWrapper<T>::operator!=(const RandomAccessContainerWrapper& rSrc) const |
| |
189 |
|
{ |
| |
190 |
|
if (rSrc.GetCount() != GetCount()) |
| |
191 |
|
return true; |
| |
192 |
|
|
| |
193 |
|
size_t stCount = GetCount(); |
| |
194 |
|
while (stCount-- > 0) |
| |
195 |
|
{ |
| |
196 |
|
if (m_vItems[stCount] != rSrc.m_vItems[stCount]) |
| |
197 |
|
return true; |
| |
198 |
|
} |
| |
199 |
|
|
| |
200 |
|
return false; |
| |
201 |
|
} |
| |
202 |
|
|
| |
203 |
211 |
#endif |