00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00045 #ifndef BLOCXX_ARRAY_IMPL_HPP_INCLUDE_GUARD_
00046 #define BLOCXX_ARRAY_IMPL_HPP_INCLUDE_GUARD_
00047 #include "blocxx/BLOCXX_config.h"
00048 #include "blocxx/Array.hpp"
00049
00050 namespace BLOCXX_NAMESPACE
00051 {
00052
00054 template <typename T>
00055 inline Array<T>::Array()
00056 : m_impl(new V)
00057 {
00058 }
00060 template <typename T>
00061 inline Array<T>::~Array()
00062 {
00063 }
00065 template <typename T>
00066 inline Array<T>::Array(V* toWrap)
00067 : m_impl(toWrap)
00068 {
00069 }
00071 template <typename T>
00072 inline Array<T>::Array(size_type n, const T& value)
00073 : m_impl(new V(n, value))
00074 {
00075 }
00077 template <typename T>
00078 inline Array<T>::Array(int n, const T& value)
00079 : m_impl(new V(n, value))
00080 {
00081 }
00083 template <typename T>
00084 inline Array<T>::Array(long n, const T& value)
00085 : m_impl(new V(n, value))
00086 {
00087 }
00089 template <typename T>
00090 inline Array<T>::Array(size_type n)
00091 : m_impl(new V(n))
00092 {
00093 }
00095 template <typename T>
00096 template<class InputIterator>
00097 inline Array<T>::Array(InputIterator first, InputIterator last)
00098 : m_impl(new V(first, last))
00099 {
00100 }
00102 template <typename T>
00103 inline typename Array<T>::iterator
00104 Array<T>::begin()
00105 {
00106 return m_impl->begin();
00107 }
00109 template <typename T>
00110 inline typename Array<T>::const_iterator
00111 Array<T>::begin() const
00112 {
00113 return m_impl->begin();
00114 }
00116 template <typename T>
00117 inline typename Array<T>::iterator
00118 Array<T>::end()
00119 {
00120 return m_impl->end();
00121 }
00123 template <typename T>
00124 inline typename Array<T>::const_iterator
00125 Array<T>::end() const
00126 {
00127 return m_impl->end();
00128 }
00130 template <typename T>
00131 inline typename Array<T>::reverse_iterator
00132 Array<T>::rbegin()
00133 {
00134 return m_impl->rbegin();
00135 }
00137 template <typename T>
00138 inline typename Array<T>::const_reverse_iterator
00139 Array<T>::rbegin() const
00140 {
00141 return m_impl->rbegin();
00142 }
00144 template <typename T>
00145 inline typename Array<T>::reverse_iterator
00146 Array<T>::rend()
00147 {
00148 return m_impl->rend();
00149 }
00151 template <typename T>
00152 inline typename Array<T>::const_reverse_iterator
00153 Array<T>::rend() const
00154 {
00155 return m_impl->rend();
00156 }
00158 template <typename T>
00159 inline typename Array<T>::size_type
00160 Array<T>::size() const
00161 {
00162 return m_impl->size();
00163 }
00165 template <typename T>
00166 inline typename Array<T>::size_type
00167 Array<T>::max_size() const
00168 {
00169 return m_impl->max_size();
00170 }
00172 template <typename T>
00173 inline typename Array<T>::size_type
00174 Array<T>::capacity() const
00175 {
00176 return m_impl->capacity();
00177 }
00179 template <typename T>
00180 inline bool
00181 Array<T>::empty() const
00182 {
00183 return m_impl->empty();
00184 }
00186 template <typename T>
00187 inline typename Array<T>::reference
00188 Array<T>::operator[](size_type n)
00189 {
00190 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00191 checkValidIndex(n);
00192 #endif
00193 return m_impl->operator[](n);
00194 }
00196 template <typename T>
00197 inline typename Array<T>::const_reference
00198 Array<T>::operator[](size_type n) const
00199 {
00200 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00201 checkValidIndex(n);
00202 #endif
00203 return m_impl->operator[](n);
00204 }
00206 template <typename T>
00207 inline Array<T>&
00208 Array<T>::operator+= (const T& x)
00209 {
00210 m_impl->push_back(x);
00211 return *this;
00212 }
00214 template <typename T>
00215 inline void
00216 Array<T>::reserve(size_type n)
00217 {
00218 m_impl->reserve(n);
00219 }
00221 template <typename T>
00222 inline typename Array<T>::reference
00223 Array<T>::front()
00224 {
00225 return m_impl->front();
00226 }
00228 template <typename T>
00229 inline typename Array<T>::const_reference
00230 Array<T>::front() const
00231 {
00232 return m_impl->front();
00233 }
00235 template <typename T>
00236 inline typename Array<T>::reference
00237 Array<T>::back()
00238 {
00239 return m_impl->back();
00240 }
00242 template <typename T>
00243 inline typename Array<T>::const_reference
00244 Array<T>::back() const
00245 {
00246 return m_impl->back();
00247 }
00249 template <typename T>
00250 inline void
00251 Array<T>::push_back(const T& x)
00252 {
00253 m_impl->push_back(x);
00254 }
00256 template <typename T>
00257 inline void
00258 Array<T>::append(const T& x)
00259 {
00260 push_back(x);
00261 }
00263 template <typename T>
00264 inline void
00265 Array<T>::swap(Array<T>& x)
00266 {
00267 m_impl.swap(x.m_impl);
00268 }
00270 template <typename T>
00271 inline typename Array<T>::iterator
00272 Array<T>::insert(iterator position, const T& x)
00273 {
00274 return m_impl->insert(position, x);
00275 }
00277 template <typename T>
00278 inline void
00279 Array<T>::insert(size_type position, const T& x)
00280 {
00281 m_impl->insert(m_impl->begin() + position, x);
00282 }
00284 template <typename T>
00285 inline void
00286 Array<T>::remove(size_type index)
00287 {
00288 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00289 checkValidIndex(index);
00290 #endif
00291 m_impl->erase(m_impl->begin() + index);
00292 }
00294 template <typename T>
00295 inline void
00296 Array<T>::remove(size_type begin, size_type end)
00297 {
00298 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00299 checkValidIndex(begin);
00300 checkValidIndex(end - 1);
00301 #endif
00302 m_impl->erase(m_impl->begin() + begin, m_impl->begin() + end);
00303 }
00305 template <typename T>
00306 template<class InputIterator>
00307 inline void
00308 Array<T>::insert(iterator position, InputIterator first, InputIterator last)
00309 {
00310 m_impl->insert(position, first, last);
00311 }
00313 template <typename T>
00314 inline void
00315 Array<T>::appendArray(const Array<T>& x)
00316 {
00317 insert(end(), x.begin(), x.end());
00318 }
00320 template <typename T>
00321 inline void
00322 Array<T>::pop_back()
00323 {
00324 m_impl->pop_back();
00325 }
00327 template <typename T>
00328 inline typename Array<T>::iterator
00329 Array<T>::erase(iterator position)
00330 {
00331 return m_impl->erase(position);
00332 }
00334 template <typename T>
00335 inline typename Array<T>::iterator
00336 Array<T>::erase(iterator first, iterator last)
00337 {
00338 return m_impl->erase(first, last);
00339 }
00341 template <typename T>
00342 inline void
00343 Array<T>::resize(size_type new_size, const T& x)
00344 {
00345 m_impl->resize(new_size, x);
00346 }
00348 template <typename T>
00349 inline void
00350 Array<T>::resize(size_type new_size)
00351 {
00352 m_impl->resize(new_size);
00353 }
00355 template <typename T>
00356 inline void
00357 Array<T>::clear()
00358 {
00359 m_impl->clear();
00360 }
00362 template <typename T>
00363 inline typename Array<T>::const_iterator
00364 Array<T>::find(const T &x, const_iterator first, const_iterator last) const
00365 {
00366 for( ; first != end(); ++first)
00367 {
00368 if( x == *first)
00369 return first;
00370 if(first == last)
00371 break;
00372 }
00373 return end();
00374 }
00376 template <typename T>
00377 inline typename Array<T>::const_iterator
00378 Array<T>::find(const T &x) const
00379 {
00380 return find(x, begin(), end());
00381 }
00383 template <typename T>
00384 inline typename Array<T>::iterator
00385 Array<T>::find(const T &x, iterator first, iterator last)
00386 {
00387 for( ; first != end(); ++first)
00388 {
00389 if( x == *first)
00390 return first;
00391 if(first == last)
00392 break;
00393 }
00394 return end();
00395 }
00397 template <typename T>
00398 inline typename Array<T>::iterator
00399 Array<T>::find(const T &x)
00400 {
00401 return find(x, begin(), end());
00402 }
00404 template <typename T>
00405 inline bool
00406 Array<T>::contains(const T& x, const_iterator first, const_iterator last) const
00407 {
00408 return find(x, first, last) != end();
00409 }
00411 template <typename T>
00412 inline bool
00413 Array<T>::contains(const T& x) const
00414 {
00415 return find(x, begin(), end()) != end();
00416 }
00417
00418 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00419
00420 BLOCXX_COMMON_API void throwArrayOutOfBoundsException(size_t size, size_t idx);
00421
00423 template <typename T>
00424 inline void
00425 Array<T>::checkValidIndex(size_type index) const
00426 {
00427 if (index >= size())
00428 {
00429 throwArrayOutOfBoundsException(size(), index);
00430 }
00431 }
00432 #endif
00433 template<class T>
00434 inline bool operator==(const Array<T>& x, const Array<T>& y)
00435 {
00436 return *x.m_impl == *y.m_impl;
00437 }
00438 template<class T>
00439 inline bool operator<(const Array<T>& x, const Array<T>& y)
00440 {
00441 return *x.m_impl < *y.m_impl;
00442 }
00443 template<class T>
00444 inline void swap(Array<T>& x, Array<T>& y)
00445 {
00446 x.swap(y);
00447 }
00448
00449 }
00450
00451 #endif
00452