Panini 1.4.0
Header-only library for generating C++, written in C++17
panini::Scope Class Reference

Command for outputting a scope with braces. More...

#include <Scope.hpp>

Inheritance diagram for panini::Scope:
panini::Command

Public Types

using TCallback = std::function< void(Writer &writer)>
 

Public Member Functions

 Scope (std::string &&name, TCallback &&callback, BraceBreakingStyle breakingStyle=BraceBreakingStyle::Inherit) noexcept
 
 Scope (const std::string &name, TCallback &&callback, BraceBreakingStyle breakingStyle=BraceBreakingStyle::Inherit) noexcept
 
 Scope (std::string &&name, TCallback &&callback, const ScopeOptions &options) noexcept
 
 Scope (const std::string &name, TCallback &&callback, const ScopeOptions &options) noexcept
 
void Visit (Writer &writer) override
 
- Public Member Functions inherited from panini::Command
virtual ~Command ()=default
 

Detailed Description

Command for outputting a scope with braces.

Scopes have a named chunk and use a Braces command to add opening and closing braces to the output.

Note that the command will automatically add a chunk between the name and the opening brace if the brace breaking style was set to BraceBreakingStyle::Attach by the writer or as an override for this command. This chunk can be configured with ScopeOptions.

Example:

writer << Scope("void SpaceShip::Fire()", [](Writer& writer) {
writer << Scope(R"(g_AudioManager->PlaySound("pewpew.wav", [this](Sound& sound))", [](Writer& writer) {
writer << "FireMissile();" << NextLine();
});
Scope(std::string &&name, TCallback &&callback, BraceBreakingStyle breakingStyle=BraceBreakingStyle::Inherit) noexcept
Definition: Scope.hpp:94
@ Attach
Open brace on the same line.

Output:

void SpaceShip::Fire()
{
g_AudioManager->PlaySound("pewpew.wav", [this](Sound& sound) {
FireMissile();
}
}
See also
Braces

Member Typedef Documentation

◆ TCallback

using panini::Scope::TCallback = std::function<void(Writer& writer)>

Callback type used for conditions.

Parameters
writerActive writer.

Constructor & Destructor Documentation

◆ Scope() [1/4]

panini::Scope::Scope ( std::string &&  name,
TCallback &&  callback,
BraceBreakingStyle  breakingStyle = BraceBreakingStyle::Inherit 
)
inlineexplicitnoexcept
Deprecated:
This constructor will be removed in the next major release. Prefer using the constructor that takes ScopeOptions

Create a Scope with a name and a callback that are both moved into the instance.

The callback is called when the command is visited by a Writer.

Setting the breakingStyle parameter to BraceBreakingStyle::Inherit copies the brace breaking style from the writer, otherwise it will be overridden for this command only.

◆ Scope() [2/4]

panini::Scope::Scope ( const std::string &  name,
TCallback &&  callback,
BraceBreakingStyle  breakingStyle = BraceBreakingStyle::Inherit 
)
inlineexplicitnoexcept
Deprecated:
This constructor will be removed in the next major release. Prefer using the constructor that takes ScopeOptions

Create a Scope with a name that is copied and a callback that is moved into the instance.

The callback is called when the command is visited by a Writer.

Setting the breakingStyle parameter to BraceBreakingStyle::Inherit copies the brace breaking style from the writer, otherwise it will be overridden for this command only.

◆ Scope() [3/4]

panini::Scope::Scope ( std::string &&  name,
TCallback &&  callback,
const ScopeOptions options 
)
inlineexplicitnoexcept

Create a Scope with a name and a callback that are both moved into the instance. options are used to configure the command instance.

◆ Scope() [4/4]

panini::Scope::Scope ( const std::string &  name,
TCallback &&  callback,
const ScopeOptions options 
)
inlineexplicitnoexcept

Create a Scope with a name that is copied and a callback that is moved into the instance. options are used to configure the command instance.

Member Function Documentation

◆ Visit()

void panini::Scope::Visit ( Writer writer)
inlineoverridevirtual

Accepts a Writer to write chunks to the output.

Implements panini::Command.


The documentation for this class was generated from the following file: