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,
37};

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 107 of file literal.hpp.

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

◆ FormatSourceValid()

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

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

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

Definition at line 78 of file literal.hpp.

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

◆ 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 125 of file literal.hpp.

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

◆ PrintfSourceValid()

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

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

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

Definition at line 89 of file literal.hpp.

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

◆ 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 143 of file literal.hpp.

144{
145 constexpr bool format_match = FormatMatches<Source, Args...>();
146 constexpr bool printf_match = PrintfMatches<Source, Args...>();
147
148 if constexpr (Forced == Frontend::Format)
149 {
150 return format_match ? Resolution::Format : Resolution::None;
151 }
152 else if constexpr (Forced == Frontend::Printf)
153 {
154 return printf_match ? Resolution::Printf : Resolution::None;
155 }
156 else if constexpr (format_match && !printf_match)
157 {
158 return Resolution::Format;
159 }
160 else if constexpr (!format_match && printf_match)
161 {
162 return Resolution::Printf;
163 }
164 else if constexpr (!format_match && !printf_match)
165 {
166 return Resolution::None;
167 }
168 else
169 {
170 constexpr bool format_uses_syntax = UsesFormatSyntax<Source>();
171 constexpr bool printf_uses_syntax = UsesPrintfSyntax<Source>();
172
173 if constexpr (format_uses_syntax && !printf_uses_syntax)
174 {
175 return Resolution::Format;
176 }
177 else if constexpr (!format_uses_syntax && printf_uses_syntax)
178 {
179 return Resolution::Printf;
180 }
181 else if constexpr (!format_uses_syntax && !printf_uses_syntax)
182 {
183 return Resolution::Format;
184 }
185 else
186 {
187 return Resolution::Ambiguous;
188 }
189 }
190}
consteval bool FormatMatches()
Returns whether one argument list is accepted by the brace frontend, guarded by source-level validity...
Definition literal.hpp:107
consteval bool PrintfMatches()
Returns whether one argument list is accepted by the printf frontend, guarded by source-level validit...
Definition literal.hpp:125

◆ 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 198 of file literal.hpp.

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

◆ 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 44 of file literal.hpp.

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

◆ 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 61 of file literal.hpp.

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