结构体 ara::log::Format
[SWS_LOG_00207] Upstream: RS_LT_00046
struct Format final {...};
A type holding a formatting hint. The interpretation of precision depends on fmt: For integral types (i.e. Fmt::kDec, Fmt::kOct, Fmt::kHex, Fmt::kBin), precision is interpreted as the minimum number of digits to output, similar to e.g. std::printf("%.7d"). For the floating-point specifiers Fmt::kDecFloat, Fmt::kEngFloat and Fmt::kHexFloat, precision denotes the exact number of digits to be shown after the decimal point; for Fmt::kAutoFloat, precision denotes the number of significant digits to be shown according to the rules of the std::printf "%g" specifier. If fmt is Fmt::kDefault, the precision field is ignored, and an implementation-defined formatting is applied. For integral types, if precision is 0, it is interpreted the same as if it was 1. For convenience, there are helper functions to create specific instances of this struct. The helper functions should be used instead of creating instances manually.
Header-Datei #include "ara/log/logger.h" Forwarding-Header #include "ara/log/log_fwd.h" Scope namespace ara::log
用户指南人工智能生成 用作格式化提示,以在输出日志值时控制表示格式和精度。
AI 生成
未审核
模型: gemini-3.8-flash-medium · 推理强度: medium · 温度: 不可控 · 提示词: ae5714d3cea4
来源
未决问题(2)
摘要 详细
用作格式化提示,以在输出日志值时控制表示格式和精度。
结构体 ara::log::Format 用作日志系统中的格式化提示,将格式说明符 fmt([SWS_LOG_00225] )与精度规范 precision([SWS_LOG_00226] )绑定在一起。实例应优先通过提供的辅助函数创建,其中对 precision 的求值根据格式类型在整数的最少位数与浮点数的小数位数之间进行区分。对于整数类型,精度为零会被视作一,而在 Fmt::kDefault 下该字段会被完全忽略。
更多 ›
上下文
数据结构 ara::log::Format 在 AUTOSAR Adaptive Platform 的日志框架中用作输出格式化值的格式化提示。为此,它捆绑了两个核心属性:枚举类型 Fmt 的格式说明 fmt([SWS_LOG_00225] )以及作为 std::uint16_t 的相关精度 precision([SWS_LOG_00226] )。交互伙伴包括日志模块的输出组件和格式化流,以及生成具有格式化文本输出的日志消息的应用程序逻辑。Interpretation:规范中提到的用于实例化的辅助函数可能直接位于模块 ara::log 中,以提供标准化格式化。 问题 Q-1c465e69c99359fa (未决)
生命周期
作为最终数据结构(struct Format final),ara::log::Format 没有内部状态机,也没有复杂的阶段转换。尽管属性被声明为公共变量([SWS_LOG_00225] ,[SWS_LOG_00226] ),但规范明确要求不要手动创建实例,而是使用提供的辅助函数。实例通常是寿命短暂的值对象,通过复制或引用传递给日志流。Interpretation:由于该结构不包含内部同步,跨线程边界的复制和并发读取访问可能是线程安全的,而可变访问必须进行外部同步。 问题 Q-bd0f1147e9472c19 (未决)
使用路径
典型用法包括确定格式说明符 fmt([SWS_LOG_00225] )并指定所需的精度 precision([SWS_LOG_00226] )。对 precision 的求值取决于 fmt 中选择的类型:
整数类型: 对于 Fmt::kDec、Fmt::kOct、Fmt::kHex 和 Fmt::kBin,precision 表示要输出的最少位数,类似于通过 std::printf("%.7d") 进行的格式化。
定点和指数表示的浮点类型: 对于 Fmt::kDecFloat、Fmt::kEngFloat 和 Fmt::kHexFloat,precision 指定小数位数的精确数量。
自动浮点表示: 在 Fmt::kAutoFloat 下,precision 根据 std::printf 中格式说明符 %g 的规则定义有效位数。
默认格式化: 当 fmt 的值为 Fmt::kDefault 时,precision 中的指定会被忽略,并应用由实现决定的格式化。
活动图:依赖于 fmt 对 precision 求值的分支逻辑。来源:[SWS_LOG_00225] ,[SWS_LOG_00226]
错误场景
该结构不定义错误码或异常;边界情况改为以容错且确定性的方式处理。对于整数格式标识符(Fmt::kDec、Fmt::kOct、Fmt::kHex、Fmt::kBin),值 precision = 0([SWS_LOG_00226] )的求值在语义上等同于值 1,以防止空输出。如果 fmt 设置为 Fmt::kDefault([SWS_LOG_00225] ),则 precision 中设置的值不会导致错误状态,而是会被静默丢弃。
本指南基于 AUTOSAR Adaptive Platform R25-11 日志模块规范的要求。
UML 类图 Hohle Dreieckspfeile = Vererbung (zeigt zur Basisklasse); Klicken öffnet die jeweilige Klassenseite.
G
nara__log__Format351
«struct»
Format
+ fmt
+ precision
常量 / 变量文档
Fmt fmt;
Status: valid/auto-approved
Version: rel:R25-11#04613a79
Versionshistorie & Revisions (2 transitions, 6 revision)
Current State valid/auto-approved
Reason unchanged
Campaign 2026-08-sws-log-pilot-after-tool-improvement
Active Version AUTOSAR/AP/record/SWS_LOG_00225@rel:R25-11#04613a79
Point-in-Time History:
Release:
R25-11 (Current / Active) R21-11 R22-11 R23-11 R24-11 R20-11 R19-11
View Snapshot
Recorded Revisions (6):
R25-11 rel:R25-11#637a0dc22026-09-30 Inspect R21-11 rel:R21-11#b0525fe12026-10-14 Inspect R22-11 rel:R22-11#81b856192026-10-14 Inspect R23-11 rel:R23-11#04613a792026-10-14 Inspect R24-11 rel:R24-11#04613a792026-10-14 Inspect R25-11 rel:R25-11#04613a792026-10-14 active Inspect
Historical Snapshot:
× Back to current
🚫
Requirement entfallen: Dieses Element ist im gewählten Release nicht mehr enthalten.
Requirement Text as-of this release:
Reachable Artifacts & Dependents:
Date Actor Transition Reason / Rationale Campaign
2026-08-10 tool valid/unversioned → invalid/obsoletespec update after tool improvement 2026-08-sws-log-pilot-after-tool-improvement 2026-08-10 tool invalid/obsolete → valid/auto-approvedunchanged 2026-08-sws-log-pilot-after-tool-improvement
std::uint16_t precision;
Header-Datei #include "ara/log/logger.h" Scope struct ara::log::Format Symbol precision Typ std::uint16_t
Status: valid/auto-approved
Version: rel:R25-11#c555de85
Versionshistorie & Revisions (2 transitions, 6 revision)
Current State valid/auto-approved
Reason unchanged
Campaign 2026-08-sws-log-pilot-after-tool-improvement
Active Version AUTOSAR/AP/record/SWS_LOG_00226@rel:R25-11#c555de85
Point-in-Time History:
Release:
R25-11 (Current / Active) R21-11 R22-11 R23-11 R24-11 R20-11 R19-11
View Snapshot
Recorded Revisions (6):
R25-11 rel:R25-11#ee3180342026-09-30 Inspect R21-11 rel:R21-11#c847203d2026-10-14 Inspect R22-11 rel:R22-11#406eff9e2026-10-14 Inspect R23-11 rel:R23-11#c555de852026-10-14 Inspect R24-11 rel:R24-11#c555de852026-10-14 Inspect R25-11 rel:R25-11#c555de852026-10-14 active Inspect
Historical Snapshot:
× Back to current
🚫
Requirement entfallen: Dieses Element ist im gewählten Release nicht mehr enthalten.
Requirement Text as-of this release:
Reachable Artifacts & Dependents:
Date Actor Transition Reason / Rationale Campaign
2026-08-10 tool valid/unversioned → invalid/obsoletespec update after tool improvement 2026-08-sws-log-pilot-after-tool-improvement 2026-08-10 tool invalid/obsolete → valid/auto-approvedunchanged 2026-08-sws-log-pilot-after-tool-improvement
gemini-3.8-flash-low· 2026-10-13 · 德文原文