Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfError.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of Tissue Forge.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
25#ifndef _SOURCE_TFERROR_H_
26#define _SOURCE_TFERROR_H_
27
28#include <tf_port.h>
29
30#include <exception>
31#include <string>
32#include <vector>
33
34
35namespace TissueForge {
36
37
38 struct CAPI_EXPORT Error {
41
43 std::string msg;
44
46 int lineno;
47
49 std::string fname;
50
52 std::string func;
53 };
54
56 typedef void (*ErrorCallback)(const Error &err);
57
64 CPPAPI_FUNC(unsigned int) addErrorCallback(ErrorCallback &cb);
65
71 CPPAPI_FUNC(HRESULT) removeErrorCallback(const unsigned int &cb_id);
72
77
78 #define tf_error(code, msg) errSet(code, msg, __LINE__, __FILE__, TF_FUNCTION)
79
80 #define tf_exp(e) expSet(e, "", __LINE__, __FILE__, TF_FUNCTION)
81
82 #define TF_RETURN_EXP(e) expSet(e, "", __LINE__, __FILE__, TF_FUNCTION); return NULL
83
87 CPPAPI_FUNC(HRESULT) errSet(HRESULT code, const char* msg, int line, const char* file, const char* func);
88
92 CPPAPI_FUNC(HRESULT) expSet(const std::exception&, const char* msg, int line, const char* file, const char* func);
93
97 CPPAPI_FUNC(bool) errOccurred();
98
102 CPPAPI_FUNC(void) errClear();
103
107 CPPAPI_FUNC(std::string) errStr(const Error &err);
108
112 CPPAPI_FUNC(std::vector<Error>) errGetAll();
113
117 CPPAPI_FUNC(Error) errGetFirst();
118
122 CPPAPI_FUNC(void) errClearFirst();
123
127 CPPAPI_FUNC(Error) errPopFirst();
128
129};
130
131inline std::ostream& operator<<(std::ostream& os, const TissueForge::Error &err)
132{
133 os << std::string("Code: ");
134 os << std::to_string(err.err);
135 os << std::string(", Msg: ");
136 os << err.msg;
137 os << std::string(", File: ");
138 os << err.fname;
139 os << std::string(", Line: ");
140 os << std::to_string(err.lineno);
141 os << std::string(", Function: ");
142 os << err.func;
143 return os;
144}
145
146#endif // _SOURCE_TFERROR_H_
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
void errClearFirst()
std::string errStr(const Error &err)
HRESULT clearErrorCallbacks()
Remove all error callbacks from the registry.
HRESULT expSet(const std::exception &, const char *msg, int line, const char *file, const char *func)
HRESULT removeErrorCallback(const unsigned int &cb_id)
Remove an error callback from the registry.
void errClear()
std::vector< Error > errGetAll()
HRESULT errSet(HRESULT code, const char *msg, int line, const char *file, const char *func)
unsigned int addErrorCallback(ErrorCallback &cb)
Register an error callback.
void(* ErrorCallback)(const Error &err)
Definition tfError.h:56
Error errGetFirst()
bool errOccurred()
Error errPopFirst()
Definition tfError.h:38
std::string func
Definition tfError.h:52
std::string msg
Definition tfError.h:43
std::string fname
Definition tfError.h:49
int lineno
Definition tfError.h:46
HRESULT err
Definition tfError.h:40
int32_t HRESULT
Definition tf_port.h:255