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
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_VECTOR_H
00051 #define LASS_GUARDIAN_OF_INCLUSION_NUM_VECTOR_H
00052
00053 #include "num_common.h"
00054 #include "num_traits.h"
00055 #include "../meta/bool.h"
00056 #include "../meta/wrap.h"
00057 #include "../util/call_traits.h"
00058 #include "impl/vector_expressions.h"
00059
00060 namespace lass
00061 {
00062 namespace num
00063 {
00064
00065 template
00066 <
00067 typename T,
00068 typename S = impl::VStorage<T>
00069 >
00070 class Vector
00071 {
00072 public:
00073
00074 typedef Vector<T, S> TSelf;
00075 typedef S TStorage;
00076
00077 typedef typename util::CallTraits<T>::TValue TValue;
00078 typedef typename util::CallTraits<T>::TParam TParam;
00079 typedef typename util::CallTraits<T>::TReference TReference;
00080 typedef typename util::CallTraits<T>::TConstReference TConstReference;
00081 typedef num::NumTraits<T> TNumTraits;
00082 typedef size_t TSize;
00083
00084 template <typename U> struct Rebind
00085 {
00086 typedef Vector<U, S> Type;
00087 };
00088
00089 Vector();
00090 explicit Vector(TSize iDimension, TParam iInitialValue = TNumTraits::zero);
00091 explicit Vector(const TStorage& iStorage);
00092 template <typename VectorType> explicit Vector(const VectorType& iVector);
00093 template <typename T2, typename S2> Vector(const Vector<T2, S2>& iOther);
00094
00095 template <typename T2, typename S2> Vector<T, S>& operator=(const Vector<T2, S2>& iOther);
00096
00097 const TSize size() const;
00098
00099 const TValue operator[](TSize iIndex) const;
00100 TReference operator[](TSize iIndex);
00101 const TValue at(TSize iIndex) const;
00102 TReference at(TSize iIndex);
00103
00104 const Vector<T, S>& operator+() const;
00105 const Vector<T, impl::VNeg<T, S> > operator-() const;
00106 template <typename T2, typename S2> Vector<T, S>& operator+=(const Vector<T2, S2>& iB);
00107 template <typename T2, typename S2> Vector<T, S>& operator-=(const Vector<T2, S2>& iB);
00108 template <typename T2, typename S2> Vector<T, S>& operator*=(const Vector<T2, S2>& iB);
00109 template <typename T2, typename S2> Vector<T, S>& operator/=(const Vector<T2, S2>& iB);
00110 template <typename T2> Vector<T, S>& operator+=(const T2& iB);
00111 template <typename T2> Vector<T, S>& operator-=(const T2& iB);
00112 template <typename T2> Vector<T, S>& operator*=(const T2& iB);
00113 template <typename T2> Vector<T, S>& operator/=(const T2& iB);
00114
00115 const bool isEmpty() const;
00116 const bool isZero() const;
00117 const TValue sum() const;
00118 const TValue min() const;
00119 const TValue max() const;
00120 const TValue squaredNorm() const;
00121 const TValue norm() const;
00122 const Vector<T, impl::VMul<T, S, impl::VScalar<T> > > normal() const;
00123 const Vector<T, impl::VRec<T, S> > reciprocal() const;
00124
00125 template <typename S2> const Vector<T, impl::VMul<T, S, impl::VScalar<T> > >
00126 project(const Vector<T, S2>& iB) const;
00127 template <typename S2> const Vector<T, impl::VSub<T, S2, impl::VMul<T, S, impl::VScalar<T> > > >
00128 reject(const Vector<T, S2>& iB) const;
00129
00130 const Vector<T, impl::VFun<T, S> > transform(T (*iOperator)(T));
00131
00132 void normalize();
00133
00134 const TStorage& storage() const;
00135 TStorage& storage();
00136 void swap(Vector<T, S>& iOther);
00137
00138 private:
00139
00140 template <typename T2, typename S2> friend class Vector;
00141
00142 template <typename IntegralType> void init(IntegralType iDimension, meta::Wrap<meta::True>);
00143 template <typename VectorType> void init(const VectorType& iVector, meta::Wrap<meta::False>);
00144
00145 TStorage storage_;
00146 };
00147
00148 template <typename T, typename S1, typename S2>
00149 bool operator==(const Vector<T>& iA, const Vector<T>& iB);
00150 template <typename T, typename S1, typename S2>
00151 inline bool operator!=(const Vector<T>& iA, const Vector<T>& iB);
00152
00153 template <typename T, typename S1, typename S2>
00154 const T dot(const Vector<T, S1>& iA, const Vector<T, S2>& iB);
00155
00156 template <typename T, typename S1, typename S2>
00157 const Vector<T, impl::VAdd<T, S1, S2> > operator+(const Vector<T, S1>& iA, const Vector<T, S2>& iB);
00158 template <typename T, typename S1, typename S2>
00159 const Vector<T, impl::VSub<T, S1, S2> > operator-(const Vector<T, S1>& iA, const Vector<T, S2>& iB);
00160 template <typename T, typename S1, typename S2>
00161 const Vector<T, impl::VMul<T, S1, S2> > operator*(const Vector<T, S1>& iA, const Vector<T, S2>& iB);
00162 template <typename T, typename S1, typename S2>
00163 const Vector<T, impl::VDiv<T, S1, S2> > operator/(const Vector<T, S1>& iA, const Vector<T, S2>& iB);
00164
00165 template <typename T, typename S>
00166 const Vector<T, impl::VAdd<T, impl::VScalar<T>, S> > operator+(const T& iA, const Vector<T, S>& iB);
00167 template <typename T, typename S>
00168 const Vector<T, impl::VSub<T, impl::VScalar<T>, S> > operator-(const T& iA, const Vector<T, S>& iB);
00169 template <typename T, typename S>
00170 const Vector<T, impl::VMul<T, impl::VScalar<T>, S> > operator*(const T& iA, const Vector<T, S>& iB);
00171 template <typename T, typename S>
00172 const Vector<T, impl::VDiv<T, impl::VScalar<T>, S> > operator/(const T& iA, const Vector<T, S>& iB);
00173
00174 template <typename T, typename S>
00175 const Vector<T, impl::VAdd<T, S, impl::VScalar<T> > > operator+(const Vector<T, S>& iA, const T& iB);
00176 template <typename T, typename S>
00177 const Vector<T, impl::VSub<T, S, impl::VScalar<T> > > operator-(const Vector<T, S>& iA, const T& iB);
00178 template <typename T, typename S>
00179 const Vector<T, impl::VMul<T, S, impl::VScalar<T> > > operator*(const Vector<T, S>& iA, const T& iB);
00180 template <typename T, typename S>
00181 const Vector<T, impl::VDiv<T, S, impl::VScalar<T> > > operator/(const Vector<T, S>& iA, const T& iB);
00182
00183
00184 template <typename T, typename S, typename Char, typename Traits>
00185 std::basic_ostream<Char, Traits>&
00186 operator<<(std::basic_ostream<Char, Traits>& iS, const Vector<T, S>& iA);
00187
00188 template <typename T, typename S, typename Char, typename Traits>
00189 std::basic_istream<Char, Traits>&
00190 operator>>(std::basic_istream<Char, Traits>& iS, Vector<T>& iB);
00191
00192 }
00193
00194 }
00195
00196 #include "vector.inl"
00197
00198 #ifdef LASS_GUARDIAN_OF_INCLUSION_NUM_MATRIX_H
00199 #include "matrix_vector.h"
00200 #endif
00201
00202 #endif
00203
00204