vector/Vector2.hxx

00001 // Copyright (C) 2010, INRIA
00002 // Author(s): Marc Fragu, Vivien Mallet
00003 //
00004 // This file is part of the linear-algebra library Seldon,
00005 // http://seldon.sourceforge.net/.
00006 //
00007 // Seldon is free software; you can redistribute it and/or modify it under the
00008 // terms of the GNU Lesser General Public License as published by the Free
00009 // Software Foundation; either version 2.1 of the License, or (at your option)
00010 // any later version.
00011 //
00012 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
00015 // more details.
00016 //
00017 // You should have received a copy of the GNU Lesser General Public License
00018 // along with Seldon. If not, see http://www.gnu.org/licenses/.
00019 
00020 
00021 #ifndef SELDON_FILE_VECTOR_VECTOR2_HXX
00022 
00023 
00024 #ifndef SELDON_VECTOR2_DEFAULT_ALLOCATOR_0
00025 
00028 #define SELDON_VECTOR2_DEFAULT_ALLOCATOR_0 SELDON_DEFAULT_ALLOCATOR
00029 #endif
00030 
00031 #ifndef SELDON_VECTOR2_DEFAULT_ALLOCATOR_1
00032 
00035 #define SELDON_VECTOR2_DEFAULT_ALLOCATOR_1 MallocObject
00036 #endif
00037 
00038 
00039 namespace Seldon
00040 {
00041 
00042 
00044 
00055   template <class T,
00056             class Allocator0 = SELDON_VECTOR2_DEFAULT_ALLOCATOR_0<T>,
00057             class Allocator1 = SELDON_VECTOR2_DEFAULT_ALLOCATOR_1<
00058               Vector<T, VectFull, Allocator0> > >
00059   class Vector2
00060   {
00061   public:
00062     typedef T value_type;
00063     typedef T* pointer;
00064     typedef const T* const_pointer;
00065     typedef T& reference;
00066     typedef const T& const_reference;
00067 
00068   protected:
00069     Vector<Vector<T, VectFull, Allocator0>, VectFull, Allocator1> data_;
00070 
00071   public:
00072 
00073     /*** Constructors and destructor ***/
00074 
00075     Vector2();
00076     Vector2(int length);
00077     Vector2(const Vector<int>& length);
00078     ~Vector2();
00079 
00080     /*** Management of the vectors ***/
00081 
00082     bool IsEmpty() const;
00083     int GetLength() const;
00084     int GetSize() const;
00085     int GetLength(int i) const;
00086     int GetSize(int i) const;
00087     int GetNelement() const;
00088     int GetNelement(int beg, int end) const;
00089     Vector<int> GetShape() const;
00090     void GetShape(Vector<int>& shape) const;
00091     void Reallocate(int M);
00092     void Reallocate(int i, int N);
00093     void Reallocate(const Vector<int>& length);
00094     void Select(int beg, int end);
00095     template <class Td, class Allocatord>
00096     void Flatten(Vector<Td, VectFull, Allocatord>& data) const;
00097     template <class Td, class Allocatord>
00098     void Flatten(int beg, int end, Vector<Td, VectFull, Allocatord>& data)
00099       const;
00100 
00101     void PushBack(int i, const T& x);
00102     void PushBack(const Vector<T, VectFull, Allocator0>& X);
00103     void PushBack(const Vector<Vector<T, VectFull, Allocator0>,
00104                   VectFull, Allocator1>& V);
00105     void PushBack(const Vector2<T, Allocator0, Allocator1>& V);
00106 
00107     void Clear();
00108     void Clear(int i);
00109 
00110     void Fill(const T& x);
00111 
00112     Vector<Vector<T, VectFull, Allocator0>, VectFull, Allocator1>&
00113     GetVector();
00114     const Vector<Vector<T, VectFull, Allocator0>, VectFull,
00115                  Allocator1> GetVector() const;
00116 
00117     Vector<T, VectFull, Allocator0>& GetVector(int i);
00118     const Vector<T, VectFull, Allocator0>& GetVector(int i) const;
00119 
00120     void Copy(const Vector2<T, Allocator0, Allocator1>& V);
00121 
00122     /*** Element access and assignment ***/
00123 
00124     const Vector<T, VectFull, Allocator0>& operator() (int i) const;
00125     Vector<T, VectFull, Allocator0>& operator() (int i);
00126     const_reference operator() (int i, int j) const;
00127     reference operator() (int i, int j);
00128 
00129     /*** Convenient methods ***/
00130 
00131     template <class V2>
00132     bool HasSameShape(const V2& V) const;
00133     void Print() const;
00134   };
00135 
00136 
00137 }
00138 
00139 
00140 #define SELDON_FILE_VECTOR_VECTOR2_HXX
00141 #endif