MathTL
algebra/fixed_vector.h
00001 // -*- c++ -*-
00002 
00003 // +--------------------------------------------------------------------+
00004 // | This file is part of MathTL - the Mathematical Template Library    |
00005 // |                                                                    |
00006 // | Copyright (c) 2002-2009                                            |
00007 // | Thorsten Raasch, Manuel Werner, Andreas Schneider                  |
00008 // +--------------------------------------------------------------------+
00009 
00010 #ifndef _MATHTL_FIXED_VECTOR_H
00011 #define _MATHTL_FIXED_VECTOR_H
00012 
00013 #include <iostream>
00014 
00015 // external functionality, for convenience:
00016 #include <algebra/vector_norms.h>
00017 #include <algebra/vector_arithmetics.h>
00018 
00019 namespace MathTL
00020 {
00032   template <class C, unsigned int SIZE>
00033   class FixedVector
00034   {
00035   public:
00039     typedef C value_type;
00040     
00044     typedef value_type* pointer;
00045 
00049     typedef const value_type* const_pointer;
00050 
00054     typedef value_type* iterator;
00055 
00059     typedef const value_type* const_iterator;
00060 
00064     typedef value_type& reference;
00065     
00069     typedef const value_type& const_reference;
00070 
00074     typedef unsigned int size_type;
00075 
00080     FixedVector();
00081 
00085     FixedVector(const C);
00086 
00090     FixedVector(const FixedVector<C, SIZE>& v);
00091 
00095     virtual ~FixedVector();
00096 
00100     inline size_type size() const {return SIZE;}
00101 
00105     FixedVector<C, SIZE>& operator = (const FixedVector<C, SIZE>& v);
00106 
00110     FixedVector<C, SIZE>& operator = (const C c);
00111 
00115     const C operator [] (const size_type i) const;
00116 
00120     const C operator () (const size_type i) const;
00121 
00125     C& operator [] (const size_type i);
00126 
00130     C& operator () (const size_type i);
00131 
00135     const_iterator begin() const;
00136 
00140     iterator begin();
00141 
00146     const_iterator end() const;
00147 
00152     iterator end();
00153 
00157     template <class C2>
00158     bool operator == (const FixedVector<C2, SIZE>& v) const;
00159 
00163     template <class C2>
00164     bool operator != (const FixedVector<C2, SIZE>& v) const;
00165 
00169     template <class C2>
00170     bool operator < (const FixedVector<C2, SIZE>& v) const;
00171 
00175     template <class C2>
00176     void add(const FixedVector<C2, SIZE>& v);
00177     
00181     template <class C2>
00182     void add(const C2 s, const FixedVector<C2, SIZE>& v);
00183     
00188     template <class C2>
00189     void sadd(const C s, const FixedVector<C2, SIZE>& v);
00190 
00194     void scale(const C s);
00195 
00199     template <class C2>
00200     FixedVector<C, SIZE>& operator += (const FixedVector<C2, SIZE>& v);
00201 
00205     template <class C2>
00206     void subtract(const FixedVector<C2, SIZE>& v);
00207 
00211     template <class C2>
00212     FixedVector<C, SIZE>& operator -= (const FixedVector<C2, SIZE>& v);
00213 
00217     template <class C2>
00218     const C inner_product (const FixedVector<C2, SIZE>& v) const;
00219 
00223     FixedVector<C, SIZE>& operator *= (const C c);
00224     
00228     FixedVector<C, SIZE>& operator /= (const C c);
00229     
00230   protected:
00234     C* values_;
00235   };
00236 
00242   template <class C, class C2, unsigned int SIZE>
00243   FixedVector<C, SIZE> operator + (const FixedVector<C, SIZE>& v1, const FixedVector<C2, SIZE>& v2);
00244 
00250   template <class C, class C2, unsigned int SIZE>
00251   FixedVector<C, SIZE> operator - (const FixedVector<C, SIZE>& v1, const FixedVector<C2, SIZE>& v2);
00252 
00257   template <class C, unsigned int SIZE>
00258   std::ostream& operator << (std::ostream& os, const FixedVector<C, SIZE>& v);
00259 }
00260 
00261 // include implementation of inline functions
00262 #include <algebra/fixed_vector.cpp>
00263 
00264 #endif // _MATHTL_FIXED_VECTOR_H
 All Classes Functions Variables Typedefs Enumerations