68 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			68 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /**
 | |
|  * Copyright (c) 2022 Dominic Masters
 | |
|  * 
 | |
|  * This software is released under the MIT License.
 | |
|  * https://opensource.org/licenses/MIT
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| #include "dawnsharedlibs.hpp"
 | |
| 
 | |
| #define ASSERTS_ENABLED 1
 | |
| 
 | |
| #if ASSERTS_ENABLED == 0
 | |
| 
 | |
| static inline void assertTrue(bool_t x) {}
 | |
| 
 | |
| #elif ASSERTS_ENABLED == 1
 | |
| 
 | |
|   /**
 | |
|    * Assert a given value to be true.
 | |
|    * @param x Value to assert as true.
 | |
|    */
 | |
|   void assertTrue(bool_t x);
 | |
| 
 | |
|   /**
 | |
|    * Asserts a given statement to be false.
 | |
|    * @param x Value to assert as false.
 | |
|    */
 | |
|   void assertFalse(bool_t x);
 | |
| 
 | |
|   /**
 | |
|    * Asserts that a given line of code is unreachable. Essentially a forced
 | |
|    * assertion failure, good for "edge cases"
 | |
|    */
 | |
|   void assertUnreachable();
 | |
| 
 | |
|   /**
 | |
|    * Assert a given pointer to not point to a null pointer.
 | |
|    * @param pointer Pointer to assert is not a null pointer.
 | |
|    */
 | |
|   void assertNotNull(void *pointer);
 | |
| 
 | |
|   /**
 | |
|    * Asserts a given pointer to be a nullptr.
 | |
|    * @param pointer Pointer to assert is nullptr.
 | |
|    */
 | |
|   void assertNull(void *pointer);
 | |
| 
 | |
|   /**
 | |
|    * Asserts a function as being deprecated.
 | |
|    */
 | |
|   void assertDeprecated();
 | |
| 
 | |
|   /**
 | |
|    * Asserts that a given map has a key.
 | |
|    * 
 | |
|    * @param map Map to check.
 | |
|    * @param key Key to try and assert exists.
 | |
|    */
 | |
|   template<typename K, typename V>
 | |
|   void assertMapHasKey(std::map<K,V> map, K key) {
 | |
|     assertTrue(map.find(key) != map.end());
 | |
|   }
 | |
| #else
 | |
| 
 | |
|   #define assertTrue assert
 | |
| 
 | |
| #endif |