提供静态全局的输入输出接口绑定与写会话管理 / STDIO interface for read and write ports
More...
#include <stdio.hpp>
|
| template<Print::Text Source, typename... Args> |
| static int | Print (Args &&... args) |
| | 将一个编译期 brace 字面量打印到当前 STDIO 输出 / Print one compile-time brace literal to the active STDIO output
|
| |
| template<Print::Text Source, typename... Args> |
| static int | Printf (Args &&... args) |
| | 将一个编译期 printf 字面量打印到当前 STDIO 输出 / Print one compile-time printf literal to the active STDIO output
|
| |
|
| static int | WriteCompiledToStream (WritePort::Stream &stream, void *context, CompiledWriteFun write_fun) |
| | 在指定 Stream 上执行一次完整的 STDIO 编译格式写入与收尾 / Run one complete STDIO compiled-format write and finalize pass on the given Stream
|
| |
| static int | WriteCompiledSession (void *context, CompiledWriteFun write_fun) |
| | 执行一次完整的 STDIO 编译格式流会话选择、写入与收尾 / Run one complete STDIO compiled-format stream session: stream selection, write, and finalization
|
| |
| template<typename Call > |
| static int | RunCompiledSession (Call &call) |
| | 执行一次模板已知的 STDIO 编译格式会话 / Run one STDIO compiled-format session whose format and argument types are already known at compile time
|
| |
| template<typename CompiledFormat , typename... Args> |
| static int | RunCompiled (const CompiledFormat &format, Args &&... args) |
| | 用一份已编译格式和一组运行时参数执行一次完整的 STDIO 写会话 / Run one complete STDIO write session with one compiled format and one runtime argument pack
|
| |
| static bool | BeginWriteSession () |
| | 获取一个共享的 STDIO 写入会话 / Acquire one shared STDIO write session
|
| |
| static int | FinishWriteSession (WritePort::Stream &stream, size_t retained_size, ErrorCode format_result) |
| | 提交当前编译格式会话的写入流并释放共享会话 / Commit the current compiled-format session stream and release the shared session
|
| |
提供静态全局的输入输出接口绑定与写会话管理 / STDIO interface for read and write ports
Definition at line 19 of file stdio.hpp.
◆ CompiledWriteFun
◆ BeginWriteSession()
| bool STDIO::BeginWriteSession |
( |
| ) |
|
|
staticnodiscardprivate |
获取一个共享的 STDIO 写入会话 / Acquire one shared STDIO write session
- Returns
- 成功获取共享写会话返回
true,否则返回 false / Returns true on success, otherwise false
Definition at line 51 of file stdio.cpp.
52{
54 {
55 return false;
56 }
57
59 {
61 }
62
64}
互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms).
ErrorCode Lock()
加锁,如果锁已被占用,则阻塞等待 (Lock the mutex, blocking if it is already locked).
static LibXR::Mutex * write_mutex_
Write port mutex. 写入端口互斥锁。
static WritePort * write_
Write port instance. 写入端口。
@ OK
操作成功 | Operation successful
◆ FinishWriteSession()
提交当前编译格式会话的写入流并释放共享会话 / Commit the current compiled-format session stream and release the shared session
- Parameters
-
| stream | 当前会话使用的写入流 / Write stream used by the current session |
| retained_size | 当前会话真正保留下来的字节数 / Byte count actually retained by the current session |
| format_result | 本次格式化写出阶段的状态 / Status returned by the formatting write phase |
- Returns
- 当前 STDIO 会话最终提交的字节数;失败返回
-1 / Byte count finally committed by the current STDIO session; returns -1 on failure
Definition at line 89 of file stdio.cpp.
91{
93
94
95
96
97
98
100
102
104 retained_size > static_cast<size_t>(std::numeric_limits<int>::max()))
105 {
106 return -1;
107 }
108
109 return static_cast<int>(retained_size);
110}
void Unlock()
解锁互斥锁 (Unlock the mutex).
ErrorCode Commit()
手动提交已写入的数据到队列,并释放当前锁。
◆ Print()
| static int LibXR::STDIO::Print |
( |
Args &&... | args | ) |
|
|
inlinestatic |
将一个编译期 brace 字面量打印到当前 STDIO 输出 / Print one compile-time brace literal to the active STDIO output
- Template Parameters
-
| Source | 编译期 brace 格式字面量 / Compile-time brace format literal |
| Args | 调用点运行时参数类型列表 / Call-site runtime argument types |
- Parameters
-
| args | 参与本次打印的运行时参数 / Runtime arguments used by the current print |
- Returns
- 返回当前 STDIO 流实际保留并提交的字节数;若会话建立或提交失败则返回
-1 / Returns the byte count actually retained and committed to the current STDIO stream; returns -1 on session or commit failure
Definition at line 196 of file stdio.hpp.
197 {
199 return RunCompiled(format, std::forward<Args>(args)...);
200 }
static int RunCompiled(const CompiledFormat &format, Args &&... args)
用一份已编译格式和一组运行时参数执行一次完整的 STDIO 写会话 / Run one complete STDIO write session with one compiled format and...
◆ Printf()
| static int LibXR::STDIO::Printf |
( |
Args &&... | args | ) |
|
|
inlinestatic |
将一个编译期 printf 字面量打印到当前 STDIO 输出 / Print one compile-time printf literal to the active STDIO output
- Template Parameters
-
| Source | 编译期 printf 格式字面量 / Compile-time printf format literal |
| Args | 调用点运行时参数类型列表 / Call-site runtime argument types |
- Parameters
-
| args | 参与本次打印的运行时参数 / Runtime arguments used by the current print |
- Returns
- 返回当前 STDIO 流实际保留并提交的字节数;若会话建立或提交失败则返回
-1 / Returns the byte count actually retained and committed to the current STDIO stream; returns -1 on session or commit failure
Definition at line 210 of file stdio.hpp.
211 {
213 return RunCompiled(format, std::forward<Args>(args)...);
214 }
static consteval Compiled< Source > Build()
在编译期解析并校验 printf 格式串 / Parse and validate a printf format at compile time
◆ RunCompiled()
template<typename CompiledFormat , typename... Args>
| static int LibXR::STDIO::RunCompiled |
( |
const CompiledFormat & | format, |
|
|
Args &&... | args ) |
|
inlinestaticnodiscardprivate |
用一份已编译格式和一组运行时参数执行一次完整的 STDIO 写会话 / Run one complete STDIO write session with one compiled format and one runtime argument pack
- Template Parameters
-
| CompiledFormat | 编译后的格式类型 / Compiled format type |
| Args | 运行时参数类型列表 / Runtime argument types |
- Parameters
-
| format | 编译后的格式对象 / Compiled format object |
| args | 参与本次写会话的运行时参数 / Runtime arguments used by the current write session |
- Returns
- 当前 STDIO 会话最终提交的字节数;失败返回
-1 / Byte count finally committed by the current STDIO session; returns -1 on failure
Definition at line 162 of file stdio.hpp.
163 {
164 CompiledCall<CompiledFormat, Args...> call{
165 format, std::forward_as_tuple(std::forward<Args>(args)...)};
167 }
static int RunCompiledSession(Call &call)
执行一次模板已知的 STDIO 编译格式会话 / Run one STDIO compiled-format session whose format and argument types are al...
◆ RunCompiledSession()
template<typename Call >
| static int LibXR::STDIO::RunCompiledSession |
( |
Call & | call | ) |
|
|
inlinestaticnodiscardprivate |
执行一次模板已知的 STDIO 编译格式会话 / Run one STDIO compiled-format session whose format and argument types are already known at compile time
该 helper 只保留模板相关的最薄一层:拿共享会话,再把类型化调用对象交给 WriteCompiledSession()。 This helper keeps only the thinnest template layer: acquire the shared session, then pass the typed call object into WriteCompiledSession().
- Template Parameters
-
| Call | 类型化编译格式调用对象 / Typed compiled-format call object |
- Parameters
-
| call | 当前会话的类型化调用对象 / Typed call object for the current session |
- Returns
- 当前 STDIO 会话最终提交的字节数;失败返回
-1 / Byte count finally committed by the current STDIO session; returns -1 on failure
Definition at line 143 of file stdio.hpp.
144 {
146 {
147 return -1;
148 }
149
151 }
static int WriteCompiledSession(void *context, CompiledWriteFun write_fun)
执行一次完整的 STDIO 编译格式流会话选择、写入与收尾 / Run one complete STDIO compiled-format stream session: stream selecti...
static bool BeginWriteSession()
获取一个共享的 STDIO 写入会话 / Acquire one shared STDIO write session
◆ WriteCompiledSession()
| int STDIO::WriteCompiledSession |
( |
void * | context, |
|
|
CompiledWriteFun | write_fun ) |
|
staticnodiscardprivate |
执行一次完整的 STDIO 编译格式流会话选择、写入与收尾 / Run one complete STDIO compiled-format stream session: stream selection, write, and finalization
若当前已存在外部绑定的 write_stream_,则复用它;否则创建一个临时的 WritePort::Stream 供本次会话使用。 Reuses the externally bound write_stream_ when available; otherwise creates one temporary WritePort::Stream for the current session.
- Parameters
-
| context | 前端桥接函数对应的类型擦除上下文 / Type-erased context consumed by the frontend bridge |
| write_fun | 前端桥接写入函数 / Frontend bridge write function |
- Returns
- 当前 STDIO 会话最终提交的字节数;失败返回
-1 / Byte count finally committed by the current STDIO session; returns -1 on failure
Definition at line 74 of file stdio.cpp.
75{
77 ASSERT(write_fun != nullptr);
78
80 {
82 }
83
87}
static LibXR::WritePort::Stream * write_stream_
Optional externally owned write stream. 可选的外部托管写流。
static int WriteCompiledToStream(WritePort::Stream &stream, void *context, CompiledWriteFun write_fun)
在指定 Stream 上执行一次完整的 STDIO 编译格式写入与收尾 / Run one complete STDIO compiled-format write and finalize pass ...
◆ WriteCompiledToStream()
| int STDIO::WriteCompiledToStream |
( |
WritePort::Stream & | stream, |
|
|
void * | context, |
|
|
CompiledWriteFun | write_fun ) |
|
staticnodiscardprivate |
在指定 Stream 上执行一次完整的 STDIO 编译格式写入与收尾 / Run one complete STDIO compiled-format write and finalize pass on the given Stream
该 helper 统一负责:构造 CompiledSink、调用前端桥接函数、再用 FinishWriteSession() 做最终提交或丢弃。 This helper centralizes: constructing CompiledSink, invoking the frontend bridge, then finalizing through FinishWriteSession().
- Parameters
-
| stream | 本次会话绑定的写入流 / Write stream bound to the current session |
| context | 前端桥接函数对应的类型擦除上下文 / Type-erased context consumed by the frontend bridge |
| write_fun | 前端桥接写入函数 / Frontend bridge write function |
- Returns
- 当前 STDIO 会话最终提交的字节数;失败返回
-1 / Byte count finally committed by the current STDIO session; returns -1 on failure
Definition at line 66 of file stdio.cpp.
68{
69 CompiledSink sink(stream);
70 auto ec = write_fun(context, sink);
72}
static int FinishWriteSession(WritePort::Stream &stream, size_t retained_size, ErrorCode format_result)
提交当前编译格式会话的写入流并释放共享会话 / Commit the current compiled-format session stream and release the shared sess...
◆ read_
Read port instance. 读取端口。
Definition at line 25 of file stdio.hpp.
◆ write_
Write port instance. 写入端口。
Definition at line 26 of file stdio.hpp.
◆ write_mutex_
Initial value:
Write port mutex. 写入端口互斥锁。
Definition at line 27 of file stdio.hpp.
◆ write_stream_
Initial value:
Optional externally owned write stream. 可选的外部托管写流。
Definition at line 29 of file stdio.hpp.
The documentation for this class was generated from the following files: