Panini 1.4.0
Header-only library for generating C++, written in C++17
CommentBlock.hpp
Go to the documentation of this file.
1/*
2 MIT No Attribution
3
4 Copyright 2021-2023 Mr. Hands
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to
8 deal in the Software without restriction, including without limitation the
9 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 sell copies of the Software, and to permit persons to whom the Software is
11 furnished to do so.
12
13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 DEALINGS IN THE SOFTWARE.
20*/
21
22#pragma once
23
24#include "commands/Command.hpp"
25#include "writers/Writer.hpp"
26
27namespace panini
28{
29
65 : public Command
66 {
67
68 public:
77 inline explicit CommentBlock(
78 std::function<void(Writer&)>&& callback) noexcept
79 : m_callback(std::exchange(callback, {}))
80 {
81 }
82
83 inline void Visit(Writer& writer) override
84 {
85 writer << "/* ";
86 writer.SetIsInCommentBlock(true);
87
88 m_callback(writer);
89
90 writer.SetIsInCommentBlock(false);
91 writer << NextLine() << " */";
92 }
93
94 private:
95 std::function<void(Writer&)> m_callback;
96
97 };
98
99};
Base class for commands.
Definition: Command.hpp:44
Command for outputting comment blocks over multiple lines.
Definition: CommentBlock.hpp:66
CommentBlock(std::function< void(Writer &)> &&callback) noexcept
Definition: CommentBlock.hpp:77
void Visit(Writer &writer) override
Definition: CommentBlock.hpp:83
Pure virtual interface for writers.
Definition: Writer.hpp:44
virtual void SetIsInCommentBlock(bool value)=0
Definition: Braces.hpp:29
Command for outtputing a new line chunk.
Definition: NextLine.hpp:36