00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 namespace TooN {
00032
00033 namespace Internal{
00034 template<int Size, class Precision, int Stride, class Mem> struct GenericVBase;
00035
00037
00038
00039
00040 struct Default{};
00041
00042 template<int Stride, class Ptr=Default, class CPtr=Default, class Ref=Default, class CRef=Default>
00043 struct SliceVBase {
00044
00045
00046 template<int Size, typename Precision>
00047 struct VLayout
00048 : public GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision, Ptr, CPtr, Ref, CRef> > {
00049 typedef typename VectorSlice<Size, Precision, Ptr, CPtr, Ref, CRef>::PointerType PointerType;
00050
00051 VLayout(PointerType d, int length, int stride)
00052 :GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision, Ptr, CPtr, Ref, CRef> >(d, length, stride){
00053 }
00054
00055 template<class Op>
00056 VLayout(const Operator<Op>& op)
00057 :GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision> >(op) {}
00058 };
00059
00060 };
00061
00062 template<int Stride>
00063 struct SliceVBase<Stride, Default, Default, Default, Default> {
00064
00065
00066 template<int Size, typename Precision>
00067 struct VLayout
00068 : public GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision> > {
00069
00070 typedef typename VectorSlice<Size, Precision>::PointerType PointerType;
00071
00072 VLayout(PointerType d, int length, int stride)
00073 :GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision> >(d, length, stride){
00074 }
00075
00076 template<class Op>
00077 VLayout(const Operator<Op>& op)
00078 :GenericVBase<Size, Precision, Stride, VectorSlice<Size, Precision> >(op) {}
00079 };
00080
00081 };
00082
00084
00085
00086
00087
00088 struct VBase {
00089
00090
00091 template<int Size, class Precision>
00092 struct VLayout
00093 : public GenericVBase<Size, Precision, 1, VectorAlloc<Size, Precision> > {
00094
00095 VLayout(){}
00096
00097 VLayout(int s)
00098 :GenericVBase<Size, Precision, 1, VectorAlloc<Size, Precision> >(s)
00099 {}
00100
00101 template<class Op>
00102 VLayout(const Operator<Op>& op)
00103 :GenericVBase<Size, Precision, 1, VectorAlloc<Size, Precision> >(op) {}
00104 };
00105 };
00106
00108
00109
00110
00111
00112 template<int Size, typename Precision, int Stride, typename Mem> struct GenericVBase: public Mem, public StrideHolder<Stride>
00113 {
00114 int stride() const{
00115 return StrideHolder<Stride>::stride();
00116 }
00117
00118
00119 GenericVBase(){}
00120
00121 GenericVBase(int s)
00122 :Mem(s)
00123 {}
00124
00125 typedef typename Mem::PointerType PointerType;
00126 typedef typename Mem::ConstPointerType ConstPointerType;
00127 typedef typename Mem::ReferenceType ReferenceType;
00128 typedef typename Mem::ConstReferenceType ConstReferenceType;
00129
00130 GenericVBase(PointerType d, int length, int stride)
00131 :Mem(d, length),StrideHolder<Stride>(stride){
00132 }
00133
00134 template<class Op>
00135 GenericVBase(const Operator<Op> & op) : Mem(op), StrideHolder<Stride>(op) {}
00136
00137 using Mem::data;
00138 using Mem::size;
00139
00140 ReferenceType operator[](int i) {
00141 Internal::check_index(size(), i);
00142 return data()[i * stride()];
00143 }
00144
00145 const ConstReferenceType operator[](int i) const {
00146 Internal::check_index(size(), i);
00147 return data()[i * stride()];
00148 }
00149
00150 typedef SliceVBase<Stride, PointerType, ConstPointerType, ReferenceType, ConstReferenceType> SliceBase;
00151 typedef SliceVBase<Stride, ConstPointerType, ConstPointerType, ConstReferenceType, ConstReferenceType> ConstSliceBase;
00152
00153
00154
00155 template<int Start, int Length>
00156 Vector<Length, Precision, SliceBase> slice(int start, int length){
00157 Internal::CheckSlice<Size, Start, Length>::check(size(), start, length);
00158 return Vector<Length, Precision, SliceBase>(data() + stride() * (Start==Dynamic?start:Start), Length==Dynamic?length:Length, stride(), Slicing());
00159 }
00160
00161 template<int Start, int Length>
00162 const Vector<Length, const Precision, ConstSliceBase> slice(int start, int length) const{
00163 Internal::CheckSlice<Size, Start, Length>::check(size(), start, length);
00164 return Vector<Length, const Precision, ConstSliceBase>(data() + stride() * (Start==Dynamic?start:Start), Length==Dynamic?length:Length, stride(), Slicing());
00165 }
00166
00167
00168
00169
00170 template<int Start, int Length> Vector<Length, Precision, SliceBase> slice(){
00171 Internal::CheckSlice<Size, Start, Length>::check();
00172 return slice<Start, Length>(Start, Length);
00173 }
00174
00175 template<int Start, int Length> const Vector<Length, const Precision, ConstSliceBase> slice() const {
00176 Internal::CheckSlice<Size, Start, Length>::check();
00177 return slice<Start, Length>(Start, Length);
00178 }
00179
00180 Vector<Dynamic, Precision, SliceBase> slice(int start, int length){
00181 return slice<Dynamic, Dynamic>(start, length);
00182 }
00183
00184 const Vector<Dynamic, const Precision, ConstSliceBase> slice(int start, int length) const{
00185 return slice<Dynamic, Dynamic>(start, length);
00186 }
00187
00188
00189 const Matrix<1, Size, const Precision, Slice<1,Stride> > as_row() const{
00190 return Matrix<1, Size, const Precision, Slice<1,Stride> >(data(), 1, size(), 1, stride(), Slicing());
00191 }
00192
00193 Matrix<1, Size, Precision, Slice<1,Stride> > as_row(){
00194 return Matrix<1, Size, Precision, Slice<1,Stride> >(data(), 1, size(), 1, stride(), Slicing());
00195 }
00196
00197 const Matrix<Size, 1, const Precision, Slice<Stride,1> > as_col() const{
00198 return Matrix<Size, 1, const Precision, Slice<Stride,1> >(data(), size(), 1, stride(), 1, Slicing());
00199 }
00200
00201 Matrix<Size, 1, Precision, Slice<Stride,1> > as_col(){
00202 return Matrix<Size, 1, Precision, Slice<Stride,1> >(data(), size(), 1, stride(), 1, Slicing());
00203 }
00204
00205 typedef Vector<Size, Precision, SliceBase> as_slice_type;
00206
00207 Vector<Size, Precision, SliceBase> as_slice(){
00208 return Vector<Size, Precision, SliceBase>(data(), size(), stride(), Slicing());
00209 }
00210
00211 const Vector<Size, const Precision, ConstSliceBase> as_slice() const {
00212 return Vector<Size, const Precision, ConstSliceBase>(data(), size(), stride(), Slicing());
00213 }
00214
00215 DiagonalMatrix<Size,Precision, SliceBase> as_diagonal() {
00216 return DiagonalMatrix<Size, Precision, SliceBase> (data(), size(), stride(), Slicing());
00217 }
00218
00219 const DiagonalMatrix<Size,const Precision, ConstSliceBase> as_diagonal() const {
00220 return DiagonalMatrix<Size, const Precision, ConstSliceBase> (data(), size(), stride(), Slicing());
00221 }
00222
00223 };
00224
00225 }
00226
00227 }