-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add find_solid with implicit downcast and validity check
The `find_solid` that already exists, returns `G4VSolid*`. Sometimes you want to access more specific methods which are only available in the concrete subtypes, which requires a downcast and a pointer validity check. This template absolves the user from writing lots of boilerplate. Closes #151
- Loading branch information
Showing
6 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#pragma once | ||
|
||
#include <n4-main.hh> | ||
#include <n4-exceptions.hh> | ||
#include <n4-geometry.hh> | ||
#include <n4-utils.hh> | ||
#include <n4-testing.hh> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <exception> | ||
#include <string> | ||
|
||
namespace nain4 { | ||
namespace exceptions { | ||
|
||
#define WRAP(NAME, FROM, MESSAGE) \ | ||
"\n\n" \ | ||
"########################################################\n" \ | ||
"[n4::exceptions::" + NAME + "]\n\n" \ | ||
"[raised by " + FROM + "]: " + MESSAGE + "\n" \ | ||
"########################################################\n" \ | ||
"\n\n" | ||
|
||
struct exception : std::exception { | ||
exception(const std::string& name, const std::string& from, const std::string& message) | ||
: message(WRAP(name, from, message)) {} | ||
const char* what() const noexcept { return message.c_str();} | ||
|
||
private: | ||
std::string message; | ||
}; | ||
|
||
#define EXCEPTION(NAME) \ | ||
struct NAME : exception { \ | ||
NAME(const std::string& from, const std::string& message) \ | ||
: exception(#NAME, from, message) {} \ | ||
}; | ||
|
||
EXCEPTION(not_found) | ||
EXCEPTION(bad_cast) | ||
|
||
#undef N4_EXCEPTION | ||
#undef WRAP | ||
|
||
} // namespace exceptions | ||
} // namespace nain4 | ||
|
||
namespace n4{ using namespace nain4; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters