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 namespace TooN {
00031
00032 namespace Internal
00033 {
00034 template<bool StaticBad>
00035 struct BadSlice;
00036
00044 template<>
00045 struct BadSlice<0>{
00046 static void check(){}
00047 };
00048
00057 template<int Size, int Start, int Length>
00058 struct CheckSlice
00059 {
00060
00063 template<int Num> struct N
00064 {
00065 static int n(int num)
00066 {
00067 return Num==Dynamic?num:Num;
00068 }
00069 };
00070
00077 static void check()
00078 {
00079
00080 BadSlice<!(Size== Dynamic || Size > 0)>::check();
00081 BadSlice<!(Start >= 0)>::check();
00082 BadSlice<!(Length > 0)>::check();
00083 BadSlice<(Size != Dynamic && (Start + Length > Size))>::check();
00084 }
00085
00095 static void check(int size, int start, int length)
00096 {
00097
00098 BadSlice<!(Size == Dynamic || Size > 0)>::check();
00099 BadSlice<!(Start == Dynamic || Start >= 0)>::check();
00100 BadSlice<!(Length == Dynamic || Length > 0)>::check();
00101
00102
00103 BadSlice<(Size!=Dynamic && Length != Dynamic && Length > Size)>::check();
00104
00105
00106 BadSlice<(Start != Dynamic && Size != Dynamic && Start >= Size)>::check();
00107
00108 BadSlice<(Size != Dynamic && Start != Dynamic && Length != Dynamic && Start + Length > Size)>::check();
00109 #ifndef TOON_NDEBUG_MISMATCH
00110 if(Start != Dynamic && Start != start)
00111 {
00112 std::cerr << "TooN slice: mismatch between static and dynamic start.\n";
00113 std::abort();
00114 }
00115 if(Length != Dynamic && Length != length)
00116 {
00117 std::cerr << "TooN slice: mismatch between static and dynamic length.\n";
00118 std::abort();
00119 }
00120 if(Size != Dynamic && Size != size)
00121 {
00122 std::cerr << "TooN slice: mismatch between static and dynamic size.\n";
00123 std::abort();
00124 }
00125 #endif
00126 if( N<Start>::n(start) + N<Length>::n(length) > N<Size>::n(size) ||
00127 N<Start>::n(start) < 0 ||
00128 N<Length>::n(length) < 0)
00129 {
00130 #ifdef TOON_TEST_INTERNALS
00131 throw Internal::SliceError();
00132 #elif !defined TOON_NDEBUG_SLICE
00133 std::cerr << "TooN slice out of range" << std::endl;
00134 std::abort();
00135 #endif
00136 }
00137 }
00138 };
00139
00140 #ifdef TOON_TEST_INTERNALS
00141 template<bool StaticBad>
00142 struct BadSlice{
00143 static void check(){
00144 throw Internal::StaticSliceError();
00145 }
00146 };
00147 #endif
00148 }
00149
00150 }