TooN 2.1
|
00001 // -*- c++ -*- 00002 00003 // Copyright (C) 2009 Tom Drummond (twd20@cam.ac.uk), 00004 // Ed Rosten (er258@cam.ac.uk) 00005 // 00006 // This file is part of the TooN Library. This library is free 00007 // software; you can redistribute it and/or modify it under the 00008 // terms of the GNU General Public License as published by the 00009 // Free Software Foundation; either version 2, or (at your option) 00010 // any later version. 00011 00012 // This library is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 00017 // You should have received a copy of the GNU General Public License along 00018 // with this library; see the file COPYING. If not, write to the Free 00019 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00020 // USA. 00021 00022 // As a special exception, you may use this file as part of a free software 00023 // library without restriction. Specifically, if other files instantiate 00024 // templates or use macros or inline functions from this file, or you compile 00025 // this file and link it with other files to produce an executable, this 00026 // file does not by itself cause the resulting executable to be covered by 00027 // the GNU General Public License. This exception does not however 00028 // invalidate any other reasons why the executable file might be covered by 00029 // the GNU General Public License. 00030 00031 namespace TooN { 00032 00033 // class to generate compile time error 00034 // general case which doesn't exist 00035 template<int Size1, int Size2> 00036 struct SizeMismatch_; 00037 00038 // special cases which do exist 00039 template<int Size> 00040 struct SizeMismatch_<Size,Size>{ 00041 static inline void test(int, int){} 00042 }; 00043 00044 template<int Size> 00045 struct SizeMismatch_<Dynamic,Size>{ 00046 static inline void test(int size1, int size2){ 00047 if(size1!=size2){ 00048 #ifdef TOON_TEST_INTERNALS 00049 throw Internal::SizeMismatch(); 00050 #elif !defined TOON_NDEBUG_SIZE 00051 std::cerr << "TooN Size Mismatch" << std::endl; 00052 std::abort(); 00053 #endif 00054 } 00055 } 00056 }; 00057 00058 template<int Size> 00059 struct SizeMismatch_<Size,Dynamic>{ 00060 static inline void test(int size1, int size2){ 00061 if(size1!=size2){ 00062 #ifdef TOON_TEST_INTERNALS 00063 throw Internal::SizeMismatch(); 00064 #elif !defined TOON_NDEBUG_SIZE 00065 std::cerr << "TooN Size Mismatch" << std::endl; 00066 std::abort(); 00067 #endif 00068 } 00069 } 00070 }; 00071 00072 template <> 00073 struct SizeMismatch_<Dynamic,Dynamic>{ 00074 static inline void test(int size1, int size2){ 00075 if(size1!=size2){ 00076 #ifdef TOON_TEST_INTERNALS 00077 throw Internal::SizeMismatch(); 00078 #elif !defined TOON_NDEBUG_SIZE 00079 std::cerr << "TooN Size Mismatch" << std::endl; 00080 std::abort(); 00081 #endif 00082 } 00083 } 00084 }; 00085 00086 #if 0 00087 namespace Internal 00088 { 00089 struct BadSize; 00090 } 00091 #endif 00092 00093 #ifdef TOON_TEST_INTERNALS 00094 template<int Size1, int Size2> 00095 struct SizeMismatch_ 00096 { 00097 static inline void test(int, int) 00098 { 00099 throw Internal::StaticSizeMismatch(); 00100 } 00101 }; 00102 #endif 00103 00104 template<int Size1, int Size2> 00105 struct SizeMismatch 00106 { 00107 static inline void test(int s1, int s2) 00108 { 00109 SizeMismatch_< (Size1 == Dynamic || Size1 == Resizable)?Dynamic:Size1, 00110 (Size2 == Dynamic || Size2 == Resizable)?Dynamic:Size2 >::test(s1, s2); 00111 } 00112 }; 00113 00114 }