Panini 1.4.0
Header-only library for generating C++, written in C++17
Include.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 "data/IncludeEntry.hpp"
26#include "writers/Writer.hpp"
27
28namespace panini
29{
30
63 class Include
64 : public Command
65 {
66
67 public:
72 inline explicit Include(const IncludeEntry& entry)
73 : m_entry(entry)
74 {
75 }
76
81 inline explicit Include(IncludeEntry&& entry) noexcept
82 : m_entry(std::exchange(entry, {}))
83 {
84 }
85
93 inline explicit Include(
94 const std::filesystem::path& path,
96 : m_entry(path, style)
97 {
98 }
99
107 inline explicit Include(
108 std::filesystem::path&& path,
109 IncludeStyle style = IncludeStyle::Inherit) noexcept
110 : m_entry(path, style)
111 {
112 }
113
114 inline void Visit(Writer& writer) override
115 {
116 IncludeStyle includeStyle =
118 ? writer.GetIncludeStyle()
119 : m_entry.style;
120
121 writer << "#include ";
122
123 std::string path = m_entry.path.string();
124
125 switch (includeStyle)
126 {
127
129 writer << "\"" << path << "\"";
130 break;
131
133 writer << "'" << path << "'";
134 break;
135
137 writer << "<" << path << ">";
138 break;
139
140 default:
141 break;
142
143 }
144 }
145
146 private:
147 IncludeEntry m_entry;
148
149 };
150
151};
Base class for commands.
Definition: Command.hpp:44
Command for outputting an include statement for C++.
Definition: Include.hpp:65
void Visit(Writer &writer) override
Definition: Include.hpp:114
Include(const std::filesystem::path &path, IncludeStyle style=IncludeStyle::Inherit)
Definition: Include.hpp:93
Include(std::filesystem::path &&path, IncludeStyle style=IncludeStyle::Inherit) noexcept
Definition: Include.hpp:107
Include(IncludeEntry &&entry) noexcept
Definition: Include.hpp:81
Include(const IncludeEntry &entry)
Definition: Include.hpp:72
Pure virtual interface for writers.
Definition: Writer.hpp:44
virtual IncludeStyle GetIncludeStyle() const =0
IncludeStyle
Include style to use when writing to output.
Definition: IncludeStyle.hpp:36
@ DoubleQuotes
Output double quotation marks "".
@ Inherit
Inherit setting from the config, not valid on Writer.
@ SingleQuotes
Output single quotation marks '' (not valid for C++)
@ AngularBrackets
Output angular brackets <>
Definition: Braces.hpp:29
Data for includes.
Definition: IncludeEntry.hpp:36
IncludeStyle style
Definition: IncludeEntry.hpp:75
std::filesystem::path path
Definition: IncludeEntry.hpp:70