00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SELDON_FILE_VECTOR_HXX
00021
00022 #include "../share/Common.hxx"
00023 #include "../share/Properties.hxx"
00024 #include "../share/Storage.hxx"
00025 #include "../share/Errors.hxx"
00026 #include "../share/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
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
00049 protected:
00050 static Allocator vect_allocator_;
00051
00052
00053 protected:
00054
00055 int m_;
00056
00057 pointer data_;
00058
00059
00060 public:
00061
00062 Vector_Base();
00063 explicit Vector_Base(int i);
00064 Vector_Base(const Vector_Base<T, Allocator>& A);
00065
00066
00067 ~Vector_Base();
00068
00069
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
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, VectFull, Allocator>: public Vector_Base<T, Allocator>
00092 {
00093
00094 public:
00095 typedef typename Allocator::value_type value_type;
00096 typedef typename Allocator::pointer pointer;
00097 typedef typename Allocator::const_pointer const_pointer;
00098 typedef typename Allocator::reference reference;
00099 typedef typename Allocator::const_reference const_reference;
00100
00101 typedef VectFull storage;
00102
00103
00104 private:
00105
00106
00107 public:
00108
00109 explicit Vector();
00110 explicit Vector(int i);
00111 Vector(int i, pointer data);
00112 Vector(const Vector<T, VectFull, Allocator>& A);
00113
00114
00115 ~Vector();
00116 void Clear();
00117
00118
00119 void Reallocate(int i);
00120 void Resize(int i);
00121 void SetData(int i, pointer data);
00122 template <class Allocator0>
00123 void SetData(const Vector<T, VectFull, Allocator0>& V);
00124 void Nullify();
00125
00126
00127 reference operator() (int i);
00128 reference Get(int i);
00129 #ifndef SWIG
00130 const_reference operator() (int i) const;
00131 const_reference Get(int i) const;
00132 Vector<T, VectFull, Allocator>& operator= (const Vector<T, VectFull,
00133 Allocator>& X);
00134 #endif
00135 void Copy(const Vector<T, VectFull, Allocator>& X);
00136 Vector<T, VectFull, Allocator> Copy() const;
00137 void Append(const T& x);
00138 template<class T0>
00139 void PushBack(const T0& x);
00140 template<class Allocator0>
00141 void PushBack(const Vector<T, VectFull, Allocator0>& X);
00142
00143
00144 int GetDataSize();
00145
00146
00147 void Zero();
00148 void Fill();
00149 template <class T0>
00150 void Fill(const T0& x);
00151 #ifndef SWIG
00152 template <class T0>
00153 Vector<T, VectFull, Allocator>& operator= (const T0& X);
00154 #endif
00155 template <class T0>
00156 Vector<T, VectFull, Allocator>& operator*= (const T0& X);
00157 void FillRand();
00158 void Print() const;
00159
00160
00161 value_type GetNormInf() const;
00162 int GetNormInfIndex() const;
00163
00164
00165 void Write(string FileName, bool with_size = true) const;
00166 void Write(ostream& FileStream, bool with_size = true) const;
00167 void WriteText(string FileName) const;
00168 void WriteText(ostream& FileStream) const;
00169 #ifdef SELDON_WITH_HDF5
00170 void WriteHDF5(string FileName, string group_name,
00171 string dataset_name) const;
00172 #endif
00173 void Read(string FileName, bool with_size = true);
00174 void Read(istream& FileStream, bool with_size = true);
00175 void ReadText(string FileName);
00176 void ReadText(istream& FileStream);
00177 };
00178
00179 #ifndef SWIG
00180 template <class T, class Storage, class Allocator>
00181 ostream& operator << (ostream& out,
00182 const Vector<T, Storage, Allocator>& V);
00183 #endif
00184
00185
00186 }
00187
00188 #define SELDON_FILE_VECTOR_HXX
00189 #endif