From f0f95c1714500f1cb39af4a48167e1c9be668bbb Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 5 Mar 2018 23:07:04 -0600 Subject: [PATCH] Add ox_assert to ox/std (synced from b616d9c0f215d7a7a93114a97096a1f4374560d5) --- src/ox/std/CMakeLists.txt | 2 ++ src/ox/std/assert.cpp | 19 +++++++++++++++++++ src/ox/std/assert.hpp | 17 +++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 src/ox/std/assert.cpp create mode 100644 src/ox/std/assert.hpp diff --git a/src/ox/std/CMakeLists.txt b/src/ox/std/CMakeLists.txt index f30a34815..7ecff3783 100644 --- a/src/ox/std/CMakeLists.txt +++ b/src/ox/std/CMakeLists.txt @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8) add_library( OxStd + assert.cpp memops.cpp random.cpp strops.cpp @@ -16,6 +17,7 @@ set_property( install( FILES + assert.hpp bitops.hpp byteswap.hpp memops.hpp diff --git a/src/ox/std/assert.cpp b/src/ox/std/assert.cpp new file mode 100644 index 000000000..1778ea6dc --- /dev/null +++ b/src/ox/std/assert.cpp @@ -0,0 +1,19 @@ +/* + * Copyright 2015 - 2018 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#if defined(OX_USE_STDLIB) +#include +#include +#endif + +void oxAssert(const char *file, int line, bool pass, const char *msg) { + if (!pass) { + std::cerr << '(' << file << ':' << line << "): " << msg << std::endl; + std::abort(); + } +} \ No newline at end of file diff --git a/src/ox/std/assert.hpp b/src/ox/std/assert.hpp new file mode 100644 index 000000000..6c0fe8b11 --- /dev/null +++ b/src/ox/std/assert.hpp @@ -0,0 +1,17 @@ +/* + * Copyright 2015 - 2018 gtalent2@gmail.com + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +void oxAssert(const char *file, int line, bool pass, const char *msg); + +#ifdef NDEBUG +#define ox_assert(pass, msg) oxAssert(__FILE__, __LINE__, pass, msg) +#else +#define ox_assert(pass, msg) +#endif \ No newline at end of file