forked from openbmc/sdbusplus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sdbus++: events: generate exception constructors
Generate constructors for exceptions using the listed metadata. Signed-off-by: Patrick Williams <[email protected]> Change-Id: I99dc912e4ad0746a14d3053a5653327ae12440dd
- Loading branch information
1 parent
0ac157a
commit d925c0b
Showing
7 changed files
with
96 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#pragma once | ||
|
||
#include <algorithm> | ||
#include <cstdint> | ||
|
||
namespace sdbusplus::utility | ||
{ | ||
namespace details | ||
{ | ||
|
||
template <std::size_t N> | ||
struct consteval_string_holder | ||
{ | ||
char value[N] = {}; | ||
|
||
consteval consteval_string_holder(const char (&str)[N]) | ||
{ | ||
std::ranges::copy(str, value); | ||
} | ||
}; | ||
|
||
} // namespace details | ||
|
||
/** Type to allow compile-time parameter string comparisons. | ||
* | ||
* Example: | ||
* void foo(consteval_string<"FOO">); | ||
* | ||
* If the function is not called with foo("FOO"), it will be a compile error. | ||
*/ | ||
template <details::consteval_string_holder V> | ||
struct consteval_string | ||
{ | ||
std::string_view value; | ||
|
||
template <typename T> | ||
consteval consteval_string(const T& s) : value(s) | ||
{ | ||
if (value != V.value) | ||
{ | ||
report_error("String mismatch; check parameter name."); | ||
} | ||
} | ||
|
||
// This is not a real function but used to trigger compile errors due to | ||
// calling a non-constexpr function in a constexpr context. | ||
static void report_error(const char*); | ||
}; | ||
|
||
} // namespace sdbusplus::utility |
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
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