libxr  1.0
Want to be the best embedded framework
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 literal frontend selection mode. More...
 
enum class  Resolution : uint8_t { None , Format , Printf , Ambiguous }
 Result of resolving one logger literal against the available frontends. More...
 

Functions

template<Print::Text Source>
consteval bool UsesFormatSyntax ()
 Returns whether one valid brace literal actually uses brace syntax.
 
template<Print::Text Source>
consteval bool UsesPrintfSyntax ()
 Returns whether one valid printf literal actually uses printf syntax.
 
template<Print::Text Source>
consteval bool FormatSourceValid ()
 Returns whether one brace-style source is source-level valid.
 
template<Print::Text Source>
consteval bool PrintfSourceValid ()
 Returns whether one printf-style source is source-level valid.
 
template<Print::Text Source, typename... Args>
consteval bool FormatMatches ()
 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 ()
 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 ()
 Selects the logger frontend for one literal plus one concrete argument list.
 
template<Frontend Forced, Print::Text Source, typename... Args>
consteval Frontend SelectFrontend ()
 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 literal frontend selection mode.

Logger 字面量前端选择模式。

Enumerator
Auto 

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

Format 

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

Printf 

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

Definition at line 18 of file literal.hpp.

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

◆ Resolution

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

Result of resolving one logger literal against the available frontends.

将一条 logger 字面量与可用前端进行解析后的结果。

Enumerator
None 

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

Format 

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

Printf 

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

Ambiguous 

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

Definition at line 30 of file literal.hpp.

31{
32 None,
33 Format,
34 Printf,
35 Ambiguous,
36};
@ Ambiguous
both frontends remain valid and both syntaxes are used / 两个前端都可用且都真的使用了自己的语法

Function Documentation

◆ FormatMatches()

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

Returns whether one argument list is accepted by the brace frontend, guarded by source-level validity first.

判断一组参数是否能被 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. logger 自动检测不能把多余实参当作 brace 字面量的无害输入,否则不受支持的 printf 风格源串可能回退成 brace 纯文本并静默丢弃实参。

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

Returns whether one brace-style source is source-level valid.

判断一条 brace 风格源串在源级上是否合法。

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

Returns whether one argument list is accepted by the printf frontend, guarded by source-level validity first.

判断一组参数是否能被 printf 前端接受;会先做源级合法性保护。

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

Returns whether one printf-style source is source-level valid.

判断一条 printf 风格源串在源级上是否合法。

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

Selects the logger frontend for one literal plus one concrete argument list.

为一条 logger 字面量及一组具体参数选择前端。

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()
Returns whether one argument list is accepted by the brace frontend, guarded by source-level validity...
Definition literal.hpp:106
consteval bool PrintfMatches()
Returns whether one argument list is accepted by the printf frontend, guarded by source-level validit...
Definition literal.hpp:124

◆ SelectFrontend()

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

Selects the final logger frontend after validating the resolution result.

在校验解析结果后,选择最终 logger 前端。

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(resolution == Resolution::Format,
204 "LibXR::Logger: XR_FMT(...) literal is not accepted by the brace frontend");
205 return Frontend::Format;
206 }
207 else if constexpr (Forced == Frontend::Printf)
208 {
209 static_assert(
210 resolution == Resolution::Printf,
211 "LibXR::Logger: XR_PRINTF(...) literal is not accepted by the printf frontend");
212 return Frontend::Printf;
213 }
214 else if constexpr (resolution == Resolution::Format)
215 {
216 return Frontend::Format;
217 }
218 else if constexpr (resolution == Resolution::Printf)
219 {
220 return Frontend::Printf;
221 }
222 else if constexpr (resolution == Resolution::Ambiguous)
223 {
224 static_assert(resolution != Resolution::Ambiguous,
225 "LibXR::Logger: literal is ambiguous between brace and printf frontends; use XR_FMT(...) or XR_PRINTF(...)");
226 return Frontend::Auto;
227 }
228 else
229 {
230 static_assert(resolution != Resolution::None,
231 "LibXR::Logger: literal matches neither brace nor printf frontend");
232 return Frontend::Auto;
233 }
234}
consteval Resolution ResolveFrontend()
Selects the logger frontend for one literal plus one concrete argument list.
Definition literal.hpp:142

◆ UsesFormatSyntax()

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

Returns whether one valid brace literal actually uses brace syntax.

判断一条合法 brace 字面量是否真的使用了 brace 语法。

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

Returns whether one valid printf literal actually uses printf syntax.

判断一条合法 printf 字面量是否真的使用了 printf 语法。

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}