Selaa lähdekoodia

Add initial ce_assert() implementation

Daniele Bartolini 12 vuotta sitten
vanhempi
sitoutus
9958b3be73
5 muutettua tiedostoa jossa 48 lisäystä ja 0 poistoa
  1. 3 0
      CMakeLists.txt
  2. 1 0
      src/CMakeLists.txt
  3. 1 0
      src/Config.h.in
  4. 1 0
      src/Crown.h
  5. 42 0
      src/core/Assert.h

+ 3 - 0
CMakeLists.txt

@@ -101,3 +101,6 @@ if (CROWN_BUILD_TESTS)
 	add_subdirectory(tests)
 endif (CROWN_BUILD_TESTS)
 
+# always debug mode for now
+set (CROWN_DEBUG)
+

+ 1 - 0
src/CMakeLists.txt

@@ -47,6 +47,7 @@ set (CORE_SRC
 )
 
 set (CORE_HEADERS
+	core/Assert.h
 	core/Types.h
 	core/Args.h
 	core/Log.h

+ 1 - 0
src/Config.h.in

@@ -33,6 +33,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #cmakedefine CROWN_BUILD_OPENGL
 #cmakedefine CROWN_BUILD_OPENGLES
 #cmakedefine CROWN_USE_FLOAT
+#cmakedefine CROWN_DEBUG
 
 // OS peculiarities
 #if defined(LINUX) || defined(ANDROID)

+ 1 - 0
src/Crown.h

@@ -26,6 +26,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 #pragma once
 
 // Core
+#include "Assert.h"
 #include "Types.h"
 #include "Args.h"
 #include "Log.h"

+ 42 - 0
src/core/Assert.h

@@ -0,0 +1,42 @@
+/*
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "Config.h"
+#include "OS.h"
+
+#pragma once
+
+#ifdef CROWN_DEBUG
+	#define ce_assert(condition, message, ...)\
+	\
+		do\
+		{\
+			os::printf("Assertion failed: %s\n\t" message, #condition, __VA_ARGS__);\
+			os::printf("\n");
+			abort();\
+		} while (0)
+#else
+	#define ce_assert(condition, message, ...) ((void)0)
+#endif