toon-members
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Toon-members] TooN TooN.h helpers.h internal/operators.hh int...


From: Tom Drummond
Subject: [Toon-members] TooN TooN.h helpers.h internal/operators.hh int...
Date: Mon, 30 Mar 2009 21:22:39 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Tom Drummond <twd20>    09/03/30 21:22:39

Modified files:
        .              : TooN.h helpers.h 
        internal       : operators.hh vector.hh 

Log message:
        Introduced NoAliasOperator derived from Operator
        and convertible by NoAlias(...)
        
        Vector::operator= only takes a NoAliasOperator
        Vecotr() will take an Operator

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/TooN.h?cvsroot=toon&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/TooN/helpers.h?cvsroot=toon&r1=1.34&r2=1.35
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/operators.hh?cvsroot=toon&r1=1.24&r2=1.25
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/vector.hh?cvsroot=toon&r1=1.31&r2=1.32

Patches:
Index: TooN.h
===================================================================
RCS file: /cvsroot/toon/TooN/TooN.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- TooN.h      26 Mar 2009 15:13:16 -0000      1.28
+++ TooN.h      30 Mar 2009 21:22:31 -0000      1.29
@@ -68,6 +68,7 @@
        template<int Size, class Precision, class Base> struct Vector;
        template<int Rows, int Cols, class Precision, class Base> struct Matrix;
        template<typename T> class Operator;
+       template<typename T> class NoAliasOperator;
        template<typename T> class SliceSpec: public T{};
 
        static const int Dynamic = -1;

Index: helpers.h
===================================================================
RCS file: /cvsroot/toon/TooN/helpers.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -b -r1.34 -r1.35
--- helpers.h   30 Mar 2009 20:01:31 -0000      1.34
+++ helpers.h   30 Mar 2009 21:22:36 -0000      1.35
@@ -105,7 +105,7 @@
  };
 
 
-static Operator<Internal::Zero> Zero;
+static NoAliasOperator<Internal::Zero> Zero;
 static Operator<Internal::Identity> Identity;
 
 

Index: internal/operators.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/operators.hh,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -b -r1.24 -r1.25
--- internal/operators.hh       30 Mar 2009 20:01:32 -0000      1.24
+++ internal/operators.hh       30 Mar 2009 21:22:38 -0000      1.25
@@ -13,6 +13,15 @@
 
 template<class Op> struct Operator{};
 
+template<class Op> struct NoAliasOperator : public Operator<Op> {
+       NoAliasOperator(){}
+       explicit NoAliasOperator(const Operator<Op>& op) : Operator<Op>(op) {}
+};
+
+template<class Op> NoAliasOperator<Op> NoAlias(const Operator<Op>& op){
+       return NoAliasOperator<Op>(op);
+}
+
 namespace Internal{
        
        //Operator classes. These are evaluated in the constructor
@@ -186,16 +195,16 @@
        SizeMismatch<S1, S2>:: test(v1.size(),v2.size());
        const int S0=Internal::Sizer<S1,S2>::size;
        return 
Vector<S0,P0>(Operator<VPairwise<Internal::Add,S1,P1,B1,S2,P2,B2> >(v1,v2));
-       // return Vector<Internal::Sizer<S1,S2>::size,restype>(v1, v2, 
v1.size(), Operator<Internal::Pairwise<restype, Internal::Add> >());
 }
 
 // Addition Vector - Vector
 template<int S1, int S2, typename P1, typename P2, typename B1, typename B2> 
 Vector<Internal::Sizer<S1,S2>::size, typename Internal::SubtractType<P1, 
P2>::type> operator-(const Vector<S1, P1, B1>& v1, const Vector<S2, P2, B2>& v2)
 {
-       typedef typename Internal::SubtractType<P1, P2>::type restype;
+       typedef typename Internal::SubtractType<P1, P2>::type P0;
        SizeMismatch<S1, S2>:: test(v1.size(),v2.size());
-       return Vector<Internal::Sizer<S1,S2>::size,restype>(v1, v2, v1.size(), 
Operator<Internal::Pairwise<restype, Internal::Subtract> >());
+       const int S0=Internal::Sizer<S1,S2>::size;
+       return 
Vector<S0,P0>(Operator<VPairwise<Internal::Subtract,S1,P1,B1,S2,P2,B2> 
>(v1,v2));
 }
 
 // Dot product Vector * Vector

Index: internal/vector.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/vector.hh,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -b -r1.31 -r1.32
--- internal/vector.hh  30 Mar 2009 20:01:32 -0000      1.31
+++ internal/vector.hh  30 Mar 2009 21:22:38 -0000      1.32
@@ -53,7 +53,7 @@
 
        // assignment from a 0-ary operator
        template <class Op>
-       inline Vector & operator=(const Operator<Op>& op){
+       inline Vector & operator=(const NoAliasOperator<Op>& op){
                op.eval(*this);
                return *this;
        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]