libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
Detail::LoggerLiteral Namespace Reference

Logger 的字面量前端选择片段 Literal-frontend selection fragment of Logger More...

Enumerations

enum class  Frontend : uint8_t { Auto , Format , Printf }
 Logger 字面量前端选择模式 / Logger literal frontend selection mode. More...
 
enum class  Resolution : uint8_t { None , Format , Printf , Ambiguous }
 将一条 logger 字面量与可用前端进行解析后的结果。 Result of resolving one logger literal against the available frontends. More...
 

Functions

template<Print::Text Source>
consteval bool UsesFormatSyntax ()
 判断一条合法 brace 字面量是否真的使用了 brace 语法。 Returns whether one valid brace literal actually uses brace syntax.
 
template<Print::Text Source>
consteval bool UsesPrintfSyntax ()
 判断一条合法 printf 字面量是否真的使用了 printf 语法。 Returns whether one valid printf literal actually uses printf syntax.
 
template<Print::Text Source>
consteval bool FormatSourceValid ()
 判断一条 brace 风格源串在源级上是否合法。 Returns whether one brace-style source is source-level valid.
 
template<Print::Text Source>
consteval bool PrintfSourceValid ()
 判断一条 printf 风格源串在源级上是否合法。 Returns whether one printf-style source is source-level valid.
 
template<Print::Text Source, typename... Args>
consteval bool FormatMatches ()
 判断一组参数是否能被 brace 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the brace frontend, guarded by source-level validity first.
 
template<Print::Text Source, typename... Args>
consteval bool PrintfMatches ()
 判断一组参数是否能被 printf 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the printf frontend, guarded by source-level validity first.
 
template<Frontend Forced, Print::Text Source, typename... Args>
consteval Resolution ResolveFrontend ()
 为一条 logger 字面量及一组具体参数选择前端。 Selects the logger frontend for one literal plus one concrete argument list.
 
template<Frontend Forced, Print::Text Source, typename... Args>
consteval Frontend SelectFrontend ()
 在校验解析结果后,选择最终 logger 前端。 Selects the final logger frontend after validating the resolution result.
 

Detailed Description

Logger 的字面量前端选择片段 Literal-frontend selection fragment of Logger

Note
这一组 helper 只负责在编译期判断一条日志字面量和一组参数应该落到 brace 前端还是 printf 前端,不直接处理运行时 topic 发布。 This helper set is responsible only for deciding at compile time whether one log literal plus one argument list should route to the brace frontend or the printf frontend; it does not perform runtime topic publication directly.

Enumeration Type Documentation

◆ Frontend

enum class Detail::LoggerLiteral::Frontend : uint8_t
strong

Logger 字面量前端选择模式 / Logger literal frontend selection mode.

Enumerator
Auto 

自动选择 brace 或 printf / select brace or printf automatically

Format 

强制使用 brace 风格前端 / force brace-style frontend

Printf 

强制使用 printf 风格前端 / force printf-style frontend

Definition at line 17 of file literal.hpp.

18{
19 Auto,
20 Format,
21 Printf,
22};
@ Auto
自动选择 brace 或 printf / select brace or printf automatically
@ Format
强制使用 brace 风格前端 / force brace-style frontend
@ Printf
强制使用 printf 风格前端 / force printf-style frontend

◆ Resolution

enum class Detail::LoggerLiteral::Resolution : uint8_t
strong

将一条 logger 字面量与可用前端进行解析后的结果。 Result of resolving one logger literal against the available frontends.

Enumerator
None 

两个前端都不匹配 / matches neither frontend

Format 

选择 brace 风格前端 / select brace-style frontend

Printf 

选择 printf 风格前端 / select printf-style frontend

Ambiguous 

两个前端都可用且都真的使用了自己的语法 both frontends remain valid and both syntaxes are used

Definition at line 29 of file literal.hpp.

30{
31 None,
32 Format,
33 Printf,
34 Ambiguous,
36};

Function Documentation

◆ FormatMatches()

template<Print::Text Source, typename... Args>
bool Detail::LoggerLiteral::FormatMatches ( )
nodiscardconsteval

判断一组参数是否能被 brace 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the brace frontend, guarded by source-level validity first.

logger 自动检测不能把多余实参当作 brace 字面量的无害输入,否则不受支持的 printf 风格源串可能回退成 brace 纯文本并静默丢弃实参。 Logger auto-detection must not treat extra call-site arguments as harmless for brace literals, otherwise unsupported printf-like sources can fall back to brace plain text and silently drop their arguments.

Definition at line 106 of file literal.hpp.

107{
108 if constexpr (!FormatSourceValid<Source>())
109 {
110 return false;
111 }
112 else
113 {
114 return LibXR::Format<Source>::template Matches<Args...>();
115 }
116}

◆ FormatSourceValid()

template<Print::Text Source>
bool Detail::LoggerLiteral::FormatSourceValid ( )
nodiscardconsteval

判断一条 brace 风格源串在源级上是否合法。 Returns whether one brace-style source is source-level valid.

Definition at line 77 of file literal.hpp.

78{
79 return Print::Detail::FormatFrontend::Analyze<Source>().error ==
80 Print::Detail::FormatFrontend::Error::None;
81}

◆ PrintfMatches()

template<Print::Text Source, typename... Args>
bool Detail::LoggerLiteral::PrintfMatches ( )
nodiscardconsteval

判断一组参数是否能被 printf 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the printf frontend, guarded by source-level validity first.

Definition at line 124 of file literal.hpp.

125{
126 if constexpr (!PrintfSourceValid<Source>())
127 {
128 return false;
129 }
130 else
131 {
132 return Print::Printf::template Matches<Source, Args...>();
133 }
134}

◆ PrintfSourceValid()

template<Print::Text Source>
bool Detail::LoggerLiteral::PrintfSourceValid ( )
nodiscardconsteval

判断一条 printf 风格源串在源级上是否合法。 Returns whether one printf-style source is source-level valid.

Definition at line 88 of file literal.hpp.

89{
90 return Print::Detail::PrintfCompile::Analyze<Source>().error ==
91 Print::Printf::Error::None;
92}

◆ ResolveFrontend()

template<Frontend Forced, Print::Text Source, typename... Args>
Resolution Detail::LoggerLiteral::ResolveFrontend ( )
nodiscardconsteval

为一条 logger 字面量及一组具体参数选择前端。 Selects the logger frontend for one literal plus one concrete argument list.

Definition at line 142 of file literal.hpp.

143{
144 constexpr bool format_match = FormatMatches<Source, Args...>();
145 constexpr bool printf_match = PrintfMatches<Source, Args...>();
146
147 if constexpr (Forced == Frontend::Format)
148 {
149 return format_match ? Resolution::Format : Resolution::None;
150 }
151 else if constexpr (Forced == Frontend::Printf)
152 {
153 return printf_match ? Resolution::Printf : Resolution::None;
154 }
155 else if constexpr (format_match && !printf_match)
156 {
157 return Resolution::Format;
158 }
159 else if constexpr (!format_match && printf_match)
160 {
161 return Resolution::Printf;
162 }
163 else if constexpr (!format_match && !printf_match)
164 {
165 return Resolution::None;
166 }
167 else
168 {
169 constexpr bool format_uses_syntax = UsesFormatSyntax<Source>();
170 constexpr bool printf_uses_syntax = UsesPrintfSyntax<Source>();
171
172 if constexpr (format_uses_syntax && !printf_uses_syntax)
173 {
174 return Resolution::Format;
175 }
176 else if constexpr (!format_uses_syntax && printf_uses_syntax)
177 {
178 return Resolution::Printf;
179 }
180 else if constexpr (!format_uses_syntax && !printf_uses_syntax)
181 {
182 return Resolution::Format;
183 }
184 else
185 {
186 return Resolution::Ambiguous;
187 }
188 }
189}
consteval bool FormatMatches()
判断一组参数是否能被 brace 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the brace frontend...
Definition literal.hpp:106
consteval bool PrintfMatches()
判断一组参数是否能被 printf 前端接受;会先做源级合法性保护。 Returns whether one argument list is accepted by the printf fronte...
Definition literal.hpp:124

◆ SelectFrontend()

template<Frontend Forced, Print::Text Source, typename... Args>
Frontend Detail::LoggerLiteral::SelectFrontend ( )
nodiscardconsteval

在校验解析结果后,选择最终 logger 前端。 Selects the final logger frontend after validating the resolution result.

Definition at line 197 of file literal.hpp.

198{
199 constexpr auto resolution = ResolveFrontend<Forced, Source, Args...>();
200
201 if constexpr (Forced == Frontend::Format)
202 {
203 static_assert(
204 resolution == Resolution::Format,
205 "LibXR::Logger: XR_FMT(...) literal is not accepted by the brace frontend");
206 return Frontend::Format;
207 }
208 else if constexpr (Forced == Frontend::Printf)
209 {
210 static_assert(
211 resolution == Resolution::Printf,
212 "LibXR::Logger: XR_PRINTF(...) literal is not accepted by the printf frontend");
213 return Frontend::Printf;
214 }
215 else if constexpr (resolution == Resolution::Format)
216 {
217 return Frontend::Format;
218 }
219 else if constexpr (resolution == Resolution::Printf)
220 {
221 return Frontend::Printf;
222 }
223 else if constexpr (resolution == Resolution::Ambiguous)
224 {
225 static_assert(resolution != Resolution::Ambiguous,
226 "LibXR::Logger: literal is ambiguous between brace and printf "
227 "frontends; use XR_FMT(...) or XR_PRINTF(...)");
228 return Frontend::Auto;
229 }
230 else
231 {
232 static_assert(resolution != Resolution::None,
233 "LibXR::Logger: literal matches neither brace nor printf frontend");
234 return Frontend::Auto;
235 }
236}
consteval Resolution ResolveFrontend()
为一条 logger 字面量及一组具体参数选择前端。 Selects the logger frontend for one literal plus one concrete argument lis...
Definition literal.hpp:142

◆ UsesFormatSyntax()

template<Print::Text Source>
bool Detail::LoggerLiteral::UsesFormatSyntax ( )
nodiscardconsteval

判断一条合法 brace 字面量是否真的使用了 brace 语法。 Returns whether one valid brace literal actually uses brace syntax.

Definition at line 43 of file literal.hpp.

44{
45 for (size_t i = 0; i < Source.Size(); ++i)
46 {
47 if (Source.data[i] == '{' || Source.data[i] == '}')
48 {
49 return true;
50 }
51 }
52 return false;
53}

◆ UsesPrintfSyntax()

template<Print::Text Source>
bool Detail::LoggerLiteral::UsesPrintfSyntax ( )
nodiscardconsteval

判断一条合法 printf 字面量是否真的使用了 printf 语法。 Returns whether one valid printf literal actually uses printf syntax.

Definition at line 60 of file literal.hpp.

61{
62 for (size_t i = 0; i < Source.Size(); ++i)
63 {
64 if (Source.data[i] == '%')
65 {
66 return true;
67 }
68 }
69 return false;
70}