80 lines
2.4 KiB
C++
80 lines
2.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"
|
|
|
|
/**
|
|
* Assert a given value to be true.
|
|
* @param x Value to assert as true.
|
|
* @param message Message to throw against assertion failure.
|
|
*/
|
|
void assertTrue(bool_t x, const char message[]);
|
|
void assertTrue(bool_t x, std::string message);
|
|
|
|
/**
|
|
* Asserts a given statement to be false.
|
|
* @param x Value to assert as false.
|
|
* @param message Message to throw against assertion failure.
|
|
*/
|
|
void assertFalse(bool_t x, const char message[]);
|
|
void assertFalse(bool_t x, std::string message);
|
|
|
|
/**
|
|
* Asserts that a given line of code is unreachable. Essentially a forced
|
|
* assertion failure, good for "edge cases"
|
|
* @param message Message to throw against assertion failure.
|
|
*/
|
|
void assertUnreachable(const char message[]);
|
|
void assertUnreachable(std::string message);
|
|
|
|
/**
|
|
* Assert a given pointer to not point to a null pointer.
|
|
* @param pointer Pointer to assert is not a null pointer.
|
|
* @param message Message to throw against assertion failure.
|
|
*/
|
|
void assertNotNull(void *pointer, const char message[]);
|
|
void assertNotNull(void *pointer, std::string message);
|
|
|
|
/**
|
|
* Asserts a given pointer to be a nullptr.
|
|
* @param pointer Pointer to assert is nullptr.
|
|
* @param message Message to throw against assertion failure.
|
|
*/
|
|
void assertNull(void *pointer, const char message[]);
|
|
void assertNull(void *pointer, std::string message);
|
|
|
|
/**
|
|
* Asserts a function as being deprecated.
|
|
* @param message Message to throw against assertion failure.
|
|
*/
|
|
void assertDeprecated(const char message[]);
|
|
void assertDeprecated(std::string message);
|
|
|
|
/**
|
|
* Asserts that a given map has a key.
|
|
*
|
|
* @param map Map to check.
|
|
* @param key Key to try and assert exists.
|
|
* @param message Message to throw against assertion failure.
|
|
*/
|
|
template<typename K, typename V>
|
|
void assertMapHasKey(std::map<K,V> map, K key, const char message[]) {
|
|
assertTrue(map.find(key) != map.end(), message);
|
|
}
|
|
|
|
/**
|
|
* Asserts that a given map has a key.
|
|
*
|
|
* @param map Map to check.
|
|
* @param key Key to try and assert exists.
|
|
* @param message Message to throw against assertion failure.
|
|
*/
|
|
template<typename K, typename V>
|
|
void assertMapHasKey(std::map<K,V> map, K key, std::string message) {
|
|
assertMapHasKey(map, key, message.c_str());
|
|
} |