Merge of itasc branch. Project files, scons and cmake should be working. Makefile...
[blender.git] / extern / Eigen2 / Eigen / StdVector
1 #ifdef EIGEN_USE_NEW_STDVECTOR
2 #include "NewStdVector"
3 #else
4
5 #ifndef EIGEN_STDVECTOR_MODULE_H
6 #define EIGEN_STDVECTOR_MODULE_H
7
8 #if defined(_GLIBCXX_VECTOR) || defined(_VECTOR_)
9 #error you must include <Eigen/StdVector> before <vector>. Also note that <Eigen/Sparse> includes <vector>, so it must be included after <Eigen/StdVector> too.
10 #endif                                                    
11
12 #ifndef EIGEN_GNUC_AT_LEAST
13 #ifdef __GNUC__
14   #define EIGEN_GNUC_AT_LEAST(x,y) ((__GNUC__>=x && __GNUC_MINOR__>=y) || __GNUC__>x)
15 #else
16   #define EIGEN_GNUC_AT_LEAST(x,y) 0
17 #endif
18 #endif
19
20 #define vector std_vector
21 #include <vector>        
22 #undef vector
23
24 namespace Eigen {
25
26 template<typename T> class aligned_allocator;
27
28 // meta programming to determine if a class has a given member
29 struct ei_does_not_have_aligned_operator_new_marker_sizeof {int a[1];};
30 struct ei_has_aligned_operator_new_marker_sizeof {int a[2];};
31
32 template<typename ClassType>
33 struct ei_has_aligned_operator_new {
34     template<typename T>
35     static ei_has_aligned_operator_new_marker_sizeof
36     test(T const *, typename T::ei_operator_new_marker_type const * = 0);
37     static ei_does_not_have_aligned_operator_new_marker_sizeof
38     test(...);
39
40     // note that the following indirection is needed for gcc-3.3
41     enum {ret =  sizeof(test(static_cast<ClassType*>(0))) 
42               == sizeof(ei_has_aligned_operator_new_marker_sizeof) };
43 };
44
45 #ifdef _MSC_VER
46   
47   // sometimes, MSVC detects, at compile time, that the argument x
48   // in std::vector::resize(size_t s,T x) won't be aligned and generate an error
49   // even if this function is never called. Whence this little wrapper.
50   #define _EIGEN_WORKAROUND_MSVC_STD_VECTOR(T) Eigen::ei_workaround_msvc_std_vector<T>
51   template<typename T> struct ei_workaround_msvc_std_vector : public T
52   {
53     inline ei_workaround_msvc_std_vector() : T() {}
54     inline ei_workaround_msvc_std_vector(const T& other) : T(other) {}
55     inline operator T& () { return *static_cast<T*>(this); }
56     inline operator const T& () const { return *static_cast<const T*>(this); }
57     template<typename OtherT>
58     inline T& operator=(const OtherT& other)
59     { T::operator=(other); return *this; }
60     inline ei_workaround_msvc_std_vector& operator=(const ei_workaround_msvc_std_vector& other)
61     { T::operator=(other); return *this; }
62   };
63
64 #else
65
66   #define _EIGEN_WORKAROUND_MSVC_STD_VECTOR(T) T
67
68 #endif
69
70 }
71
72 namespace std {
73
74 #define EIGEN_STD_VECTOR_SPECIALIZATION_BODY \
75   public:  \
76     typedef T value_type; \
77     typedef typename vector_base::allocator_type allocator_type; \
78     typedef typename vector_base::size_type size_type;  \
79     typedef typename vector_base::iterator iterator;  \
80     explicit vector(const allocator_type& __a = allocator_type()) : vector_base(__a) {}  \
81     vector(const vector& c) : vector_base(c) {}  \
82     vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {} \
83     vector(iterator start, iterator end) : vector_base(start, end) {}  \
84     vector& operator=(const vector& __x) {  \
85       vector_base::operator=(__x);  \
86       return *this;  \
87     }
88
89 template<typename T,
90          typename AllocT = std::allocator<T>,
91          bool HasAlignedNew = Eigen::ei_has_aligned_operator_new<T>::ret>
92 class vector : public std::std_vector<T,AllocT>
93 {
94   typedef std_vector<T, AllocT> vector_base;
95   EIGEN_STD_VECTOR_SPECIALIZATION_BODY
96 };
97
98 template<typename T,typename DummyAlloc>
99 class vector<T,DummyAlloc,true>
100   : public std::std_vector<_EIGEN_WORKAROUND_MSVC_STD_VECTOR(T),
101                            Eigen::aligned_allocator<_EIGEN_WORKAROUND_MSVC_STD_VECTOR(T)> >          
102 {
103   typedef std_vector<_EIGEN_WORKAROUND_MSVC_STD_VECTOR(T),
104                      Eigen::aligned_allocator<_EIGEN_WORKAROUND_MSVC_STD_VECTOR(T)> > vector_base;
105   EIGEN_STD_VECTOR_SPECIALIZATION_BODY
106
107   void resize(size_type __new_size)
108   { resize(__new_size, T()); }     
109
110   #if defined(_VECTOR_)
111   // workaround MSVC std::vector implementation
112   void resize(size_type __new_size, const value_type& __x)                 
113   {                                                              
114     if (vector_base::size() < __new_size)                                 
115       vector_base::_Insert_n(vector_base::end(), __new_size - vector_base::size(), __x);
116     else if (__new_size < vector_base::size())
117       vector_base::erase(vector_base::begin() + __new_size, vector_base::end());
118   }
119   #elif defined(_GLIBCXX_VECTOR) && EIGEN_GNUC_AT_LEAST(4,2)
120   // workaround GCC std::vector implementation
121   void resize(size_type __new_size, const value_type& __x)
122   {                                              
123     if (__new_size < vector_base::size())               
124       vector_base::_M_erase_at_end(this->_M_impl._M_start + __new_size);
125     else                       
126       vector_base::insert(vector_base::end(), __new_size - vector_base::size(), __x); 
127   }                                                              
128   #elif defined(_GLIBCXX_VECTOR) && EIGEN_GNUC_AT_LEAST(4,1)
129   void resize(size_type __new_size, const value_type& __x)
130   {
131     if (__new_size < vector_base::size())
132       vector_base::erase(vector_base::begin() + __new_size, vector_base::end());
133     else
134       vector_base::insert(vector_base::end(), __new_size - vector_base::size(), __x);
135   }
136   #else
137   // Before gcc-4.1 we already have: std::vector::resize(size_type,const T&),
138   // so no need for a workaround !
139   using vector_base::resize;
140   #endif  
141 };
142
143 }
144
145 #endif // EIGEN_STDVECTOR_MODULE_H
146
147 #endif // EIGEN_USE_NEW_STDVECTOR