ArrayImpl.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Vintela, Inc. All rights reserved.
00003 * Copyright (C) 2005 Novell, Inc. All rights reserved.
00004 *
00005 * Redistribution and use in source and binary forms, with or without
00006 * modification, are permitted provided that the following conditions are met:
00007 *
00008 *  - Redistributions of source code must retain the above copyright notice,
00009 *    this list of conditions and the following disclaimer.
00010 *
00011 *  - Redistributions in binary form must reproduce the above copyright notice,
00012 *    this list of conditions and the following disclaimer in the documentation
00013 *    and/or other materials provided with the distribution.
00014 *
00015 *  - Neither the name of Vintela, Inc., Novell, Inc., nor the names of its
00016 *    contributors may be used to endorse or promote products derived from this
00017 *    software without specific prior written permission.
00018 *
00019 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00020 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00021 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00022 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc., Novell, Inc., OR THE 
00023 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00024 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00025 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00026 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00027 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00028 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00029 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 *******************************************************************************/
00031 
00032 // This header file contains the implementation of the Array template class.
00033 // It is not intended to be used directly by users of the blocxx library.
00034 
00035 
00041 #ifndef BLOCXX_ARRAY_IMPL_HPP_INCLUDE_GUARD_
00042 #define BLOCXX_ARRAY_IMPL_HPP_INCLUDE_GUARD_
00043 #include "blocxx/BLOCXX_config.h"
00044 #include "blocxx/Array.hpp"
00045 
00046 namespace BLOCXX_NAMESPACE
00047 {
00048 
00050 template <typename T>
00051 inline Array<T>::Array() 
00052 : m_impl(new V) 
00053 {
00054 }
00056 template <typename T>
00057 inline Array<T>::~Array() 
00058 {
00059 }
00061 template <typename T>
00062 inline Array<T>::Array(V* toWrap) 
00063 : m_impl(toWrap) 
00064 {
00065 }
00067 template <typename T>
00068 inline Array<T>::Array(size_type n, const T& value) 
00069 : m_impl(new V(n, value)) 
00070 {
00071 }
00073 template <typename T>
00074 inline Array<T>::Array(int n, const T& value) 
00075 : m_impl(new V(n, value)) 
00076 {
00077 }
00079 template <typename T>
00080 inline Array<T>::Array(long n, const T& value) 
00081 : m_impl(new V(n, value)) 
00082 {
00083 }
00085 template <typename T>
00086 inline Array<T>::Array(size_type n) 
00087 : m_impl(new V(n)) 
00088 {
00089 }
00091 template <typename T>
00092 template<class InputIterator>
00093 inline Array<T>::Array(InputIterator first, InputIterator last) 
00094 : m_impl(new V(first, last)) 
00095 {
00096 }
00098 template <typename T>
00099 inline typename Array<T>::iterator
00100 Array<T>::begin()
00101 { 
00102    return m_impl->begin(); 
00103 }
00105 template <typename T>
00106 inline typename Array<T>::const_iterator
00107 Array<T>::begin() const 
00108 { 
00109    return m_impl->begin(); 
00110 }
00112 template <typename T>
00113 inline typename Array<T>::iterator
00114 Array<T>::end()
00115 { 
00116    return m_impl->end(); 
00117 }
00119 template <typename T>
00120 inline typename Array<T>::const_iterator
00121 Array<T>::end() const 
00122 { 
00123    return m_impl->end(); 
00124 }
00126 template <typename T>
00127 inline typename Array<T>::reverse_iterator
00128 Array<T>::rbegin()
00129 { 
00130    return m_impl->rbegin(); 
00131 }
00133 template <typename T>
00134 inline typename Array<T>::const_reverse_iterator
00135 Array<T>::rbegin() const 
00136 { 
00137    return m_impl->rbegin(); 
00138 }
00140 template <typename T>
00141 inline typename Array<T>::reverse_iterator
00142 Array<T>::rend()
00143 { 
00144    return m_impl->rend(); 
00145 }
00147 template <typename T>
00148 inline typename Array<T>::const_reverse_iterator
00149 Array<T>::rend() const 
00150 { 
00151    return m_impl->rend(); 
00152 }
00154 template <typename T>
00155 inline typename Array<T>::size_type
00156 Array<T>::size() const 
00157 { 
00158    return m_impl->size(); 
00159 }
00161 template <typename T>
00162 inline typename Array<T>::size_type
00163 Array<T>::max_size() const 
00164 { 
00165    return m_impl->max_size(); 
00166 }
00168 template <typename T>
00169 inline typename Array<T>::size_type
00170 Array<T>::capacity() const 
00171 { 
00172    return m_impl->capacity(); 
00173 }
00175 template <typename T>
00176 inline bool
00177 Array<T>::empty() const 
00178 { 
00179    return m_impl->empty(); 
00180 }
00182 template <typename T>
00183 inline typename Array<T>::reference
00184 Array<T>::operator[](size_type n)
00185 {
00186 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00187    checkValidIndex(n);
00188 #endif
00189    return m_impl->operator[](n);
00190 }
00192 template <typename T>
00193 inline typename Array<T>::const_reference
00194 Array<T>::operator[](size_type n) const
00195 {
00196 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00197    checkValidIndex(n);
00198 #endif
00199    return m_impl->operator[](n);
00200 }
00202 template <typename T>
00203 inline Array<T>&
00204 Array<T>::operator+= (const T& x)
00205 {
00206    m_impl->push_back(x);
00207    return *this;
00208 }
00210 template <typename T>
00211 inline void
00212 Array<T>::reserve(size_type n) 
00213 { 
00214    m_impl->reserve(n); 
00215 }
00217 template <typename T>
00218 inline typename Array<T>::reference
00219 Array<T>::front() 
00220 { 
00221    return m_impl->front(); 
00222 }
00224 template <typename T>
00225 inline typename Array<T>::const_reference
00226 Array<T>::front() const 
00227 { 
00228    return m_impl->front(); 
00229 }
00231 template <typename T>
00232 inline typename Array<T>::reference
00233 Array<T>::back() 
00234 { 
00235    return m_impl->back(); 
00236 }
00238 template <typename T>
00239 inline typename Array<T>::const_reference
00240 Array<T>::back() const 
00241 { 
00242    return m_impl->back(); 
00243 }
00245 template <typename T>
00246 inline void
00247 Array<T>::push_back(const T& x) 
00248 { 
00249    m_impl->push_back(x); 
00250 }
00252 template <typename T>
00253 inline void
00254 Array<T>::append(const T& x) 
00255 { 
00256    push_back(x); 
00257 }
00259 template <typename T>
00260 inline void
00261 Array<T>::swap(Array<T>& x) 
00262 { 
00263    m_impl.swap(x.m_impl); 
00264 }
00266 template <typename T>
00267 inline typename Array<T>::iterator
00268 Array<T>::insert(iterator position, const T& x)
00269 { 
00270    return m_impl->insert(position, x); 
00271 }
00273 template <typename T>
00274 inline void
00275 Array<T>::insert(size_type position, const T& x)
00276 { 
00277    m_impl->insert(m_impl->begin() + position, x); 
00278 }
00280 template <typename T>
00281 inline void
00282 Array<T>::remove(size_type index)
00283 {
00284 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00285    checkValidIndex(index);
00286 #endif
00287    m_impl->erase(m_impl->begin() + index);
00288 }
00290 template <typename T>
00291 inline void
00292 Array<T>::remove(size_type begin, size_type end)
00293 {
00294 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00295    checkValidIndex(begin);
00296    checkValidIndex(end - 1);
00297 #endif
00298    m_impl->erase(m_impl->begin() + begin, m_impl->begin() + end);
00299 }
00301 template <typename T>
00302 template<class InputIterator>
00303 inline void
00304 Array<T>::insert(iterator position, InputIterator first, InputIterator last)
00305 {
00306    m_impl->insert(position, first, last);
00307 }
00309 template <typename T>
00310 inline void
00311 Array<T>::appendArray(const Array<T>& x)
00312 {
00313    insert(end(), x.begin(), x.end());
00314 }
00316 template <typename T>
00317 inline void
00318 Array<T>::pop_back() 
00319 { 
00320    m_impl->pop_back(); 
00321 }
00323 template <typename T>
00324 inline typename Array<T>::iterator
00325 Array<T>::erase(iterator position) 
00326 { 
00327    return m_impl->erase(position); 
00328 }
00330 template <typename T>
00331 inline typename Array<T>::iterator
00332 Array<T>::erase(iterator first, iterator last) 
00333 { 
00334    return m_impl->erase(first, last); 
00335 }
00337 template <typename T>
00338 inline void
00339 Array<T>::resize(size_type new_size, const T& x) 
00340 { 
00341    m_impl->resize(new_size, x); 
00342 }
00344 template <typename T>
00345 inline void
00346 Array<T>::resize(size_type new_size) 
00347 { 
00348    m_impl->resize(new_size); 
00349 }
00351 template <typename T>
00352 inline void
00353 Array<T>::clear() 
00354 { 
00355    m_impl->clear(); 
00356 }
00358 template <typename T>
00359 inline typename Array<T>::const_iterator
00360 Array<T>::find(const T &x, const_iterator first, const_iterator last) const
00361 {
00362    for( ; first != end(); ++first)
00363    {
00364       if( x == *first)
00365          return first;
00366       if(first == last)
00367          break;
00368    }
00369    return end();
00370 }
00372 template <typename T>
00373 inline typename Array<T>::const_iterator
00374 Array<T>::find(const T &x) const
00375 {
00376    return find(x, begin(), end());
00377 }
00379 template <typename T>
00380 inline typename Array<T>::iterator
00381 Array<T>::find(const T &x, iterator first, iterator last)
00382 {
00383    for( ; first != end(); ++first)
00384    {
00385       if( x == *first)
00386          return first;
00387       if(first == last)
00388          break;
00389    }
00390    return end();
00391 }
00393 template <typename T>
00394 inline typename Array<T>::iterator
00395 Array<T>::find(const T &x)
00396 {
00397    return find(x, begin(), end());
00398 }
00400 template <typename T>
00401 inline bool
00402 Array<T>::contains(const T& x, const_iterator first, const_iterator last) const
00403 {
00404    return find(x, first, last) != end();
00405 }
00407 template <typename T>
00408 inline bool 
00409 Array<T>::contains(const T& x) const
00410 {
00411    return find(x, begin(), end()) != end();
00412 }
00413 
00414 #ifdef BLOCXX_CHECK_ARRAY_INDEXING
00415 
00416 BLOCXX_COMMON_API void throwArrayOutOfBoundsException(size_t size, size_t idx);
00417 
00419 template <typename T>
00420 inline void
00421 Array<T>::checkValidIndex(size_type index) const
00422 {
00423    if (index >= size())
00424    {
00425       throwArrayOutOfBoundsException(size(), index);
00426    }
00427 }
00428 #endif
00429 template<class T>
00430 inline bool operator==(const Array<T>& x, const Array<T>& y)
00431 {
00432    return *x.m_impl == *y.m_impl;
00433 }
00434 template<class T>
00435 inline bool operator<(const Array<T>& x, const Array<T>& y)
00436 {
00437    return *x.m_impl < *y.m_impl;
00438 }
00439 template<class T>
00440 inline void swap(Array<T>& x, Array<T>& y)
00441 {
00442    x.swap(y);
00443 }
00444 
00445 } // end namespace BLOCXX_NAMESPACE
00446 
00447 #endif
00448    

Generated on Fri Jun 16 15:39:08 2006 for blocxx by  doxygen 1.4.6