internal/size_mismatch.hh

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<-1,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,-1>{
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<-1,-1>{
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 namespace Internal
00087 {
00088     struct BadSize;
00089 }
00090 
00091 template<int Size1, int Size2>
00092 struct SizeMismatch
00093 {
00094     static inline void test(int, int)
00095     {
00096         #ifdef TOON_TEST_INTERNALS
00097             throw Internal::StaticSizeMismatch();
00098         #else
00099             Internal::BadSize size_mismatch;
00100         #endif
00101     }
00102 };
00103 
00104 }

Generated on Thu May 7 20:28:40 2009 for TooN by  doxygen 1.5.3