|
Panini 1.4.0
Header-only library for generating C++, written in C++17
|
Command for feature flags. More...
#include <FeatureFlag.hpp>
Public Types | |
| using | TCallback = std::function< void(Writer &writer)> |
Public Member Functions | |
| FeatureFlag (bool condition, const std::string &context, TCallback &&callbackThen) noexcept | |
| FeatureFlag (bool condition, const std::string &context, TCallback &&callbackThen, TCallback &&callbackElse) noexcept | |
| void | Visit (Writer &writer) override |
Public Member Functions inherited from panini::Command | |
| virtual | ~Command ()=default |
Command for feature flags.
When the condition is true, the "then" callback is used to output code to the active writer. Otherwise, if the "else" callback is specified, this callback is used instead.
If the condition was true, the output is wrapped in single-line comments to make the generated code stand out more. These comments are omitted if the context parameter is left blank.
Feature flags are useful when you are working on generated code that depends on the context. For example, you have developed a new way to access the main database, but want to roll out this change in controlled stages instead of simultaneously.
Example:
Output when the condition is true:
Output when the condition is false:
| using panini::FeatureFlag::TCallback = std::function<void(Writer& writer)> |
Callback type used for conditions.
| writer | Active writer. |
|
inlineexplicitnoexcept |
Construct a FeatureFlag with a callback invoked when the condition is true.
| condition | Decide which callback to invoke |
| context | String added to comments for context |
| callbackThen | Invoked when condition is true |
|
inlineexplicitnoexcept |
Construct a FeatureFlag with a callback invoked when the condition is true and one when the condition is false.
| condition | Decide which callback to invoke |
| context | String added to comments for context |
| callbackThen | Invoked when condition is true |
| callbackElse | Invoked when condition is false |
|
inlineoverridevirtual |
Accepts a Writer to write chunks to the output.
Implements panini::Command.