$treeview $search $mathjax
Eigen
3.2.5
$projectbrief
|
$projectbrief
|
$searchbox |
00001 // This file is part of Eigen, a lightweight C++ template library 00002 // for linear algebra. 00003 // 00004 // Copyright (C) 2009 Gael Guennebaud <gael.guennebaud@inria.fr> 00005 // Copyright (C) 2009 Hauke Heibel <hauke.heibel@googlemail.com> 00006 // 00007 // This Source Code Form is subject to the terms of the Mozilla 00008 // Public License v. 2.0. If a copy of the MPL was not distributed 00009 // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. 00010 00011 #ifndef EIGEN_STDVECTOR_H 00012 #define EIGEN_STDVECTOR_H 00013 00014 #include "details.h" 00015 00021 #define EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(...) \ 00022 namespace std \ 00023 { \ 00024 template<> \ 00025 class vector<__VA_ARGS__, std::allocator<__VA_ARGS__> > \ 00026 : public vector<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > \ 00027 { \ 00028 typedef vector<__VA_ARGS__, EIGEN_ALIGNED_ALLOCATOR<__VA_ARGS__> > vector_base; \ 00029 public: \ 00030 typedef __VA_ARGS__ value_type; \ 00031 typedef vector_base::allocator_type allocator_type; \ 00032 typedef vector_base::size_type size_type; \ 00033 typedef vector_base::iterator iterator; \ 00034 explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {} \ 00035 template<typename InputIterator> \ 00036 vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : vector_base(first, last, a) {} \ 00037 vector(const vector& c) : vector_base(c) {} \ 00038 explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {} \ 00039 vector(iterator start, iterator end) : vector_base(start, end) {} \ 00040 vector& operator=(const vector& x) { \ 00041 vector_base::operator=(x); \ 00042 return *this; \ 00043 } \ 00044 }; \ 00045 } 00046 00047 namespace std { 00048 00049 #define EIGEN_STD_VECTOR_SPECIALIZATION_BODY \ 00050 public: \ 00051 typedef T value_type; \ 00052 typedef typename vector_base::allocator_type allocator_type; \ 00053 typedef typename vector_base::size_type size_type; \ 00054 typedef typename vector_base::iterator iterator; \ 00055 typedef typename vector_base::const_iterator const_iterator; \ 00056 explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {} \ 00057 template<typename InputIterator> \ 00058 vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) \ 00059 : vector_base(first, last, a) {} \ 00060 vector(const vector& c) : vector_base(c) {} \ 00061 explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {} \ 00062 vector(iterator start, iterator end) : vector_base(start, end) {} \ 00063 vector& operator=(const vector& x) { \ 00064 vector_base::operator=(x); \ 00065 return *this; \ 00066 } 00067 00068 template<typename T> 00069 class vector<T,EIGEN_ALIGNED_ALLOCATOR<T> > 00070 : public vector<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T), 00071 Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > 00072 { 00073 typedef vector<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T), 00074 Eigen::aligned_allocator_indirection<EIGEN_WORKAROUND_MSVC_STL_SUPPORT(T)> > vector_base; 00075 EIGEN_STD_VECTOR_SPECIALIZATION_BODY 00076 00077 void resize(size_type new_size) 00078 { resize(new_size, T()); } 00079 00080 #if defined(_VECTOR_) 00081 // workaround MSVC std::vector implementation 00082 void resize(size_type new_size, const value_type& x) 00083 { 00084 if (vector_base::size() < new_size) 00085 vector_base::_Insert_n(vector_base::end(), new_size - vector_base::size(), x); 00086 else if (new_size < vector_base::size()) 00087 vector_base::erase(vector_base::begin() + new_size, vector_base::end()); 00088 } 00089 void push_back(const value_type& x) 00090 { vector_base::push_back(x); } 00091 using vector_base::insert; 00092 iterator insert(const_iterator position, const value_type& x) 00093 { return vector_base::insert(position,x); } 00094 void insert(const_iterator position, size_type new_size, const value_type& x) 00095 { vector_base::insert(position, new_size, x); } 00096 #elif defined(_GLIBCXX_VECTOR) && (!(EIGEN_GNUC_AT_LEAST(4,1))) 00097 /* Note that before gcc-4.1 we already have: std::vector::resize(size_type,const T&). 00098 * However, this specialization is still needed to make the above EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION trick to work. */ 00099 void resize(size_type new_size, const value_type& x) 00100 { 00101 vector_base::resize(new_size,x); 00102 } 00103 #elif defined(_GLIBCXX_VECTOR) && EIGEN_GNUC_AT_LEAST(4,2) 00104 // workaround GCC std::vector implementation 00105 void resize(size_type new_size, const value_type& x) 00106 { 00107 if (new_size < vector_base::size()) 00108 vector_base::_M_erase_at_end(this->_M_impl._M_start + new_size); 00109 else 00110 vector_base::insert(vector_base::end(), new_size - vector_base::size(), x); 00111 } 00112 #else 00113 // either GCC 4.1 or non-GCC 00114 // default implementation which should always work. 00115 void resize(size_type new_size, const value_type& x) 00116 { 00117 if (new_size < vector_base::size()) 00118 vector_base::erase(vector_base::begin() + new_size, vector_base::end()); 00119 else if (new_size > vector_base::size()) 00120 vector_base::insert(vector_base::end(), new_size - vector_base::size(), x); 00121 } 00122 #endif 00123 }; 00124 } 00125 00126 #endif // EIGEN_STDVECTOR_H