libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
LibXR::Print::Writer Class Reference

运行期 writer,负责打包调用点参数并执行编译好的字节流 / Runtime writer that packs call-site arguments and executes the compiled byte stream More...

#include <writer.hpp>

Classes

class  ArgumentReader
 运行期参数字节块的顺序读取器 / Sequential reader for the packed runtime argument byte blob More...
 
class  CodeReader
 编译后记录流的顺序读取器 / Sequential reader for the compiled record stream More...
 
struct  DecimalScale
 科学计数法与通用浮点格式化使用的十进制规范化结果 / Decimal normalization result used by scientific and general float formatting More...
 
class  Executor
 按输出端共享重后端、按调用点 profile 裁剪操作码分发的字节码执行器 / Per-sink bytecode executor with shared heavy backends and per-call profile-pruned opcode dispatch More...
 
struct  ScientificDigits
 科学计数法舍入后的十进制数字块 / Rounded decimal digit block for scientific notation More...
 

Public Member Functions

template<typename Float >
Writer::ScientificDigits< Float > RoundScientificDigits (Float value, uint8_t precision)
 把一个值归一化为科学计数法的尾数数字与十进制指数 / Normalize one value into scientific-notation mantissa digits and a decimal exponent.
 
template<typename Float >
Writer::DecimalScale< Float > NormalizeDecimal (Float value)
 将一个浮点值归一化为十进制指数与缩放因子 / Normalizes one float into a decimal exponent plus scale pair.
 

Static Public Member Functions

template<typename Sink , typename Format , auto ArgumentOrder, typename... Args>
requires OutputSink<Sink> && CompiledFormat<std::remove_cvref_t<Format>>
static ErrorCode RunArgumentOrder (Sink &sink, const Format &, Args &&... args)
 执行一份编译格式;它的字段顺序与源参数顺序可以不同 / Run one compiled format whose field order and source argument order may differ
 

Detailed Description

运行期 writer,负责打包调用点参数并执行编译好的字节流 / Runtime writer that packs call-site arguments and executes the compiled byte stream

Definition at line 120 of file writer.hpp.

Member Function Documentation

◆ NormalizeDecimal()

template<typename Float >
Writer::DecimalScale< Float > LibXR::Print::Writer::NormalizeDecimal ( Float value)

将一个浮点值归一化为十进制指数与缩放因子 / Normalizes one float into a decimal exponent plus scale pair.

Template Parameters
Float浮点类型 / Float type.
Parameters
value有限正数绝对值 / Finite positive magnitude.
Returns
返回规范化后的十进制缩放描述。 Returns the normalized decimal scale description.

Definition at line 139 of file writer.hpp.

149 {
150 using Built = std::remove_cvref_t<Format>;
151 static_assert(ArgumentOrder.size() == Built::ArgumentList().size(),
152 "LibXR::Print::Writer: argument reorder list must match the "
153 "compiled field count");
154 static_assert(
155 Built::template Matches<Args...>(),
156 "LibXR::Print::Writer::RunArgumentOrder: format arguments do not match");
157
158 return RunTaggedArgumentOrder<Sink, Built::ArgumentList(), ArgumentOrder,
159 Built::Profile()>(sink, Built::Codes().data(),
160 std::forward<Args>(args)...);
161 }
162
163 private:
168 static constexpr uint8_t unspecified_precision = 0xFF;
169 template <FormatPackKind K>

◆ RoundScientificDigits()

template<typename Float >
Writer::ScientificDigits< Float > LibXR::Print::Writer::RoundScientificDigits ( Float value,
uint8_t precision )

把一个值归一化为科学计数法的尾数数字与十进制指数 / Normalize one value into scientific-notation mantissa digits and a decimal exponent.

Template Parameters
Float浮点类型 / Float type.
Parameters
value有限非负值 / Finite non-negative value.
precision尾数中保留的有效小数位数。 Significant fractional digits to retain in the mantissa.
Returns
返回舍入后的尾数、缩放因子与十进制指数;若舍入进位溢出一位,会相应调整指数。 Rounded mantissa, its scale, and the decimal exponent (carry-out adjusts the exponent when rounding overflows one digit).

Definition at line 111 of file writer.hpp.

121{
122 public:

◆ RunArgumentOrder()

template<typename Sink , typename Format , auto ArgumentOrder, typename... Args>
requires OutputSink<Sink> && CompiledFormat<std::remove_cvref_t<Format>>
static ErrorCode LibXR::Print::Writer::RunArgumentOrder ( Sink & sink,
const Format & ,
Args &&... args )
inlinestaticnodiscard

执行一份编译格式;它的字段顺序与源参数顺序可以不同 / Run one compiled format whose field order and source argument order may differ

Template Parameters
Sink输出端类型,需满足 OutputSink / Sink type satisfying OutputSink
Format编译格式类型 / Compiled format type
ArgumentOrder按字段顺序排列的源参数索引表 / Source-argument index list ordered by emitted fields
Args调用点实参类型列表 / Call-site argument types
Parameters
sink输出端 / Destination sink
format编译格式对象,仅用于约束与类型推导 / Compiled format object, used only for constraints and type deduction
args调用点实参 / Call-site arguments

这条路径用于 {1} {0} 这种格式:字段仍然按源串顺序执行, 但运行期参数包要按另一种顺序构造。 This path is used by formats such as {1} {0}: fields are still executed in source order, but the runtime argument pack must be built in another order.

Note
这条接口不重新解析源格式串;它直接执行编译好的字节流 / This function does not re-parse the source format string; it executes the compiled byte stream directly
Returns
运行期 writer 执行状态 / Returns the runtime writer status

Definition at line 147 of file writer.hpp.

149 {
150 using Built = std::remove_cvref_t<Format>;
151 static_assert(ArgumentOrder.size() == Built::ArgumentList().size(),
152 "LibXR::Print::Writer: argument reorder list must match the "
153 "compiled field count");
154 static_assert(
155 Built::template Matches<Args...>(),
156 "LibXR::Print::Writer::RunArgumentOrder: format arguments do not match");
157
158 return RunTaggedArgumentOrder<Sink, Built::ArgumentList(), ArgumentOrder,
159 Built::Profile()>(sink, Built::Codes().data(),
160 std::forward<Args>(args)...);
161 }

The documentation for this class was generated from the following files: