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

Command for outputting opening and closing (curly) braces. More...

#include <Braces.hpp>

Inheritance diagram for panini::Braces:
panini::Command

Public Types

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

Public Member Functions

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

Detailed Description

Command for outputting opening and closing (curly) braces.

This command tracks the current indentation level and takes the brace breaking style into account when outputting braces. You can change both the brace breaking style and the brace chunks it outputs with the BracesOptions parameter.

After outputting the opening brace, the Braces command calls a callback with the current Writer instance as a parameter.

If you want to prefix the opening brace with a chunk, it may be more convenient to use a Scope instead.

Note
The command will not output a space before the opening brace if the brace breaking style was set to BraceBreakingStyle::Attach.

Example:

writer << Braces([](Writer& writer) {
writer << "const char* passwords[] = " << Braces([](Writer& writer) {
writer << R"("password",)" << NextLine();
writer << R"("p4ssw0rd")" << NextLine();
}, BraceBreakingStyle::Attach) << ";" << NextLine();
});
Braces(TCallback &&callback, BraceBreakingStyle breakingStyle=BraceBreakingStyle::Inherit) noexcept
Definition: Braces.hpp:96
@ Attach
Open brace on the same line.

Output:

{
const char* passwords[] = {
"password",
"p4ssw0rd"
};
}
See also
Scope

Member Typedef Documentation

◆ TCallback

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

Constructor & Destructor Documentation

◆ Braces() [1/2]

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

Create a Braces command with 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.

◆ Braces() [2/2]

panini::Braces::Braces ( TCallback &&  callback,
const BracesOptions options 
)
inlineexplicitnoexcept

Create a Braces command a callback that is moved into the instance.

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

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

Member Function Documentation

◆ Visit()

void panini::Braces::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: