Warning: this documentation for the development version is under construction.
00001 // Copyright (C) 2001-2009 Vivien Mallet 00002 // 00003 // This file is part of the linear-algebra library Seldon, 00004 // http://seldon.sourceforge.net/. 00005 // 00006 // Seldon is free software; you can redistribute it and/or modify it under the 00007 // terms of the GNU Lesser General Public License as published by the Free 00008 // Software Foundation; either version 2.1 of the License, or (at your option) 00009 // any later version. 00010 // 00011 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY 00012 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00013 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for 00014 // more details. 00015 // 00016 // You should have received a copy of the GNU Lesser General Public License 00017 // along with Seldon. If not, see http://www.gnu.org/licenses/. 00018 00019 00020 // To be included by Seldon.hxx 00021 00022 00023 #ifndef SELDON_FILE_ARRAY3D_HXX 00024 00025 #include "../share/Common.hxx" 00026 #include "../share/Errors.hxx" 00027 #include "../share/Allocator.hxx" 00028 00029 namespace Seldon 00030 { 00031 00032 00034 00037 template <class T, class Allocator = SELDON_DEFAULT_ALLOCATOR<T> > 00038 class Array3D 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 array3D_allocator_; 00051 00052 // Attributes. 00053 protected: 00054 // Length along dimension #1. 00055 int length1_; 00056 // Length along dimension #2. 00057 int length2_; 00058 // Length along dimension #3. 00059 int length3_; 00060 00061 // Size of a slice (i.e. length1_ by length2_). 00062 int length23_; 00063 00064 // Pointer to stored elements. 00065 pointer data_; 00066 00067 // Methods. 00068 public: 00069 // Constructors. 00070 Array3D(); 00071 Array3D(int i, int j, int k); 00072 Array3D(const Array3D<T, Allocator>& A); 00073 00074 // Destructor. 00075 ~Array3D(); 00076 00077 // Basic methods. 00078 int GetLength1() const; 00079 int GetLength2() const; 00080 int GetLength3() const; 00081 int GetSize() const; 00082 int GetDataSize() const; 00083 pointer GetData() const; 00084 00085 // Memory management. 00086 void Reallocate(int i, int j, int k); 00087 void Clear(); 00088 00089 // Element access and affectation. 00090 reference operator() (int i, int j, int k); 00091 const_reference operator() (int i, int j, int k) const; 00092 Array3D<T, Allocator>& operator= (const Array3D<T, Allocator>& A); 00093 void Copy(const Array3D<T, Allocator>& A); 00094 00095 // Convenient functions. 00096 void Zero(); 00097 void Fill(); 00098 template <class T0> 00099 void Fill(const T0& x); 00100 void FillRand(); 00101 void Print() const; 00102 00103 // Input/output functions 00104 void Write(string FileName) const; 00105 void Write(ofstream& FileStream) const; 00106 void Read(string FileName); 00107 void Read(ifstream& FileStream); 00108 }; 00109 00110 00111 // 3D array allocator. 00112 template <class T, class Allocator> 00113 Allocator Array3D<T, Allocator>::array3D_allocator_; 00114 00115 00116 template <class T, class Allocator> 00117 ostream& operator << (ostream& out, 00118 const Array3D<T, Allocator>& A); 00119 00120 template <class T0, class T, class Allocator> 00121 void Mlt(const T0& alpha, Array3D<T, Allocator>& A); 00122 00123 } // namespace Seldon. 00124 00125 00126 #define SELDON_FILE_ARRAY3D_HXX 00127 #endif