PixelLightAPI
.
|
00001 /*********************************************************\ 00002 * File: CompileError.h * 00003 * 00004 * Copyright (C) 2002-2012 The PixelLight Team (http://www.pixellight.org/) 00005 * 00006 * This file is part of PixelLight. 00007 * 00008 * PixelLight is free software: you can redistribute it and/or modify 00009 * it under the terms of the GNU Lesser General Public License as published by 00010 * the Free Software Foundation, either version 3 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * PixelLight is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public License 00019 * along with PixelLight. If not, see <http://www.gnu.org/licenses/>. 00020 \*********************************************************/ 00021 00022 00023 #ifndef __PLCORE_TOOLS_COMPILEERROR_H__ 00024 #define __PLCORE_TOOLS_COMPILEERROR_H__ 00025 #pragma once 00026 00027 00028 //[-------------------------------------------------------] 00029 //[ Includes ] 00030 //[-------------------------------------------------------] 00031 #include "PLCore/PLCore.h" 00032 00033 00034 //[-------------------------------------------------------] 00035 //[ Namespace ] 00036 //[-------------------------------------------------------] 00037 namespace PLCore { 00038 00039 00040 //[-------------------------------------------------------] 00041 //[ Classes ] 00042 //[-------------------------------------------------------] 00043 /** 00044 * @brief 00045 * Compile time error 00046 * 00047 * @remarks 00048 * Implementation for 'true', takes anything as parameter to the constructor and therefore raises no error 00049 */ 00050 template<bool> 00051 struct CompileTimeError 00052 { 00053 CompileTimeError(...) {} 00054 }; 00055 00056 /** 00057 * @brief 00058 * Compile time error 00059 * 00060 * @remarks 00061 * Implementation for 'false', raising an error as it has no constructor 00062 */ 00063 template<> 00064 struct CompileTimeError<false> 00065 { 00066 }; 00067 00068 00069 //[-------------------------------------------------------] 00070 //[ Namespace ] 00071 //[-------------------------------------------------------] 00072 } // PLCore 00073 00074 00075 //[-------------------------------------------------------] 00076 //[ Macros ] 00077 //[-------------------------------------------------------] 00078 /** 00079 * @brief 00080 * Raise error 00081 * 00082 * @param[in] error 00083 * Error message (must NOT be a string but a valid C++ identifier, such as My_Error_Message!) 00084 */ 00085 #define PLCORE_ERROR(error) \ 00086 { \ 00087 class ERROR_##error {}; \ 00088 ERROR_##error _error; \ 00089 PLCore::CompileTimeError<false> __error(_error); \ 00090 } 00091 00092 // (void)sizeof( PLCore::CompileTimeError<false>(ERROR_##error()) ); \ 00093 00094 /** 00095 * @brief 00096 * Raise error if expression is false 00097 * 00098 * @param[in] expr 00099 * Expression to check 00100 * @param[in] error 00101 * Error message (must NOT be a string but a valid C++ identifier, such as My_Error_Message!) 00102 */ 00103 #define PLCORE_CHECK(expr, error) \ 00104 { \ 00105 class ERROR_##error {}; \ 00106 ERROR_##error _error; \ 00107 PLCore::CompileTimeError<(expr)> __error(_error); \ 00108 } 00109 00110 00111 #endif // __PLCORE_TOOLS_COMPILEERROR_H__
|