fixed_vector.hpp

00001 #ifndef CORE_UBLAS_FIXEDVECTOR_H
00002 #define CORE_UBLAS_FIXEDVECTOR_H
00003 
00004 #include <boost/numeric/ublas/vector.hpp>
00005 #include <core/ublas/fixed_size_array.hpp>
00006 
00007 namespace boost { namespace numeric { namespace ublas {
00008 
00014     template<class T, std::size_t N>
00015     class fixed_vector:
00016         public vector<T, fixed_size_array<T, N> > {
00017 
00018         typedef vector<T, fixed_size_array<T, N> > vector_type;
00019     public:
00021         typedef typename vector_type::size_type size_type;
00022         static const size_type max_size = N;
00023         static const size_type dimension = N;
00024 
00025         // Construction and destruction
00026         BOOST_UBLAS_INLINE
00027         fixed_vector ():
00028             vector_type (N) {}
00029         /*BOOST_UBLAS_INLINE
00030         fixed_vector (size_type size):
00031             vector_type (N) {}*/
00032         BOOST_UBLAS_INLINE
00033         fixed_vector (const fixed_vector &v):
00034             vector_type (v) {}
00035         template<class A2>              // Allow vector<T,bounded_array<N> construction
00036         BOOST_UBLAS_INLINE
00037         fixed_vector (const vector<T, A2> &v):
00038             vector_type (v) {}
00039         template<class AE>
00040         BOOST_UBLAS_INLINE
00041         fixed_vector (const vector_expression<AE> &ae):
00042             vector_type (ae) {}
00043         BOOST_UBLAS_INLINE
00044         ~fixed_vector () {}
00045 
00046         // Assignment
00047         BOOST_UBLAS_INLINE
00048         fixed_vector &operator = (const fixed_vector &v) {
00049             vector_type::operator = (v);
00050             return *this;
00051         }
00052         template<class A2>         // Generic vector assignment
00053         BOOST_UBLAS_INLINE
00054         fixed_vector &operator = (const vector<T, A2> &v) {
00055             vector_type::operator = (v);
00056             return *this;
00057         }
00058         template<class C>          // Container assignment without temporary
00059         BOOST_UBLAS_INLINE
00060         fixed_vector &operator = (const vector_container<C> &v) {
00061             vector_type::operator = (v);
00062             return *this;
00063         }
00064         template<class AE>
00065         BOOST_UBLAS_INLINE
00066         fixed_vector &operator = (const vector_expression<AE> &ae) {
00067             vector_type::operator = (ae);
00068             return *this;
00069         }
00070         
00071         
00072         // componentwise initialization
00073     
00074         BOOST_UBLAS_INLINE
00075         explicit fixed_vector(const T & v)
00076         { 
00077           assign(v);
00078         }
00079         
00080         BOOST_UBLAS_INLINE
00081         explicit fixed_vector(const T & v0, const T & v1) 
00082         {
00083             assign(v0, v1);
00084         }
00085         
00086         BOOST_UBLAS_INLINE
00087         explicit fixed_vector(const T & v0, const T & v1, const T & v2) 
00088         {
00089             assign(v0, v1, v2);
00090         }
00091         
00092         BOOST_UBLAS_INLINE
00093         explicit fixed_vector(const T & v0, const T & v1, const T & v2, const T & v3) 
00094         {
00095             assign(v0, v1, v2, v3);
00096         }
00097           
00098         BOOST_UBLAS_INLINE
00099         explicit fixed_vector(const T & v0, const T & v1, const T & v2, const T & v3, const T & v4) 
00100         {
00101           assign(v0, v1, v2, v3, v4);
00102         }
00103         
00104         BOOST_UBLAS_INLINE
00105         explicit fixed_vector(const T & v0, const T & v1, const T & v2, const T & v3, const T & v4, const T & v5) 
00106         {
00107           assign(v0, v1, v2, v3, v4, v5);
00108         }
00109         
00110         BOOST_UBLAS_INLINE
00111         explicit fixed_vector(const T & v0, const T & v1, const T & v2, const T & v3, const T & v4, const T & v5, const T & v6) 
00112         {
00113           assign(v0, v1, v2, v3, v4, v5, v6);
00114         }
00115         
00116         BOOST_UBLAS_INLINE
00117         explicit fixed_vector(const T & v0, const T & v1, const T & v2, const T & v3, const T & v4, const T & v5, const T & v6, const T & v7) 
00118         {
00119           assign(v0, v1, v2, v3, v4, v5, v6, v7);
00120         }
00121         
00122         template<class DATA_t>
00123         BOOST_UBLAS_INLINE
00124         explicit fixed_vector (const fixed_vector<DATA_t, N> &v)
00125         {
00126             for(typename vector<T, fixed_size_array<T, N> >::iterator iter = vector<T, fixed_size_array<T, N> >::begin(); iter != vector<T, fixed_size_array<T, N> >::end(); ++iter)
00127                   *iter = T(v(iter.index()));
00128         }
00129         
00130         BOOST_UBLAS_INLINE
00131         void assign(const T & v) 
00132         {
00133             for(typename vector<T, fixed_size_array<T, N> >::iterator iter = vector<T, fixed_size_array<T, N> >::begin(); iter != vector<T, fixed_size_array<T, N> >::end(); ++iter)
00134                   *iter = v;
00135         }
00136 
00137         BOOST_UBLAS_INLINE
00138         void assign(const T & v0, const T & v1)
00139         {
00140             (*this)(0) = v0;
00141             (*this)(1) = v1;
00142         }
00143 
00144         BOOST_UBLAS_INLINE
00145         void assign(const T & v0, const T & v1, const T & v2) 
00146         {
00147             (*this)(0) = v0;
00148             (*this)(1) = v1;
00149             (*this)(2) = v2;
00150         }
00151 
00152         BOOST_UBLAS_INLINE
00153         void assign(const T & v0, const T & v1, const T & v2, const T & v3) 
00154         {
00155             (*this)(0) = v0;
00156             (*this)(1) = v1;
00157             (*this)(2) = v2;
00158             (*this)(3) = v3;
00159         }
00160           
00161         BOOST_UBLAS_INLINE
00162         void assign(const T & v0, const T & v1, const T & v2, const T & v3, const T & v4) 
00163         {
00164           (*this)(0) = v0;
00165           (*this)(1) = v1;
00166           (*this)(2) = v2;
00167           (*this)(3) = v3;
00168           (*this)(4) = v4;
00169         }
00170         
00171         BOOST_UBLAS_INLINE
00172         void assign(const T & v0, const T & v1, const T & v2, const T & v3, const T & v4, const T & v5) 
00173         {
00174           (*this)(0) = v0;
00175           (*this)(1) = v1;
00176           (*this)(2) = v2;
00177           (*this)(3) = v3;
00178           (*this)(4) = v4;
00179           (*this)(5) = v5;
00180         }
00181         
00182         BOOST_UBLAS_INLINE
00183         void assign(const T & v0, const T & v1, const T & v2, const T & v3, const T & v4, const T & v5, const T & v6) 
00184         {
00185           (*this)(0) = v0;
00186           (*this)(1) = v1;
00187           (*this)(2) = v2;
00188           (*this)(3) = v3;
00189           (*this)(4) = v4;
00190           (*this)(5) = v5;
00191           (*this)(6) = v6;
00192         }
00193         
00194         BOOST_UBLAS_INLINE
00195         void assign(const T & v0, const T & v1, const T & v2, const T & v3, const T & v4, const T & v5, const T & v6, const T & v7) 
00196         {
00197           (*this)(0) = v0;
00198           (*this)(1) = v1;
00199           (*this)(2) = v2;
00200           (*this)(3) = v3;
00201           (*this)(4) = v4;
00202           (*this)(5) = v5;
00203           (*this)(6) = v6;
00204           (*this)(7) = v7;
00205         }
00207     };
00208     
00209     // comparision
00210     template<class T, std::size_t N>
00211     bool operator==(const fixed_vector<T, N> & lhs, const fixed_vector<T, N> & rhs)
00212     {
00213           for(typename fixed_vector<T, N>::const_iterator iter = lhs.begin(); iter != lhs.end(); ++iter)
00214                 if(*iter != rhs(iter.index())) return false;
00215           
00216           return true;
00217     }
00218     
00219     // comparision
00220     template<class T, std::size_t N>
00221     bool operator!=(const fixed_vector<T, N> & lhs, const fixed_vector<T, N> & rhs)
00222     {
00223           return ! (lhs == rhs);
00224     }
00225 }}}
00226 
00227 #endif

Generated on Tue Feb 10 10:01:29 2009 for imaging2 by  doxygen 1.5.5