00001 // @(#)root/smatrix:$Id: StaticCheck.h 34815 2010-08-16 09:36:00Z rdm $ 00002 // Authors: T. Glebe, L. Moneta 2005 00003 00004 00005 //////////////////////////////////////////////////////////////////////////////// 00006 // The Loki Library 00007 // Copyright (c) 2001 by Andrei Alexandrescu 00008 // This code accompanies the book: 00009 // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design 00010 // Patterns Applied". Copyright (c) 2001. Addison-Wesley. 00011 // Permission to use, copy, modify, distribute and sell this software for any 00012 // purpose is hereby granted without fee, provided that the above copyright 00013 // notice appear in all copies and that both that copyright notice and this 00014 // permission notice appear in supporting documentation. 00015 // The author or Addison-Wesley Longman make no representations about the 00016 // suitability of this software for any purpose. It is provided "as is" 00017 // without express or implied warranty. 00018 //////////////////////////////////////////////////////////////////////////////// 00019 00020 // Last update: June 20, 2001 00021 00022 #ifndef Root_Math_StaticCheck 00023 #define Root_Math_StaticCheck 00024 00025 00026 // case of dictionary generator 00027 #if defined(__MAKECINT__) || defined(G__DICTIONARY) 00028 00029 #include "Math/MConfig.h" 00030 #include <iostream> 00031 #include <cassert> 00032 00033 #define STATIC_CHECK(expr, msg) \ 00034 if (!(expr) ) std::cerr << "ERROR: " << #msg << std::endl; \ 00035 assert(expr); 00036 00037 #else 00038 00039 namespace ROOT 00040 { 00041 00042 namespace Math { 00043 00044 #ifndef USE_OLD_SC 00045 00046 00047 template<bool> struct CompileTimeChecker 00048 { 00049 CompileTimeChecker(void *) {} 00050 }; 00051 template<> struct CompileTimeChecker<false> {}; 00052 00053 } // end namespace Math 00054 } // end namespace ROOT 00055 00056 #define STATIC_CHECK(expr, msg) \ 00057 { class ERROR_##msg {}; \ 00058 ERROR_##msg e; \ 00059 (void) (ROOT::Math::CompileTimeChecker<(expr) != 0> (&e)); } 00060 00061 00062 #else 00063 //////////////////////////////////////////////////////////////////////////////// 00064 // Helper structure for the STATIC_CHECK macro 00065 //////////////////////////////////////////////////////////////////////////////// 00066 00067 template<int> struct CompileTimeError; 00068 template<> struct CompileTimeError<true> {}; 00069 00070 } // end namespace Math 00071 } // end namespace ROOT 00072 00073 //////////////////////////////////////////////////////////////////////////////// 00074 // macro STATIC_CHECK 00075 // Invocation: STATIC_CHECK(expr, id) 00076 // where: 00077 // expr is a compile-time integral or pointer expression 00078 // id is a C++ identifier that does not need to be defined 00079 // If expr is zero, id will appear in a compile-time error message. 00080 //////////////////////////////////////////////////////////////////////////////// 00081 00082 #define STATIC_CHECK(expr, msg) \ 00083 { ROOT::Math::CompileTimeError<((expr) != 0)> ERROR_##msg; (void)ERROR_##msg; } 00084 00085 00086 //////////////////////////////////////////////////////////////////////////////// 00087 // Change log: 00088 // March 20, 2001: add extra parens to STATIC_CHECK - it looked like a fun 00089 // definition 00090 // June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! 00091 //////////////////////////////////////////////////////////////////////////////// 00092 00093 #endif 00094 00095 #endif 00096 00097 #endif // STATIC_CHECK_INC_