library of assembled shared sources

http://lass.cocamware.com

vector.h

Go to the documentation of this file.
00001 /** @file
00002  *  @author Bram de Greve (bramz@users.sourceforge.net)
00003  *  @author Tom De Muer (tomdemuer@users.sourceforge.net)
00004  *
00005  *  *** BEGIN LICENSE INFORMATION ***
00006  *  
00007  *  The contents of this file are subject to the Common Public Attribution License 
00008  *  Version 1.0 (the "License"); you may not use this file except in compliance with 
00009  *  the License. You may obtain a copy of the License at 
00010  *  http://lass.sourceforge.net/cpal-license. The License is based on the 
00011  *  Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover 
00012  *  use of software over a computer network and provide for limited attribution for 
00013  *  the Original Developer. In addition, Exhibit A has been modified to be consistent 
00014  *  with Exhibit B.
00015  *  
00016  *  Software distributed under the License is distributed on an "AS IS" basis, WITHOUT 
00017  *  WARRANTY OF ANY KIND, either express or implied. See the License for the specific 
00018  *  language governing rights and limitations under the License.
00019  *  
00020  *  The Original Code is LASS - Library of Assembled Shared Sources.
00021  *  
00022  *  The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
00023  *  The Original Developer is the Initial Developer.
00024  *  
00025  *  All portions of the code written by the Initial Developer are:
00026  *  Copyright (C) 2004-2007 the Initial Developer.
00027  *  All Rights Reserved.
00028  *  
00029  *  Contributor(s):
00030  *
00031  *  Alternatively, the contents of this file may be used under the terms of the 
00032  *  GNU General Public License Version 2 or later (the GPL), in which case the 
00033  *  provisions of GPL are applicable instead of those above.  If you wish to allow use
00034  *  of your version of this file only under the terms of the GPL and not to allow 
00035  *  others to use your version of this file under the CPAL, indicate your decision by 
00036  *  deleting the provisions above and replace them with the notice and other 
00037  *  provisions required by the GPL License. If you do not delete the provisions above,
00038  *  a recipient may use your version of this file under either the CPAL or the GPL.
00039  *  
00040  *  *** END LICENSE INFORMATION ***
00041  */
00042 
00043 
00044 
00045 /** @class lass::num::Vector
00046  *  @brief a dynamic sized n-dimensional vector with vector expression templates
00047  *  @author Bram de Greve [BdG]
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 // EOF

Generated on Mon Nov 10 14:22:02 2008 for Library of Assembled Shared Sources by doxygen 1.5.7.1
SourceForge.net Logo