toon-members
[Top][All Lists]
Advanced

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

[Toon-members] TooN/internal comma.hh overfill_error.hh


From: Edward Rosten
Subject: [Toon-members] TooN/internal comma.hh overfill_error.hh
Date: Thu, 18 Jun 2009 15:30:48 +0000

CVSROOT:        /cvsroot/toon
Module name:    TooN
Changes by:     Edward Rosten <edrosten>        09/06/18 15:30:48

Added files:
        internal       : comma.hh overfill_error.hh 

Log message:
        Added missing files from the last commit.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/comma.hh?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/overfill_error.hh?cvsroot=toon&rev=1.1

Patches:
Index: comma.hh
===================================================================
RCS file: comma.hh
diff -N comma.hh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ comma.hh    18 Jun 2009 15:30:47 -0000      1.1
@@ -0,0 +1,152 @@
+namespace TooN{
+
+
+
+namespace Internal
+{
+       template<int N, int Size, class P, class B> struct VectorFiller
+       {
+               Vector<Size, P, B>& v;
+               VectorFiller<N-1, Size, P, B>* parent;
+               bool underfill;
+
+               VectorFiller(Vector<Size, P, B>& v_, VectorFiller<N-1, Size, P, 
B>* p)
+               :v(v_),parent(p),underfill(N<v.size())
+               {
+               }
+
+               VectorFiller<N+1, Size, P, B> operator,(const P& p)
+               {
+                       Internal::CheckOverFill<N, Size>::check(v.size());
+                       v[N] = p;
+                       return VectorFiller<N+1, Size, P, B>(v, this);
+               }
+
+               ~VectorFiller()
+               {
+                       #ifndef TOON_NDEBUG_FILL
+                               if(underfill)
+                               {
+                                       #ifdef TOON_TEST_INTERNALS
+                                               throw Internal::Underfill();
+                                       #else
+                                               std::cerr << "TooN: underfilled 
vector\n";
+                                               std::abort();
+                                       #endif
+                               }
+                               else if(parent)
+                                       parent->underfill = 0;
+                       #endif
+               }
+       };
+
+       template<int Size, class P, class B> struct VectorStartFill
+       {
+               Vector<Size, P, B>& v;
+               VectorStartFill(Vector<Size, P, B> & v_)
+               :v(v_){}
+
+               VectorFiller<1, Size, P, B> operator=(const P& p)
+               {
+                       Internal::CheckOverFill<1, Size>::check(v.size());
+                       v[0] = p;
+                       return VectorFiller<1, Size, P, B>(v, 0);
+               }
+       };
+
+
+       template<int N, int R, int C, class P, class B> struct MatrixFiller
+       {
+               Matrix<R, C, P, B>& m;
+               MatrixFiller<N-1, R, C, P, B>* parent;
+               int r, c;
+               bool underfill;
+
+               MatrixFiller(Matrix<R, C, P, B>& m_, MatrixFiller<N-1, R, C, P, 
B>*p, int r_, int c_)
+               :m(m_),parent(p),r(r_),c(c_),underfill(r < m.num_rows())
+               {}
+
+               MatrixFiller<N+1, R, C, P, B> operator,(const P& p)
+               {
+                       Internal::CheckMOverFill<N, R, C>::check(m.num_rows() * 
m.num_cols());
+                       m[r][c] = p;
+                       c++;
+                       if(c == m.num_rows())
+                       {
+                               c=0;
+                               r++;
+                       }               
+
+                       return MatrixFiller<N+1, R, C, P, B>(m, this, r, c);
+               }
+
+               ~MatrixFiller()
+               {
+                       #ifndef TOON_NDEBUG_FILL
+                               if(underfill)
+                               {
+                                       #ifdef TOON_TEST_INTERNALS
+                                               throw Internal::Underfill();
+                                       #else
+                                               std::cerr << "TooN: underfilled 
matrix\n";
+                                               std::abort();
+                                       #endif
+                               }
+                               else if(parent)
+                                       parent->underfill = 0;
+                       #endif
+               }
+       };
+
+       template<int R, int C, class P, class B> struct MatrixStartFill
+       {
+               Matrix<R, C, P, B>& m;
+               MatrixStartFill(Matrix<R, C, P, B> & m_)
+               :m(m_){}
+
+               MatrixFiller<1, R, C, P, B> operator=(const P& p)
+               {
+                       Internal::CheckMOverFill<0, R, C>::check(m.num_rows() * 
m.num_cols());
+                       m[0][0] = p;
+                       return MatrixFiller<1, R, C, P, B>(m, 0, 0, 1);
+               }
+       };
+
+}
+
+/**Set up a matrix for filling. Uses the following syntax:
address@hidden
+       Matrix<2,2> m;
+       Fill(m) = 1, 2,
+                 3, 4;
address@hidden
+Overfill is detected at compile time if possible, underfill
+is detected at run-time. The checks can not be optimized out
+for dynamic matrices, so define \c TOON_NDEBUG_FILL to prevent
+the checks from being used.
address@hidden m Matrix to fill
address@hidden gLinAlg
+*/
+template<int R, int C, class Precision, class Base> 
Internal::MatrixStartFill<R, C, Precision, Base> Fill(Matrix<R, C, Precision, 
Base>& m)
+{
+       return m;
+}
+
+/**Set up a vector for filling. Uses the following syntax:
address@hidden
+       Vector<2> v;
+       Fill(v) = 1, 2;
address@hidden
+Overfill is detected at compile time if possible, underfill
+is detected at run-time. The checks can not be optimized out
+for dynamic vectors, so define \c TOON_NDEBUG_FILL to prevent
+the checks from being used.
address@hidden m Matrix to fill
address@hidden gLinAlg
+*/
+template<int Size, class Precision, class Base> 
Internal::VectorStartFill<Size, Precision, Base> Fill(Vector<Size, Precision, 
Base>& v)
+{
+       return v;
+}
+
+}

Index: overfill_error.hh
===================================================================
RCS file: overfill_error.hh
diff -N overfill_error.hh
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ overfill_error.hh   18 Jun 2009 15:30:48 -0000      1.1
@@ -0,0 +1,68 @@
+namespace TooN{
+namespace Internal{
+
+template<bool b> struct overfill;
+template<> struct overfill<0>{};
+
+template<int N, int Size> struct CheckOverFill
+{
+       static void check(int)
+       {
+               #ifdef TOON_TEST_INTERNALS
+                       if(N >= Size)
+                               throw StaticVectorOverfill();
+               #else
+                       Internal::overfill<(N>=Size)> overfilled_vector;
+               #endif
+       };
+};
+
+template<int N> struct CheckOverFill<N, -1>
+{
+       static void check(int s)
+       {
+               #ifdef TOON_TEST_INTERNALS
+                       if(N >= s)
+                               throw VectorOverfill();
+               #elif !defined TOON_NDEBUG_FILL
+                       if(N >= s)
+                       {
+                               std::cerr << "TooN overfilled vector" << 
std::endl;
+                               std::abort();
+                       }
+               #endif
+       };
+};
+
+
+template<int N, int R, int C, bool IsDynamic=(R==-1||C==-1)> struct 
CheckMOverFill
+{
+       static void check(int)
+       {
+               #ifdef TOON_TEST_INTERNALS
+                       if(N >= R*C)
+                               throw StaticMatrixOverfill();
+               #else
+                       Internal::overfill<(N>=R*C)> overfilled_matrix;
+               #endif
+       }
+};
+
+template<int N, int R, int C> struct CheckMOverFill<N, R, C, 1>
+{
+       static void check(int s)
+       {
+               #ifdef TOON_TEST_INTERNALS
+                       if(N >= s)
+                               throw StaticMatrixOverfill();
+               #else
+                       if(N >= s)
+                       {
+                               std::cerr << "TooN overfilled matrix" << 
std::endl;
+                               std::abort();
+                       }
+               #endif
+       }
+};
+
+}}




reply via email to

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