Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Console.inl
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#ifndef DVD_CORE_CONSOLE_INL_
33#define DVD_CORE_CONSOLE_INL_
34
35#include "StringHelper.h"
36
37struct sink
38{
39 template<typename ...Args>
40 explicit sink(Args const& ...) noexcept {}
41};
42
43namespace Divide {
44template <typename... Args>
45NO_INLINE void Console::d_printfn(const char* format, Args&&... args)
46{
48 {
49 printfn(format, FWD(args)...);
50 }
51 else
52 {
53 sink{ format, args ... };
54 }
55}
56
57template <typename... Args>
58NO_INLINE void Console::d_printf(const char* format, Args&&... args)
59{
61 {
62 printf(format, FWD(args)...);
63 }
64 else
65 {
66 sink{ format, args ... };
67 }
68}
69
70template <typename... Args>
71NO_INLINE void Console::d_warnfn(const char* format, Args&&... args)
72{
74 {
75 warnfn(format, FWD(args)...);
76 }
77 else
78 {
79 sink{ format, args ... };
80 }
81}
82
83template <typename... Args>
84NO_INLINE void Console::d_warnf(const char* format, Args&&... args)
85{
87 {
88 warnf(format, FWD(args)...);
89 }
90 else
91 {
92 sink{ format, args ... };
93 }
94}
95
96template <typename... Args>
97NO_INLINE void Console::d_errorfn(const char* format, Args&&... args)
98{
100 {
101 errorfn(format, FWD(args)...);
102 }
103 else
104 {
105 sink{ format, args ... };
106 }
107}
108
109template <typename... Args>
110NO_INLINE void Console::d_errorf(const char* format, Args&&... args)
111{
112 if constexpr (Config::Build::IS_DEBUG_BUILD)
113 {
114 errorf(format, FWD(args)...);
115 }
116 else
117 {
118 sink{ format, args ... };
119 }
120}
121
122template <typename... Args>
123NO_INLINE void Console::printfn(const char* format, Args&&... args)
124{
125 Output( Util::StringFormat<string>(format, FWD(args)...), true, EntryType::INFO);
126}
127
128template <typename... Args>
129NO_INLINE void Console::printf(const char* format, Args&&... args)
130{
131 Output( Util::StringFormat<string>( format, FWD(args)...), false, EntryType::INFO);
132}
133
134template <typename... Args>
135NO_INLINE void Console::warnfn(const char* format, Args&&... args)
136{
137 Output( Util::StringFormat<string>( format, FWD(args)...), true, EntryType::WARNING);
138}
139
140template <typename... Args>
141NO_INLINE void Console::warnf(const char* format, Args&&... args)
142{
143 Output( Util::StringFormat<string>( format, FWD(args)...), false, EntryType::WARNING);
144}
145
146template <typename... Args>
147NO_INLINE void Console::errorfn(const char* format, Args&&... args)
148{
149 Output( Util::StringFormat<string>( format, FWD( args )...), true, EntryType::ERR);
150}
151
152template <typename... Args>
153NO_INLINE void Console::errorf(const char* format, Args&&... args)
154{
155 Output( Util::StringFormat<string>( format, FWD(args)...), false, EntryType::ERR);
156}
157
158template <typename... Args>
159NO_INLINE void Console::printfn(std::ofstream& outStream, const char* format, Args&&... args)
160{
161 Output(outStream, Util::StringFormat<string>( format, FWD(args)...), true, EntryType::INFO);
162}
163
164template <typename... Args>
165NO_INLINE void Console::printf(std::ofstream& outStream, const char* format, Args&&... args)
166{
167 Output(outStream, Util::StringFormat<string>( format, FWD(args)...), false, EntryType::INFO);
168}
169
170template <typename... Args>
171NO_INLINE void Console::warnfn(std::ofstream& outStream, const char* format, Args&&... args)
172{
173 Output(outStream, Util::StringFormat<string>( format, FWD(args)...), true, EntryType::WARNING);
174}
175
176template <typename... Args>
177NO_INLINE void Console::warnf(std::ofstream& outStream, const char* format, Args&&... args)
178{
179 Output(outStream, Util::StringFormat<string>( format, FWD(args)...), false, EntryType::WARNING);
180}
181
182template <typename... Args>
183NO_INLINE void Console::errorfn(std::ofstream& outStream, const char* format, Args&&... args)
184{
185 Output(outStream, Util::StringFormat<string>( format, FWD(args)...), true, EntryType::ERR);
186}
187
188template <typename... Args>
189NO_INLINE void Console::errorf(std::ofstream& outStream, const char* format, Args&&... args)
190{
191 Output(outStream, Util::StringFormat<string>( format, FWD(args)...), false, EntryType::ERR);
192}
193
194template <typename... Args>
195NO_INLINE void Console::d_printfn(std::ofstream& outStream, const char* format, Args&&... args)
196{
197 if constexpr (Config::Build::IS_DEBUG_BUILD)
198 {
199 printfn(outStream, format, FWD(args)...);
200 }
201 else
202 {
203 sink{ outStream, format, args ... };
204 }
205}
206
207template <typename... Args>
208NO_INLINE void Console::d_printf(std::ofstream& outStream, const char* format, Args&&... args)
209{
210 if constexpr (Config::Build::IS_DEBUG_BUILD)
211 {
212 printf(outStream, format, FWD(args)...);
213 }
214 else
215 {
216 sink{ outStream, format, args ... };
217 }
218}
219
220template <typename... Args>
221NO_INLINE void Console::d_warnfn(std::ofstream& outStream, const char* format, Args&&... args)
222{
223 if constexpr (Config::Build::IS_DEBUG_BUILD)
224 {
225 warnfn(outStream, format, FWD(args)...);
226 }
227 else
228 {
229 sink{ outStream, format, args ... };
230 }
231}
232
233template <typename... Args>
234NO_INLINE void Console::d_warnf(std::ofstream& outStream, const char* format, Args&&... args)
235{
236 if constexpr (Config::Build::IS_DEBUG_BUILD)
237 {
238 warnf(outStream, format, FWD(args)...);
239 }
240 else
241 {
242 sink{ outStream, format, args ... };
243 }
244}
245
246template <typename... Args>
247NO_INLINE void Console::d_errorfn(std::ofstream& outStream, const char* format, Args&&... args)
248{
249 if constexpr (Config::Build::IS_DEBUG_BUILD)
250 {
251 errorfn(outStream, format, FWD(args)...);
252 }
253 else
254 {
255 sink{ outStream, format, args ... };
256 }
257}
258
259template <typename... Args>
260NO_INLINE void Console::d_errorf(std::ofstream& outStream, const char* format, Args&&... args)
261{
262 if constexpr (Config::Build::IS_DEBUG_BUILD)
263 {
264 errorf(outStream, format, FWD(args)...);
265 }
266 else
267 {
268 sink{ outStream, format, args ... };
269 }
270}
271}
272
273#endif //DVD_CORE_CONSOLE_INL_
#define FWD(...)
#define NO_INLINE
constexpr bool IS_DEBUG_BUILD
Definition: config.h:55
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
static NO_INLINE void d_printfn(const char *format, T &&... args)
static NO_INLINE void d_printf(const char *format, T &&... args)
static NO_INLINE void errorfn(const char *format, T &&... args)
static NO_INLINE void warnf(const char *format, T &&... args)
static NO_INLINE void warnfn(const char *format, T &&... args)
static NO_INLINE void printfn(const char *format, T &&... args)
static NO_INLINE void d_warnfn(const char *format, T &&... args)
static void Output(std::string_view text, bool newline, EntryType type)
Definition: Console.cpp:81
static NO_INLINE void d_errorf(const char *format, T &&... args)
static NO_INLINE void d_warnf(const char *format, T &&... args)
static NO_INLINE void d_errorfn(const char *format, T &&... args)
static NO_INLINE void errorf(const char *format, T &&... args)
static NO_INLINE void printf(const char *format, T &&... args)
Definition: Console.inl:38
sink(Args const &...) noexcept
Definition: Console.inl:40