Manifold 3.0
Robust geometry
 
Loading...
Searching...
No Matches
optional_assert.h
1// Copyright 2022 The Manifold Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#ifdef MANIFOLD_DEBUG
18#include <iostream>
19#include <sstream>
20#include <stdexcept>
21#include <string>
22
26struct userErr : public virtual std::runtime_error {
27 using std::runtime_error::runtime_error;
28};
29struct topologyErr : public virtual std::runtime_error {
30 using std::runtime_error::runtime_error;
31};
32struct geometryErr : public virtual std::runtime_error {
33 using std::runtime_error::runtime_error;
34};
35using logicErr = std::logic_error;
36
37template <typename Ex>
38void AssertFail(const char* file, int line, const char* cond, const char* msg) {
39 std::ostringstream output;
40 output << "Error in file: " << file << " (" << line << "): \'" << cond
41 << "\' is false: " << msg;
42 throw Ex(output.str());
43}
44
45template <typename Ex>
46void AssertFail(const char* file, int line, const std::string& cond,
47 const std::string& msg) {
48 std::ostringstream output;
49 output << "Error in file: " << file << " (" << line << "): \'" << cond
50 << "\' is false: " << msg;
51 throw Ex(output.str());
52}
53
54// DEBUG_ASSERT is slightly slower due to the function call, but gives more
55// detailed info.
56#define DEBUG_ASSERT(condition, EX, msg) \
57 if (!(condition)) AssertFail<EX>(__FILE__, __LINE__, #condition, msg);
58// ASSERT has almost no overhead, so better to use for frequent calls like
59// vector bounds checking.
60#define ASSERT(condition, EX) \
61 if (!(condition)) throw(EX);
62#else
63#define DEBUG_ASSERT(condition, EX, msg)
64#define ASSERT(condition, EX)
65#endif
Definition optional_assert.h:32
Definition optional_assert.h:29
Definition optional_assert.h:26