Main Page | User's Guide | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

Vector.hxx

00001 // Copyright (C) 2001-2004 Vivien Mallet
00002 //
00003 // This file is part of Seldon library.
00004 // Seldon library provides matrices and vectors structures for
00005 // linear algebra.
00006 // 
00007 // Seldon is free software; you can redistribute it and/or modify
00008 // it under the terms of the GNU General Public License as published by
00009 // the Free Software Foundation; either version 2 of the License, or
00010 // (at your option) any later version.
00011 // 
00012 // Seldon is distributed in the hope that it will be useful,
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 // GNU General Public License (file "license") for more details.
00016 //
00017 // For more information, please see the Seldon home page:
00018 //     http://spacetown.free.fr/lib/seldon/
00019 
00020 #ifndef SELDON_FILE_VECTOR_HXX
00021 
00022 #include "../Common/Common.hxx"
00023 #include "../Common/Properties.hxx"
00024 #include "../Common/Storage.hxx"
00025 #include "../Common/Errors.cxx"
00026 #include "../Common/Allocator.hxx"
00027 
00028 namespace Seldon
00029 {
00030 
00031 
00033 
00037   template <class T, class Allocator = SELDON_DEFAULT_ALLOCATOR<T> >
00038   class Vector_Base
00039   {
00040     // typdef declarations.
00041   public:
00042     typedef typename Allocator::value_type value_type;
00043     typedef typename Allocator::pointer pointer;
00044     typedef typename Allocator::const_pointer const_pointer;
00045     typedef typename Allocator::reference reference;
00046     typedef typename Allocator::const_reference const_reference;
00047 
00048     // Static attributes.
00049   protected:
00050     static Allocator vect_allocator_;
00051 
00052     // Attributes.
00053   protected:
00054     // Number of elements.
00055     int m_;
00056     // Pointer to stored elements.
00057     pointer data_;
00058 
00059     // Methods.
00060   public:
00061     // Constructors.
00062     Vector_Base();
00063     explicit Vector_Base(int i);
00064     Vector_Base(Vector_Base<T, Allocator>& A);
00065   
00066     // Destructor.
00067     ~Vector_Base();
00068 
00069     // Basic methods.
00070     int GetM() const;
00071     int GetLength() const;
00072     int GetSize() const;
00073     pointer GetData() const;
00074     const_pointer GetDataConst() const;
00075     void* GetDataVoid() const;
00076     const void* GetDataConstVoid() const;
00077 
00078   };
00079 
00080 
00081   // Vector allocator.
00082   template <class T, class Allocator>
00083   Allocator Vector_Base<T, Allocator>::vect_allocator_;
00084 
00085 
00087 
00090   template <class T, class Allocator>
00091   class Vector<T, Vect_Full, Allocator>: public Spacetown,
00092                                          public Vector_Base<T, Allocator>
00093   {
00094     // typedef declaration.
00095   public:
00096     typedef typename Allocator::value_type value_type;
00097     typedef typename Allocator::pointer pointer;
00098     typedef typename Allocator::const_pointer const_pointer;
00099     typedef typename Allocator::reference reference;
00100     typedef typename Allocator::const_reference const_reference;
00101 
00102     // Attributes.
00103   private:
00104 
00105     // Methods.
00106   public:
00107     // Constructor.
00108     explicit Vector<T, Vect_Full, Allocator>()  throw();
00109     explicit Vector<T, Vect_Full, Allocator>(int i);
00110     Vector<T, Vect_Full, Allocator>(Vector<T, Vect_Full, Allocator>& A);
00111     
00112     // Destructor.
00113     ~Vector();
00114     void Clear();
00115 
00116     // Memory management.
00117     void Reallocate(int i);
00118     void SetData(int i, pointer data);
00119     void Nullify();
00120 
00121     // Element access and affectation.
00122     reference operator() (int i);
00123     const_reference operator() (int i) const;
00124     Vector<T, Vect_Full, Allocator>& operator= (const Vector<T, Vect_Full,
00125                                                 Allocator>& X);
00126     void Copy(const Vector<T, Vect_Full, Allocator>& X);
00127 
00128     // Basic functions.
00129     int GetDataSize();
00130 
00131     // Convenient functions.
00132     void Zero();
00133     void Fill();
00134     template <class T0>
00135     void Fill(const T0& x);
00136     template <class T0>
00137     Vector<T, Vect_Full, Allocator>& operator= (const T0& X);
00138     void FillRand();
00139     void Print() const;
00140 
00141     // Norms.
00142     value_type GetNormInf() const;
00143     int GetNormInfIndex() const;
00144 
00145     // Input/output functions.
00146     void Write(string FileName) const;
00147     void Write(ofstream& FileStream) const;
00148     void WriteText(string FileName) const;
00149     void WriteText(ofstream& FileStream) const;
00150     void Read(string FileName);
00151     void Read(ifstream& FileStream);
00152     
00153   };
00154 
00155   template <class T, class Storage, class Allocator>
00156   ostream& operator << (ostream& out,
00157                         const Vector<T, Storage, Allocator>& V);
00158 
00159 
00160 } // namespace Seldon.
00161 
00162 #define SELDON_FILE_VECTOR_HXX
00163 #endif

Generated on Sun Jan 16 23:37:58 2005 for Multivac by  doxygen 1.4.0