00001 #ifndef VECTOR_TMPL_HEADER
00002 #define VECTOR_TMPL_HEADER
00003
00004
00005
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <stdlib.h>
00026 #include <math.h>
00027
00028 #ifdef _STANDARD_C_PLUS_PLUS
00029 #include <iostream>
00030 #include <iomanip>
00031 #include <vector>
00032 #include <algorithm>
00033 #include <numeric>
00034 #include <functional>
00035 using namespace std;
00036 #else
00037 #include <iostream.h>
00038 #include <iomanip.h>
00039 #include <vector.h>
00040 #include <algo.h>
00041 #include <function.h>
00042 #endif
00043
00044
00045
00046 #include "Rangedimexc.hh"
00047
00048
00049
00050 namespace RazorBack {
00051
00058 template <class T_>
00059 class Vector_
00060 {
00061
00062 private:
00063
00064 vector<T_> Vec;
00065 size_t Dim;
00066 bool Ftnidx;
00067 bool Check;
00068
00069
00070 public:
00071
00072
00073
00078 explicit Vector_(size_t N=3, const T_& X=T_(0)):
00079 Vec(!N? 3: N, X), Dim(!N? 3: N),
00080 Ftnidx(false), Check(false) {}
00081
00086 explicit Vector_(const vector<T_>& V):
00087 Vec(V), Dim(Vec.size()), Ftnidx(false), Check(false)
00088 {
00089 if (V.empty()) dim(3);
00090 }
00091
00096 Vector_(const T_* Arr, size_t Len):
00097 Vec(Len), Dim(Len), Ftnidx(false), Check(false)
00098 {
00099 for (register unsigned int i=0; i<Len; i++)
00100 Vec[i]=Arr[i];
00101 }
00102
00104 virtual ~Vector_() {}
00105
00111 const T_& operator[](size_t Idx) const { return Vec[Idx]; }
00112 T_& operator[](size_t Idx) { return Vec[Idx]; }
00113 const T_& operator()(size_t Idx) const;
00114 T_& operator()(size_t Idx);
00115
00125 bool ftn_idx() const { return Ftnidx; }
00126 bool ftn_idx(bool F) { bool Of=Ftnidx; Ftnidx=F; return Of; }
00127
00132 bool range_check() const { return Check; }
00133 bool range_check(bool C) { bool Oc=Check; Check=C; return Oc; }
00134
00136 Vector_<T_>& set_values(const T_& X=T_(0));
00137
00143 size_t dim() const { return(Dim); }
00144 size_t dim(size_t D);
00145
00147 typename vector<T_>::const_iterator begin() const { return Vec.begin(); }
00148 typename vector<T_>::iterator begin() { return Vec.begin(); }
00149 typename vector<T_>::const_iterator end() const { return Vec.end(); }
00150 typename vector<T_>::iterator end() { return Vec.end(); }
00151
00157 Vector_<T_>& operator+=(const T_& X);
00158 Vector_<T_>& operator-=(const T_& X);
00159 Vector_<T_>& operator*=(const T_& X);
00160 Vector_<T_> operator*(const T_& X) const;
00161 Vector_<T_>& operator/=(const T_& X);
00162 Vector_<T_> operator/(const T_& X) const;
00163
00168 Vector_<T_>& operator+=(const Vector_<T_>& V);
00169 Vector_<T_> operator+(const Vector_<T_>& V) const;
00170 Vector_<T_>& operator-=(const Vector_<T_>& V);
00171 Vector_<T_> operator-(const Vector_<T_>& V) const;
00172 T_ operator*(const Vector_<T_>& V) const;
00173
00175
00182 T_ vec_len2() const { return((*this) * (*this)); }
00183 T_ vec_len() const { return(sqrt(vec_len2())); }
00184
00191 T_ vec_norm();
00192
00194
00202 void transform(unary_function<T_, T_> Unaryfunc)
00203 {
00204 std::transform(Vec.begin(), Vec.end(), Vec.begin(), Unaryfunc);
00205 }
00206
00208 void read(istream& In);
00209 };
00210
00211
00212
00213
00214
00215
00216
00220 template <class T_>
00221 Vector_<T_> operator*(const T_& X, const Vector_<T_>& V);
00222
00228 template <class T_>
00229 Vector_<T_> cross_prod(const Vector_<T_>& V1, const Vector_<T_>& V2);
00230
00236 template <class T_>
00237 T_ vec_len2(const Vector_<T_>& V) { return(V*V); }
00238
00243 template <class T_>
00244 T_ vec_len(const Vector_<T_>& V) { return(sqrt(V*V)); }
00245
00250 template <class T_>
00251 T_ diff_len2(const Vector_<T_>& V1, const Vector_<T_>& V2);
00252
00253
00254
00266 template <class T_>
00267 istream& operator>>(istream& In, Vector_<T_>& V)
00268 {
00269 V.read(In);
00270 return In;
00271 }
00272
00274 template <class T_>
00275 ostream& operator<<(ostream& Out, const Vector_<T_>& V);
00276
00277
00278
00280 typedef Vector_<double> Vecdbl_;
00281 typedef Vector_<float> Vecflt_;
00282
00283 }
00284
00285 #ifdef INCLUDE_TMPL_DEFS
00286 #include "Vector.cc"
00287 #endif
00288
00289
00290
00291 #endif // VECTOR_TMPL_HEADER