Doxygen
Loading...
Searching...
No Matches
message.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2023 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16#ifndef MESSAGE_H
17#define MESSAGE_H
18
19#include <fmt/core.h>
20#include <fmt/compile.h>
21
22#include "types.h"
23#include "qcstring.h"
24
33
34void msg_(fmt::string_view fmt, fmt::format_args args);
35void warn_(WarningType type, const QCString &file, int line, fmt::string_view fmt, fmt::format_args args);
36void warn_uncond_(fmt::string_view fmt, fmt::format_args args);
37void err_(fmt::string_view fmt, fmt::format_args args);
38void err_full_(const QCString &file, int line, fmt::string_view fmt, fmt::format_args args);
39void term_(fmt::string_view fmt, fmt::format_args args);
40QCString warn_line(const QCString &file, int line);
42void warn_flush();
43void finishWarnExit();
44
45template<typename ...Args>
46void err_fmt(fmt::format_string<Args...> fmt, Args&&... args)
47{
48 err_(fmt,fmt::make_format_args(args...));
49}
50
51template<typename ...Args>
52void err_full_fmt(const QCString &file, int line, fmt::format_string<Args...> fmt,Args&&... args)
53{
54 err_full_(file,line,fmt,fmt::make_format_args(args...));
55}
56
57template<typename ...Args>
58void term_fmt(fmt::format_string<Args...> fmt, Args&&... args)
59{
60 term_(fmt,fmt::make_format_args(args...));
61}
62
63template<typename ...Args>
64void msg_fmt(fmt::format_string<Args...> fmt, Args&&... args)
65{
66 msg_(fmt,fmt::make_format_args(args...));
67}
68
69template<typename ...Args>
70void warn_fmt(WarningType type, const QCString &file, int line, fmt::format_string<Args...> fmt,Args&&... args)
71{
72 warn_(type,file,line,fmt,fmt::make_format_args(args...));
73}
74
75template<typename ...Args>
76void warn_uncond_fmt(fmt::format_string<Args...> fmt,Args&&... args)
77{
78 warn_uncond_(fmt,fmt::make_format_args(args...));
79}
80
81// N is size including 0-terminal
82template<std::size_t N>
83constexpr bool has_newline_at_end(const char (&str)[N])
84{
85 return str[N-2]=='\n';
86}
87
88#define msg_no_newline_allowed(x) \
89 static_assert(!has_newline_at_end(x),"text: \"" x "\" should not have \\n at end");
90
91#define msg_newline_required(x) \
92 static_assert(has_newline_at_end(x),"text: \"" x "\" should have \\n at end");
93
94#define msg(fmt,...) \
95 msg_fmt(FMT_STRING(fmt),##__VA_ARGS__)
96
97#define warn(file,line,fmt,...) do { \
98 msg_no_newline_allowed(fmt); \
99 warn_fmt(WarningType::Generic,file,line,FMT_STRING(fmt),##__VA_ARGS__); \
100 } while (0)
101
102#define warn_undoc(file,line,fmt,...) do { \
103 msg_no_newline_allowed(fmt); \
104 warn_fmt(WarningType::Undocumented,file,line,FMT_STRING(fmt),##__VA_ARGS__); \
105 } while (0)
106
107#define warn_incomplete_doc(file,line,fmt,...) do { \
108 msg_no_newline_allowed(fmt); \
109 warn_fmt(WarningType::IncompleteDoc,file,line,FMT_STRING(fmt),##__VA_ARGS__); \
110 } while (0)
111
112#define warn_doc_error(file,line,fmt,...) do { \
113 msg_no_newline_allowed(fmt); \
114 warn_fmt(WarningType::DocError,file,line,FMT_STRING(fmt),##__VA_ARGS__); \
115 } while (0)
116
117#define warn_layout(file,line,fmt,...) do { \
118 msg_no_newline_allowed(fmt); \
119 warn_fmt(WarningType::Layout,file,line,FMT_STRING(fmt),##__VA_ARGS__); \
120 } while (0)
121
122#define warn_uncond(fmt,...) do { \
123 msg_newline_required(fmt); \
124 warn_uncond_fmt(FMT_STRING(fmt),##__VA_ARGS__); \
125 } while (0)
126
127#define err(fmt,...) do { \
128 msg_newline_required(fmt); \
129 err_fmt(FMT_STRING(fmt),##__VA_ARGS__); \
130 } while (0)
131
132#define err_full(file,line,fmt,...) do { \
133 msg_no_newline_allowed(fmt); \
134 err_full_fmt(file,line,FMT_STRING(fmt),##__VA_ARGS__); \
135 } while (0)
136
137#define term(fmt,...) do { \
138 msg_newline_required(fmt); \
139 term_fmt(FMT_STRING(fmt),##__VA_ARGS__); \
140 } while (0)
141
142
143#ifdef DOXYGEN_ONLY
144namespace fmt { template<typename T> struct formatter {}; }
145#endif
146
147//! adds support for formatting QCString
148template<> struct fmt::formatter<QCString> : formatter<std::string>
149{
150 auto format(const QCString &c, format_context& ctx) const {
151 return formatter<std::string>::format(c.str(), ctx);
152 }
153};
154
155//! adds support for formatting Protected
156template<> struct fmt::formatter<Protection> : formatter<std::string>
157{
158 auto format(Protection prot, format_context& ctx) const {
159 std::string result="Unknown";
160 switch (prot)
161 {
162 case Protection::Public: result="Public"; break;
163 case Protection::Protected: result="Protected"; break;
164 case Protection::Private: result="Private"; break;
165 case Protection::Package: result="Package"; break;
166 }
167 return formatter<std::string>::format(result, ctx);
168 }
169};
170
171//! adds support for formatting Specifier
172template<> struct fmt::formatter<Specifier> : formatter<std::string>
173{
174 auto format(Specifier spec, format_context& ctx) const {
175 std::string result="Unknown";
176 switch (spec)
177 {
178 case Specifier::Normal: result="Normal"; break;
179 case Specifier::Virtual: result="Virtual"; break;
180 case Specifier::Pure: result="Pure"; break;
181 }
182 return formatter<std::string>::format(result, ctx);
183 }
184};
185
186//! adds support for formatting MethodTypes
187template<> struct fmt::formatter<MethodTypes> : formatter<std::string>
188{
189 auto format(MethodTypes mtype, format_context& ctx) const {
190 std::string result="Unknown";
191 switch (mtype)
192 {
193 case MethodTypes::Method: result="Method"; break;
194 case MethodTypes::Signal: result="Signal"; break;
195 case MethodTypes::Slot: result="Slot"; break;
196 case MethodTypes::DCOP: result="DCOP"; break;
197 case MethodTypes::Property: result="Property"; break;
198 case MethodTypes::Event: result="Event"; break;
199 }
200 return formatter<std::string>::format(result, ctx);
201 }
202};
203
204//! adds support for formatting RelatesType
205template<> struct fmt::formatter<RelatesType> : formatter<std::string>
206{
207 auto format(RelatesType type, format_context& ctx) const {
208 std::string result="Unknown";
209 switch (type)
210 {
211 case RelatesType::Simple: result="Simple"; break;
212 case RelatesType::Duplicate: result="Duplicate"; break;
213 case RelatesType::MemberOf: result="MemberOf"; break;
214 }
215 return formatter<std::string>::format(result, ctx);
216 }
217};
218
219//! adds support for formatting RelationShip
220template<> struct fmt::formatter<Relationship> : formatter<std::string>
221{
222 auto format(Relationship relation, format_context& ctx) const {
223 std::string result="Unknown";
224 switch (relation)
225 {
226 case Relationship::Member: result="Member"; break;
227 case Relationship::Related: result="Related"; break;
228 case Relationship::Foreign: result="Foreign"; break;
229 }
230 return formatter<std::string>::format(result, ctx);
231 }
232};
233
234//! adds support for formatting SrcLangExt
235template<> struct fmt::formatter<SrcLangExt> : formatter<std::string>
236{
237 auto format(SrcLangExt lang, format_context& ctx) const {
238 std::string result="Unknown";
239 switch (lang)
240 {
241 case SrcLangExt::Unknown: result="Unknown"; break;
242 case SrcLangExt::IDL: result="IDL"; break;
243 case SrcLangExt::Java: result="Java"; break;
244 case SrcLangExt::CSharp: result="C#"; break;
245 case SrcLangExt::D: result="D"; break;
246 case SrcLangExt::PHP: result="PHP"; break;
247 case SrcLangExt::ObjC: result="Objective-C"; break;
248 case SrcLangExt::Cpp: result="C++"; break;
249 case SrcLangExt::JS: result="Javascript"; break;
250 case SrcLangExt::Python: result="Python"; break;
251 case SrcLangExt::Fortran: result="Fortran"; break;
252 case SrcLangExt::VHDL: result="VHDL"; break;
253 case SrcLangExt::XML: result="XML"; break;
254 //case SrcLangExt::Tcl: result="Tcl"; break;
255 case SrcLangExt::Markdown: result="Markdown"; break;
256 case SrcLangExt::SQL: result="SQL"; break;
257 case SrcLangExt::Slice: result="Slice"; break;
258 case SrcLangExt::Lex: result="Lex"; break;
259 }
260 return formatter<std::string>::format(result, ctx);
261 }
262};
263
264//! adds support for formatting MemberType
265template<> struct fmt::formatter<MemberType> : formatter<std::string>
266{
267 auto format(MemberType mtype, format_context& ctx) const {
268 std::string result="Unknown";
269 switch (mtype)
270 {
271 case MemberType::Define: result="Define"; break;
272 case MemberType::Function: result="Function"; break;
273 case MemberType::Variable: result="Variable"; break;
274 case MemberType::Typedef: result="Typedef"; break;
275 case MemberType::Enumeration: result="Enumeration"; break;
276 case MemberType::EnumValue: result="EnumValue"; break;
277 case MemberType::Signal: result="Signal"; break;
278 case MemberType::Slot: result="Slot"; break;
279 case MemberType::Friend: result="Friend"; break;
280 case MemberType::DCOP: result="DCOP"; break;
281 case MemberType::Property: result="Property"; break;
282 case MemberType::Event: result="Event"; break;
283 case MemberType::Interface: result="Interface"; break;
284 case MemberType::Service: result="Service"; break;
285 case MemberType::Sequence: result="Sequence"; break;
286 case MemberType::Dictionary: result="Dictionary"; break;
287 }
288 return formatter<std::string>::format(result, ctx);
289 }
290};
291
292//! adds support for formatting TypeSpecifier
293template<> struct fmt::formatter<TypeSpecifier> : formatter<std::string>
294{
295 auto format(TypeSpecifier type, format_context& ctx) const {
296 return formatter<std::string>::format(type.to_string(),ctx);
297 }
298};
299
300//! adds support for formatting EntryType
301template<> struct fmt::formatter<EntryType> : formatter<std::string>
302{
303 auto format(EntryType type, format_context& ctx) const {
304 return formatter<std::string>::format(type.to_string(),ctx);
305 }
306};
307
308//! adds support for formatting MemberListType
309template<> struct fmt::formatter<MemberListType> : formatter<std::string>
310{
311 auto format(MemberListType type, format_context& ctx) const {
312 return formatter<std::string>::format(type.to_string(),ctx);
313 }
314};
315
316#endif // MESSAGE_H
317
Wrapper class for the Entry type.
Definition types.h:631
std::string to_string() const
Definition types.h:643
Wrapper class for the MemberListType type.
Definition types.h:184
std::string to_string() const
Definition types.h:224
This is an alternative implementation of QCString.
Definition qcstring.h:101
const std::string & str() const
Definition qcstring.h:537
Wrapper class for a number of boolean properties.
Definition types.h:492
std::string to_string() const
Definition types.h:520
@ Undocumented
Definition doxygen.cpp:288
void warn_uncond_fmt(fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:76
void err_(fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:159
QCString warn_line(const QCString &file, int line)
Definition message.cpp:196
void term_fmt(fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:58
constexpr bool has_newline_at_end(const char(&str)[N])
Definition message.h:83
void warn_(WarningType type, const QCString &file, int line, fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:132
void warn_uncond_(fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:151
void initWarningFormat()
Definition message.cpp:218
WarningType
Definition message.h:26
@ IncompleteDoc
Definition message.h:29
void warn_flush()
Definition message.cpp:211
void msg_(fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:117
void msg_fmt(fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:64
void err_fmt(fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:46
void finishWarnExit()
Definition message.cpp:276
void term_(fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:174
void err_full_(const QCString &file, int line, fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:167
void warn_fmt(WarningType type, const QCString &file, int line, fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:70
void err_full_fmt(const QCString &file, int line, fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:52
Definition message.h:144
auto format(EntryType type, format_context &ctx) const
Definition message.h:303
auto format(MemberListType type, format_context &ctx) const
Definition message.h:311
auto format(MemberType mtype, format_context &ctx) const
Definition message.h:267
auto format(MethodTypes mtype, format_context &ctx) const
Definition message.h:189
auto format(Protection prot, format_context &ctx) const
Definition message.h:158
auto format(const QCString &c, format_context &ctx) const
Definition message.h:150
auto format(RelatesType type, format_context &ctx) const
Definition message.h:207
auto format(Relationship relation, format_context &ctx) const
Definition message.h:222
auto format(Specifier spec, format_context &ctx) const
Definition message.h:174
auto format(SrcLangExt lang, format_context &ctx) const
Definition message.h:237
auto format(TypeSpecifier type, format_context &ctx) const
Definition message.h:295
This file contains a number of basic enums and types.
MethodTypes
Kind of method.
Definition types.h:32
@ Property
Definition types.h:32
MemberType
Definition types.h:390
@ Enumeration
Definition types.h:395
@ EnumValue
Definition types.h:396
@ Dictionary
Definition types.h:406
@ Interface
Definition types.h:403
@ Sequence
Definition types.h:405
@ Variable
Definition types.h:393
@ Property
Definition types.h:401
@ Typedef
Definition types.h:394
@ Function
Definition types.h:392
@ Service
Definition types.h:404
Protection
Protection level of members.
Definition types.h:26
@ Package
Definition types.h:26
@ Public
Definition types.h:26
@ Private
Definition types.h:26
@ Protected
Definition types.h:26
SrcLangExt
Language as given by extension.
Definition types.h:42
@ Markdown
Definition types.h:57
@ CSharp
Definition types.h:46
@ Fortran
Definition types.h:53
@ Unknown
Definition types.h:43
@ Python
Definition types.h:52
@ Slice
Definition types.h:59
Relationship
Kind of member relationship.
Definition types.h:38
RelatesType
Type of member relation.
Definition types.h:35
@ MemberOf
Definition types.h:35
@ Duplicate
Definition types.h:35
Specifier
Virtualness of a member.
Definition types.h:29
@ Virtual
Definition types.h:29
@ Normal
Definition types.h:29
@ Pure
Definition types.h:29