[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN TooN.h internal/debug.hh internal/slice_er...
From: |
Edward Rosten |
Subject: |
[Toon-members] TooN TooN.h internal/debug.hh internal/slice_er... |
Date: |
Fri, 09 Jan 2009 16:23:44 +0000 |
CVSROOT: /cvsroot/toon
Module name: TooN
Changes by: Edward Rosten <edrosten> 09/01/09 16:23:44
Modified files:
. : TooN.h
internal : debug.hh slice_error.hh
Added files:
internal : size_mismatch.hh
Removed files:
internal : size_assert.hh
Log message:
Moved size_assert to size_mismatch for better error messages.
Added internals testing, with TOON_TEST_INTERNALS defined.
This throws, instead of aborting, including on compile-time errors.
This
allows for handy test programs.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/TooN.h?cvsroot=toon&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/debug.hh?cvsroot=toon&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/slice_error.hh?cvsroot=toon&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/size_mismatch.hh?cvsroot=toon&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/TooN/internal/size_assert.hh?cvsroot=toon&r1=1.1&r2=0
Patches:
Index: TooN.h
===================================================================
RCS file: /cvsroot/toon/TooN/TooN.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- TooN.h 9 Jan 2009 14:24:02 -0000 1.13
+++ TooN.h 9 Jan 2009 16:23:43 -0000 1.14
@@ -5,7 +5,19 @@
#include <cstdlib>
namespace TooN
{
- #include <TooN/internal/size_assert.hh>
+ #ifdef TOON_TEST_INTERNALS
+ namespace Internal
+ {
+ struct BadIndex{};
+ struct SliceError{};
+ struct StaticSliceError{};
+ struct SizeMismatch{};
+ struct StaticSizeMismatch{};
+ }
+
+ #endif
+
+ #include <TooN/internal/size_mismatch.hh>
#include <TooN/internal/slice_error.hh>
#include <TooN/internal/debug.hh>
#include <TooN/internal/vector.hh>
Index: internal/debug.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/debug.hh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- internal/debug.hh 9 Jan 2009 14:24:03 -0000 1.1
+++ internal/debug.hh 9 Jan 2009 16:23:43 -0000 1.2
@@ -1,12 +1,19 @@
namespace Internal
{
- static inline void check_index(int i, int s)
+
+
+
+ static inline void check_index(int s, int i)
{
- #ifdef TOON_CHECK_BOUNDS
+ #if defined TOON_CHECK_BOUNDS || defined TOON_TEST_INTERNALS
if(i<0 || i >= s)
{
+ #ifdef TOON_TEST_INTERNALS
+ throw Internal::BadIndex();
+ #else
std::cerr << "Toon index out of range" <<
std::endl;
std::abort();
+ #endif
}
#endif
}
Index: internal/slice_error.hh
===================================================================
RCS file: /cvsroot/toon/TooN/internal/slice_error.hh,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- internal/slice_error.hh 9 Jan 2009 14:24:03 -0000 1.1
+++ internal/slice_error.hh 9 Jan 2009 16:23:43 -0000 1.2
@@ -24,12 +24,25 @@
{
if(start + length >= size)
{
+ #ifdef TOON_TEST_INTERNALS
+ throw Internal::SliceError();
+ #else
std::cerr << "Toon slice out of range" <<
std::endl;
std::abort();
+ #endif
}
}
};
+ #ifdef TOON_TEST_INTERNALS
+ template<int Size, bool StaticBad>
+ struct BadSlice{
+ static void check(){
+ throw Internal::StaticSliceError();
+ }
+ };
+ #endif
+
}
Index: internal/size_mismatch.hh
===================================================================
RCS file: internal/size_mismatch.hh
diff -N internal/size_mismatch.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ internal/size_mismatch.hh 9 Jan 2009 16:23:43 -0000 1.1
@@ -0,0 +1,66 @@
+// -*- c++ -*-
+
+// class to generate compile time error
+// general case which doesn't exist
+template<int Size1, int Size2>
+struct SizeMismatch;
+
+// special cases which do exist
+template<int Size>
+struct SizeMismatch<Size,Size>{
+ static inline void test(int size1, int size2){}
+};
+
+template<int Size>
+struct SizeMismatch<-1,Size>{
+ static inline void test(int size1, int size2){
+ if(size1!=size2){
+ #ifdef TOON_TEST_INTERNALS
+ throw Internal::SizeMismatch();
+ #else
+ std::cerr << "Toon Size Mismatch" << std::endl;
+ std::abort();
+ #endif
+ }
+ }
+};
+
+template<int Size>
+struct SizeMismatch<Size,-1>{
+ static inline void test(int size1, int size2){
+ if(size1!=size2){
+ #ifdef TOON_TEST_INTERNALS
+ throw Internal::SizeMismatch();
+ #else
+ std::cerr << "Toon Size Mismatch" << std::endl;
+ std::abort();
+ #endif
+ }
+ }
+};
+
+template <>
+struct SizeMismatch<-1,-1>{
+ static inline void test(int size1, int size2){
+ if(size1!=size2){
+ #ifdef TOON_TEST_INTERNALS
+ throw Internal::SizeMismatch();
+ #else
+ std::cerr << "Toon Size Mismatch" << std::endl;
+ std::abort();
+ #endif
+ }
+ }
+};
+
+
+#ifdef TOON_TEST_INTERNALS
+ template<int Size1, int Size2>
+ struct SizeMismatch
+ {
+ static inline void test(int, int)
+ {
+ throw Internal::StaticSizeMismatch();
+ }
+ };
+#endif
Index: internal/size_assert.hh
===================================================================
RCS file: internal/size_assert.hh
diff -N internal/size_assert.hh
--- internal/size_assert.hh 9 Jan 2009 14:24:03 -0000 1.1
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,44 +0,0 @@
-// -*- c++ -*-
-
-// class to generate compile time error
-// general case which doesn't exist
-template<int Size1, int Size2>
-struct SizeMismatch;
-
-// special cases which do exist
-template<int Size>
-struct SizeMismatch<Size,Size>{
- static inline void test(int size1, int size2){}
-};
-
-template<int Size>
-struct SizeMismatch<-1,Size>{
- static inline void test(int size1, int size2){
- if(size1!=size2){
- std::cerr << "Toon Size Mismatch" << std::endl;
- std::abort();
- }
- }
-};
-
-template<int Size>
-struct SizeMismatch<Size,-1>{
- static inline void test(int size1, int size2){
- if(size1!=size2){
- std::cerr << "Toon Size Mismatch" << std::endl;
- std::abort();
- }
- }
-};
-
-template <>
-struct SizeMismatch<-1,-1>{
- static inline void test(int size1, int size2){
- if(size1!=size2){
- std::cerr << "Toon Size Mismatch" << std::endl;
- std::abort();
- }
- }
-};
-
-
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN TooN.h internal/debug.hh internal/slice_er...,
Edward Rosten <=