[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN/internal vbase.hh allocator.hh
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN/internal vbase.hh allocator.hh |
Date: |
Mon, 01 Feb 2010 19:27:42 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 10/02/01 19:27:42
Modified files:
internal : vbase.hh allocator.hh
Log message:
Extra parameterization in SliceVBsase to allow for Vectors with data
held in an underlying smart pointer. The parameterization allow
customzation
of the pointer type and the return type from operator[].
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vbase.hh?cvsroot=toon&r1=1.44&r2=1.45
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/allocator.hh?cvsroot=toon&r1=1.37&r2=1.38
Patches:
Index: vbase.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vbase.hh,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -b -r1.44 -r1.45
--- vbase.hh 11 Jan 2010 14:59:12 -0000 1.44
+++ vbase.hh 1 Feb 2010 19:27:41 -0000 1.45
@@ -37,16 +37,39 @@
//
// Slice holding class
//
+struct Default{};
-template<int Stride>
+template<int Stride, class Ptr=Default, class CPtr=Default, class Ref=Default,
class CRef=Default>
struct SliceVBase {
// this class is really just a typedef
template<int Size, typename Precision>
struct VLayout
+ : public GenericVBase<Size, Precision, Stride,
VectorSlice<Size, Precision, Ptr, CPtr, Ref, CRef> > {
+ typedef typename VectorSlice<Size, Precision, Ptr, CPtr, Ref,
CRef>::PointerType PointerType;
+
+ VLayout(PointerType d, int length, int stride)
+ :GenericVBase<Size, Precision, Stride,
VectorSlice<Size, Precision, Ptr, CPtr, Ref, CRef> >(d, length, stride){
+ }
+
+ template<class Op>
+ VLayout(const Operator<Op>& op)
+ :GenericVBase<Size, Precision, Stride,
VectorSlice<Size, Precision> >(op) {}
+ };
+
+};
+
+template<int Stride>
+struct SliceVBase<Stride, Default, Default, Default, Default> {
+
+ // this class is really just a typedef
+ template<int Size, typename Precision>
+ struct VLayout
: public GenericVBase<Size, Precision, Stride,
VectorSlice<Size, Precision> > {
- VLayout(Precision* d, int length, int stride)
+ typedef typename VectorSlice<Size, Precision>::PointerType
PointerType;
+
+ VLayout(PointerType d, int length, int stride)
:GenericVBase<Size, Precision, Stride,
VectorSlice<Size, Precision> >(d, length, stride){
}
@@ -99,7 +122,12 @@
:Mem(s)
{}
- GenericVBase(Precision* d, int length, int stride)
+ typedef typename Mem::PointerType PointerType;
+ typedef typename Mem::ConstPointerType ConstPointerType;
+ typedef typename Mem::ReferenceType ReferenceType;
+ typedef typename Mem::ConstReferenceType ConstReferenceType;
+
+ GenericVBase(PointerType d, int length, int stride)
:Mem(d, length),StrideHolder<Stride>(stride){
}
@@ -109,47 +137,51 @@
using Mem::data;
using Mem::size;
- Precision& operator[](int i) {
+ ReferenceType operator[](int i) {
Internal::check_index(size(), i);
return data()[i * stride()];
}
- const Precision& operator[](int i) const {
+ const ConstReferenceType operator[](int i) const {
Internal::check_index(size(), i);
return data()[i * stride()];
}
+ typedef SliceVBase<Stride, PointerType, ConstPointerType,
ReferenceType, ConstReferenceType> SliceBase;
+ typedef SliceVBase<Stride, ConstPointerType, ConstPointerType,
ConstReferenceType, ConstReferenceType> ConstSliceBase;
+
+
//Completely generic Vector slice operations below:
template<int Start, int Length>
- Vector<Length, Precision, SliceVBase<Stride> > slice(int start, int
length){
+ Vector<Length, Precision, SliceBase> slice(int start, int length){
Internal::CheckSlice<Size, Start, Length>::check(size(), start,
length);
- return Vector<Length, Precision, SliceVBase<Stride> >(data() +
stride() * (Start==Dynamic?start:Start), Length==Dynamic?length:Length,
stride(), Slicing());
+ return Vector<Length, Precision, SliceBase>(data() + stride() *
(Start==Dynamic?start:Start), Length==Dynamic?length:Length, stride(),
Slicing());
}
template<int Start, int Length>
- const Vector<Length, const Precision, SliceVBase<Stride> > slice(int
start, int length) const{
+ const Vector<Length, const Precision, ConstSliceBase> slice(int start,
int length) const{
Internal::CheckSlice<Size, Start, Length>::check(size(), start,
length);
- return Vector<Length, const Precision, SliceVBase<Stride>
>(data() + stride() * (Start==Dynamic?start:Start),
Length==Dynamic?length:Length, stride(), Slicing());
+ return Vector<Length, const Precision, ConstSliceBase>(data() +
stride() * (Start==Dynamic?start:Start), Length==Dynamic?length:Length,
stride(), Slicing());
}
//Special case slice operations
- template<int Start, int Length> Vector<Length, Precision,
SliceVBase<Stride> > slice(){
+ template<int Start, int Length> Vector<Length, Precision, SliceBase>
slice(){
Internal::CheckSlice<Size, Start, Length>::check();
return slice<Start, Length>(Start, Length);
}
- template<int Start, int Length> const Vector<Length, const Precision,
SliceVBase<Stride> > slice() const {
+ template<int Start, int Length> const Vector<Length, const Precision,
ConstSliceBase> slice() const {
Internal::CheckSlice<Size, Start, Length>::check();
return slice<Start, Length>(Start, Length);
}
- Vector<Dynamic, Precision, SliceVBase<Stride> > slice(int start, int
length){
+ Vector<Dynamic, Precision, SliceBase> slice(int start, int length){
return slice<Dynamic, Dynamic>(start, length);
}
- const Vector<Dynamic, Precision, SliceVBase<Stride> > slice(int start,
int length) const{
+ const Vector<Dynamic, Precision, ConstSliceBase> slice(int start, int
length) const{
return slice<Dynamic, Dynamic>(start, length);
}
@@ -170,22 +202,22 @@
return Matrix<Size, 1, Precision, Slice<Stride,1> >(data(),
size(), 1, stride(), 1, Slicing());
}
- typedef Vector<Size, Precision, SliceVBase<Stride> > as_slice_type;
+ typedef Vector<Size, Precision, SliceBase> as_slice_type;
- Vector<Size, Precision, SliceVBase<Stride> > as_slice(){
- return Vector<Size, Precision, SliceVBase<Stride> >(data(),
size(), stride(), Slicing());
+ Vector<Size, Precision, SliceBase> as_slice(){
+ return Vector<Size, Precision, SliceBase>(data(), size(),
stride(), Slicing());
}
- const Vector<Size, const Precision, SliceVBase<Stride> > as_slice()
const {
- return Vector<Size, const Precision, SliceVBase<Stride>
>(data(), size(), stride(), Slicing());
+ const Vector<Size, const Precision, ConstSliceBase> as_slice() const {
+ return Vector<Size, const Precision, ConstSliceBase>(data(),
size(), stride(), Slicing());
}
- DiagonalMatrix<Size,Precision, SliceVBase<Stride> > as_diagonal() {
- return DiagonalMatrix<Size, Precision, SliceVBase<Stride> >
(data(), size(), stride(), Slicing());
+ DiagonalMatrix<Size,Precision, SliceBase> as_diagonal() {
+ return DiagonalMatrix<Size, Precision, SliceBase> (data(),
size(), stride(), Slicing());
}
- const DiagonalMatrix<Size,const Precision, SliceVBase<Stride> >
as_diagonal() const {
- return DiagonalMatrix<Size, const Precision, SliceVBase<Stride>
> (data(), size(), stride(), Slicing());
+ const DiagonalMatrix<Size,const Precision, ConstSliceBase>
as_diagonal() const {
+ return DiagonalMatrix<Size, const Precision, ConstSliceBase>
(data(), size(), stride(), Slicing());
}
};
Index: allocator.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/allocator.hh,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -b -r1.37 -r1.38
--- allocator.hh 18 Jan 2010 15:32:13 -0000 1.37
+++ allocator.hh 1 Feb 2010 19:27:41 -0000 1.38
@@ -48,6 +48,15 @@
namespace Internal
{
+template<class Precision> struct DefaultTypes
+{
+ typedef Precision* PointerType;
+ typedef const Precision* ConstPointerType;
+ typedef Precision& ReferenceType;
+ typedef const Precision& ConstReferenceType;
+};
+
+
template<int Size, class Precision, bool heap> class StackOrHeap;
template<int Size, class Precision> class StackOrHeap<Size,Precision,0>
@@ -112,7 +121,7 @@
///The class switches to heap allocation automatically for large Vectors.
///Naturally, the vector is not resizable.
///@ingroup gInternal
-template<int Size, class Precision> struct VectorAlloc : public
StaticSizedAllocator<Size, Precision> {
+template<int Size, class Precision> struct VectorAlloc : public
StaticSizedAllocator<Size, Precision>, DefaultTypes<Precision> {
///Default constructor (only for statically sized vectors)
VectorAlloc() { }
@@ -158,14 +167,13 @@
template<class Op> void try_destructive_resize(const
Operator<Op>&)
{}
-
};
///@internal
///@brief Allocate memory for a dynamic sized Vector.
///This is not resizable.
///@ingroup gInternal
-template<class Precision> struct VectorAlloc<Dynamic, Precision> {
+template<class Precision> struct VectorAlloc<Dynamic, Precision>: public
DefaultTypes<Precision> {
Precision * const my_data;
const int my_size;
@@ -232,7 +240,7 @@
///New elements available after a resize are treated as
///uninitialized.
///@ingroup gInternal
-template<class Precision> struct VectorAlloc<Resizable, Precision> {
+template<class Precision> struct VectorAlloc<Resizable, Precision>: public
DefaultTypes<Precision> {
protected:
std::vector<Precision> numbers;
@@ -325,7 +333,8 @@
///@brief Hold a pointer to yield a statically sized slice of a Vector.
///Not resizable.
///@ingroup gInternal
-template<int S, class Precision> struct VectorSlice
+//template<int S, class Precision, class PtrType=Precision*, class
ConstPtrType=const Precision*, class RefType=Precision&, class
ConstRefType=const Precision&> struct VectorSlice
+template<int S, class Precision, class PtrType=Precision*, class
ConstPtrType=const Precision*, class RefType=Precision&, class
ConstRefType=const Precision&> struct VectorSlice
{
int size() const {
return S;
@@ -333,23 +342,23 @@
//Optional Constructors
- Precision* const my_data;
- VectorSlice(Precision* p)
+ const PtrType my_data;
+ VectorSlice(PtrType p)
:my_data(p){}
- VectorSlice(Precision* p, int /*size*/)
+ VectorSlice(PtrType p, int /*size*/)
:my_data(p){}
template<class Op>
VectorSlice(const Operator<Op>& op) : my_data(op.data()) {}
protected:
- Precision *data()
+ PtrType data()
{
return my_data;
};
- const Precision *data() const
+ ConstPtrType data() const
{
return my_data;
};
@@ -359,18 +368,24 @@
template<class Op> void try_destructive_resize(const
Operator<Op>&)
{}
+
+ public:
+ typedef PtrType PointerType;
+ typedef ConstPtrType ConstPointerType;
+ typedef RefType ReferenceType;
+ typedef ConstRefType ConstReferenceType;
};
///@internal
///@brief Hold a pointer to yield a dynamically sized slice of a Vector.
///Not resizable.
///@ingroup gInternal
-template<class Precision> struct VectorSlice<Dynamic, Precision>
+template<class Precision, class PtrType, class ConstPtrType, class RefType,
class ConstRefType> struct VectorSlice<Dynamic, Precision, PtrType,
ConstPtrType, RefType, ConstRefType>
{
- Precision* const my_data;
+ const PtrType my_data;
const int my_size;
- VectorSlice(Precision* d, int s)
+ VectorSlice(PtrType d, int s)
:my_data(d), my_size(s)
{ }
@@ -383,12 +398,12 @@
protected:
- Precision *data()
+ PtrType data()
{
return my_data;
};
- const Precision *data() const
+ ConstPtrType data() const
{
return my_data;
};
@@ -398,10 +413,13 @@
template<class Op> void try_destructive_resize(const
Operator<Op>&)
{}
-};
-
-
+ public:
+ typedef PtrType PointerType;
+ typedef ConstPtrType ConstPointerType;
+ typedef RefType ReferenceType;
+ typedef ConstRefType ConstReferenceType;
+};
////////////////////////////////////////////////////////////////////////////////
//
@@ -443,8 +461,6 @@
}
};
-
-
///@internal
///This struct holds the number of rows, only allocating space if
///necessary.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN/internal vbase.hh allocator.hh,
Edward Rosten <=