5 #ifndef LODESTAR_RECURSIONEXCEPTION_HPP
6 #define LODESTAR_RECURSIONEXCEPTION_HPP
14 #define INIT_RECURSION_GUARD(CALLSTACK, CURRENT_ADDRESS) \
16 {auto ptrToEffectiveEnd = std::find(std::get<0>(CALLSTACK).begin(), std::get<0>(CALLSTACK).end(), decltype(CURRENT_ADDRESS){}); \
17 auto idx = std::find(std::get<0>(CALLSTACK).begin(), ptrToEffectiveEnd, CURRENT_ADDRESS); \
18 if (idx != ptrToEffectiveEnd) { \
19 throw RecursionException<std::size_t>(std::get<1>(CALLSTACK)); \
21 std::get<0>(CALLSTACK)[std::get<2>(CALLSTACK)] = CURRENT_ADDRESS; \
22 std::get<1>(CALLSTACK) = CURRENT_ADDRESS; \
23 std::get<2>(CALLSTACK)++;}
25 #define OPEN_RECURSION_GUARD(CALLSTACK, CURRENT_ADDRESS) \
27 std::get<1>(CALLSTACK) = CURRENT_ADDRESS;
29 #define CLOSE_RECURSION_GUARD(CALLSTACK, CURRENT_ADDRESS) \
30 } catch (const RecursionException<std::size_t> &rexception) { \
31 if (rexception.getInstance() == CURRENT_ADDRESS) std::get<1>(CALLSTACK) = CURRENT_ADDRESS; \
32 else throw rexception; \
35 #define OPEN_CATCH_RECURSION_GUARD(CALLSTACK, CURRENT_ADDRESS) } \
36 catch (const RecursionException<std::size_t> &rexception) { \
37 if (rexception.getInstance() != CURRENT_ADDRESS) { throw rexception; }
39 #define CLOSE_CATCH_RECURSION_GUARD(CALLSTACK, CURRENT_ADDRESS) \
40 std::get<1>(CALLSTACK) = CURRENT_ADDRESS; \
43 template <
typename TType>
50 virtual const char* what()
const noexcept {
51 std::cout << instance_ << std::endl;
52 return std::to_string(instance_).c_str();
55 virtual const TType getInstance()
const noexcept {
62 #endif //LODESTAR_RECURSIONEXCEPTION_HPP