Updated locale gen
This commit is contained in:
9
src/dawnshared/assert/CMakeLists.txt
Normal file
9
src/dawnshared/assert/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
# Copyright (c) 2022 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
assert.cpp
|
||||
)
|
40
src/dawnshared/assert/assert.cpp
Normal file
40
src/dawnshared/assert/assert.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Copyright (c) 2022 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assert.hpp"
|
||||
|
||||
#if ASSERTS_ENABLED == 0
|
||||
|
||||
#elif ASSERTS_ENABLED == 1
|
||||
void assertTrue(bool_t x) {
|
||||
if(x != true) {
|
||||
throw "Assertion Failed";
|
||||
free(0);
|
||||
}
|
||||
assert(x == true);
|
||||
}
|
||||
|
||||
void assertFalse(bool_t x) {
|
||||
assertTrue(!x);
|
||||
}
|
||||
|
||||
void assertUnreachable() {
|
||||
assertTrue(false);
|
||||
}
|
||||
|
||||
void assertNotNull(void *pointer) {
|
||||
assertTrue(pointer != nullptr && pointer != NULL);
|
||||
}
|
||||
|
||||
void assertNull(void *pointer) {
|
||||
assertTrue(pointer == NULL || pointer == nullptr);
|
||||
}
|
||||
|
||||
void assertDeprecated() {
|
||||
assertUnreachable();
|
||||
}
|
||||
#endif
|
68
src/dawnshared/assert/assert.hpp
Normal file
68
src/dawnshared/assert/assert.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* 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
|
Reference in New Issue
Block a user