Panini 1.4.0
Header-only library for generating C++, written in C++17
IncludeBlock.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 "commands/Include.hpp"
26#include "data/IncludeSet.hpp"
27#include "writers/Writer.hpp"
28
29namespace panini
30{
31
60 : public Command
61 {
62
63 public:
68 inline explicit IncludeBlock(const IncludeSet& set)
69 : m_set(set)
70 {
71 }
72
77 inline explicit IncludeBlock(IncludeSet&& set) noexcept
78 : m_set(std::exchange(set, {}))
79 {
80 }
81
82 inline void Visit(Writer& writer) override
83 {
84 // sort includes and resolve "inherit" include style with the
85 // writer's include style
86
87 m_set.Sort(writer.GetIncludeStyle());
88
89 // write includes
90
91 size_t includeIndex = 0;
92 for (IncludeEntry& entry : m_set)
93 {
94 if (includeIndex++ > 0)
95 {
96 writer << NextLine();
97 }
98
99 writer << Include(entry);
100 }
101 }
102
103 private:
104 IncludeSet m_set;
105
106 };
107
108};
Base class for commands.
Definition: Command.hpp:44
Command for outputting a block of include statements.
Definition: IncludeBlock.hpp:61
void Visit(Writer &writer) override
Definition: IncludeBlock.hpp:82
IncludeBlock(const IncludeSet &set)
Definition: IncludeBlock.hpp:68
IncludeBlock(IncludeSet &&set) noexcept
Definition: IncludeBlock.hpp:77
Command for outputting an include statement for C++.
Definition: Include.hpp:65
Collection of unique file system paths.
Definition: IncludeSet.hpp:46
void Sort(IncludeStyle resolvedStyle)
Definition: IncludeSet.hpp:165
Pure virtual interface for writers.
Definition: Writer.hpp:44
virtual IncludeStyle GetIncludeStyle() const =0
Definition: Braces.hpp:29
Data for includes.
Definition: IncludeEntry.hpp:36
Command for outtputing a new line chunk.
Definition: NextLine.hpp:36