00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __VCLASSES_HH
00020 #define __VCLASSES_HH
00021
00022 #include <assert.h>
00023
00025
00026
00027
00029
00030 template <int Size>
00031 class Vector : public FixedVector<Size, FixedVAccessor<Size,typename SizeTraits<Size>::get_zone> > {
00032 public:
00033
00034 inline Vector(){}
00035
00036
00037 inline Vector(const double from[Size]){
00038 memcpy(this->my_values,from,Size*sizeof(double));
00039 }
00040
00041
00042 template <class T, class Op>
00043 inline Vector(const T& arg, const Operator<Op>&){Op::eval(*this,arg);}
00044
00045
00046 template <class LHS, class RHS, class Op>
00047 inline Vector(const LHS& lhs, const RHS& rhs, const Operator<Op>&){Op::eval(*this,lhs,rhs);}
00048
00049
00050 template<class Accessor>
00051 inline Vector(const FixedVector<Size,Accessor>& from){
00052 FixedVector<Size, FixedVAccessor<Size,typename SizeTraits<Size>::get_zone> >::operator=(from);
00053 }
00054
00055
00056 template<class Accessor>
00057 inline Vector(const DynamicVector<Accessor>& from){
00058 assert(from.size() == Size);
00059 FixedVector<Size, FixedVAccessor<Size,typename SizeTraits<Size>::get_zone> >::operator=(from);
00060 }
00061
00062 template <class Accessor> inline Vector<Size>& operator=(const FixedVector<Size,Accessor>& fv) {
00063 *this = Vector<Size>(fv);
00064 return *this;
00065 }
00066
00067 template <class Accessor> inline Vector<Size>& operator=(const DynamicVector<Accessor>& dv) {
00068 *this = Vector<Size>(dv);
00069 return *this;
00070 }
00071
00072
00073 VectorMagic::VectorFiller<1,Size, Vector<Size>, VectorMagic::CommaStyle> operator=(double t) {
00074 (*this)[0] = t;
00075 return VectorMagic::VectorFiller<1,Size, Vector<Size>, VectorMagic::CommaStyle>(*this);
00076 }
00077
00078 template <int N> VectorMagic::VectorFiller<N,Size, Vector<Size>,VectorMagic::CommaStyle> operator=(const VectorMagic::ComponentPlaceHolder<N>& t) {
00079 return VectorMagic::VectorFiller<N,Size, Vector<Size>,VectorMagic::CommaStyle>(*this);
00080 }
00081
00082 };
00083
00084
00085
00086
00087
00088 template <>
00089 class Vector<> : public DynamicVector<DynamicVAccessor> {
00090 public:
00091 Vector(){
00092 this->my_size = 0;
00093 this->my_values = NULL;
00094 }
00095
00096 inline void resize(int new_size)
00097 {
00098 if(this->my_size != new_size)
00099 {
00100 delete[] this->my_values;
00101 this->my_size = new_size;
00102 this->my_values = new double[this->my_size];
00103 }
00104 }
00105
00106 template <class Accessor> inline void assign(const VectorBase<Accessor>& v) {
00107 resize(v.size());
00108 DynamicVector<DynamicVAccessor>::operator=(v);
00109 }
00110 Vector(int Size) {
00111 this->my_size=Size; this->my_values = new double[Size];
00112 }
00113
00114 inline Vector(int Size, double* from){
00115 this->my_size=Size;
00116 this->my_values = new double[Size];
00117 memcpy(this->my_values,from,Size*sizeof(double));
00118 }
00119
00120 inline ~Vector(){
00121 delete[] this->my_values;
00122 }
00123
00124
00125 template <class T, class Op>
00126 Vector(const T& arg, const Operator<Op>&){
00127 Op::eval(*this,arg);
00128 }
00129
00130
00131 template <class LHS, class RHS, class Op>
00132 Vector(const LHS& lhs, const RHS& rhs, const Operator<Op>&){
00133 Op::eval(*this,lhs,rhs);
00134 }
00135
00136
00137 template<class Accessor>
00138 Vector(const VectorBase<Accessor>& from){
00139 this->my_size = from.size();
00140 this->my_values = new double[this->my_size];
00141 DynamicVector<DynamicVAccessor>::operator=(from);
00142 }
00143
00144
00145 Vector(const Vector& from){
00146 this->my_size = from.my_size;
00147 this->my_values = new double[this->my_size];
00148 memcpy(this->my_values,from.my_values,this->my_size*sizeof(double));
00149 }
00150 };
00151
00152 struct VSizer{
00153 static inline void set_size(Vector<>& v, int size){
00154 v.my_size=size;
00155 v.my_values=new double[size];
00156 }
00157 };
00158
00159
00160 #endif