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 "dstring.h"
24
33
34void msg_(fmt::string_view fmt, fmt::format_args args);
35void warn_(WarningType type, const DString &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 DString &file, int line, fmt::string_view fmt, fmt::format_args args);
39void term_(fmt::string_view fmt, fmt::format_args args);
40DString warn_line(const DString &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 DString &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 DString &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#define ASSERT(x) if ( !(x) )\
143 warn_uncond("ASSERT: Internal inconsistency: \"{}\" in {} ({})\n",#x,__FILE__,__LINE__)
144
145#ifdef DOXYGEN_ONLY
146namespace fmt { template<typename T> struct formatter {}; }
147#endif
148
149//! adds support for formatting DString
150template<> struct fmt::formatter<DString> : formatter<std::string>
151{
152 auto format(const DString &c, format_context& ctx) const {
153 return formatter<std::string>::format(c.str(), ctx);
154 }
155};
156
157//! adds support for formatting Protected
158template<> struct fmt::formatter<Protection> : formatter<std::string>
159{
160 auto format(Protection prot, format_context& ctx) const {
161 return formatter<std::string>::format(to_string(prot), ctx);
162 }
163};
164
165//! adds support for formatting Specifier
166template<> struct fmt::formatter<Specifier> : formatter<std::string>
167{
168 auto format(Specifier spec, format_context& ctx) const {
169 return formatter<std::string>::format(to_string(spec), ctx);
170 }
171};
172
173//! adds support for formatting MethodTypes
174template<> struct fmt::formatter<MethodTypes> : formatter<std::string>
175{
176 auto format(MethodTypes mtype, format_context& ctx) const {
177 return formatter<std::string>::format(to_string(mtype), ctx);
178 }
179};
180
181//! adds support for formatting RelatesType
182template<> struct fmt::formatter<RelatesType> : formatter<std::string>
183{
184 auto format(RelatesType type, format_context& ctx) const {
185 return formatter<std::string>::format(to_string(type), ctx);
186 }
187};
188
189//! adds support for formatting RelationShip
190template<> struct fmt::formatter<Relationship> : formatter<std::string>
191{
192 auto format(Relationship relation, format_context& ctx) const {
193 return formatter<std::string>::format(to_string(relation), ctx);
194 }
195};
196
197//! adds support for formatting SrcLangExt
198template<> struct fmt::formatter<SrcLangExt> : formatter<std::string>
199{
200 auto format(SrcLangExt lang, format_context& ctx) const {
201 return formatter<std::string>::format(to_string(lang), ctx);
202 }
203};
204
205//! adds support for formatting MemberType
206template<> struct fmt::formatter<MemberType> : formatter<std::string>
207{
208 auto format(MemberType mtype, format_context& ctx) const {
209 return formatter<std::string>::format(to_string(mtype), ctx);
210 }
211};
212
213//! adds support for formatting TypeSpecifier
214template<> struct fmt::formatter<TypeSpecifier> : formatter<std::string>
215{
216 auto format(TypeSpecifier type, format_context& ctx) const {
217 return formatter<std::string>::format(type.to_string(),ctx);
218 }
219};
220
221//! adds support for formatting EntryType
222template<> struct fmt::formatter<EntryType> : formatter<std::string>
223{
224 auto format(EntryType type, format_context& ctx) const {
225 return formatter<std::string>::format(type.to_string(),ctx);
226 }
227};
228
229//! adds support for formatting MemberListType
230template<> struct fmt::formatter<MemberListType> : formatter<std::string>
231{
232 auto format(MemberListType type, format_context& ctx) const {
233 return formatter<std::string>::format(type.to_string(),ctx);
234 }
235};
236
237#endif // MESSAGE_H
238
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
const std::string & str() const
Definition dstring.h:645
Wrapper class for the Entry type.
Definition types.h:856
std::string to_string() const
Definition types.h:868
Wrapper class for the MemberListType type.
Definition types.h:346
std::string to_string() const
Definition types.h:386
Wrapper class for a number of boolean properties.
Definition types.h:694
std::string to_string() const
Definition types.h:738
@ Undocumented
Definition doxygen.cpp:293
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:171
void term_fmt(fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:58
void err_full_fmt(const DString &file, int line, fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:52
void err_full_(const DString &file, int line, fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:182
constexpr bool has_newline_at_end(const char(&str)[N])
Definition message.h:83
void warn_uncond_(fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:160
void initWarningFormat()
Definition message.cpp:233
WarningType
Definition message.h:26
@ IncompleteDoc
Definition message.h:29
void warn_flush()
Definition message.cpp:226
void warn_fmt(WarningType type, const DString &file, int line, fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:70
void msg_(fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:126
void msg_fmt(fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:64
DString warn_line(const DString &file, int line)
Definition message.cpp:211
void err_fmt(fmt::format_string< Args... > fmt, Args &&... args)
Definition message.h:46
void finishWarnExit()
Definition message.cpp:291
void term_(fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:189
void warn_(WarningType type, const DString &file, int line, fmt::string_view fmt, fmt::format_args args)
Definition message.cpp:141
Definition message.h:146
auto format(const DString &c, format_context &ctx) const
Definition message.h:152
auto format(EntryType type, format_context &ctx) const
Definition message.h:224
auto format(MemberListType type, format_context &ctx) const
Definition message.h:232
auto format(MemberType mtype, format_context &ctx) const
Definition message.h:208
auto format(MethodTypes mtype, format_context &ctx) const
Definition message.h:176
auto format(Protection prot, format_context &ctx) const
Definition message.h:160
auto format(RelatesType type, format_context &ctx) const
Definition message.h:184
auto format(Relationship relation, format_context &ctx) const
Definition message.h:192
auto format(Specifier spec, format_context &ctx) const
Definition message.h:168
auto format(SrcLangExt lang, format_context &ctx) const
Definition message.h:200
auto format(TypeSpecifier type, format_context &ctx) const
Definition message.h:216
This file contains a number of basic enums and types.
MethodTypes
Definition types.h:119
MemberType
Definition types.h:569
Protection
Definition types.h:32
SrcLangExt
Definition types.h:207
Relationship
Definition types.h:167
RelatesType
Definition types.h:143
Specifier
Definition types.h:80