命名空间
变体
操作

std::basic_syncbuf

来自 cppreference.cn
< cpp‎ | io
 
 
 
 
定义于头文件 <syncstream>
template<

    class CharT,
    class Traits = std::char_traits<CharT>,
    class Allocator = std::allocator<CharT>

> class basic_syncbuf : public std::basic_streambuf<CharT, Traits>
(C++20 起)

std::basic_syncbuf 是一个 std::basic_streambuf 的包装器(在构造时以指针形式提供)。它在自己的内部缓冲区中累积输出,并在销毁时以及明确请求时原子地将其全部内容传输到被包装的缓冲区,使得它们显示为连续的字符序列。它保证没有数据竞争,也没有发送到被包装缓冲区的字符交错,只要对同一缓冲区的其他所有输出都通过(可能是不同的)std::basic_syncbuf 实例进行。

std::basic_syncbuf 的典型实现包含一个指向被包装的 std::basic_streambuf 的指针,一个布尔标志指示缓冲区是否会在同步(flush)时将其内容传输到被包装的缓冲区,一个布尔标志指示当策略不是在同步时发出(emit)时存在挂起的 flush,一个使用 Allocator(例如 std::string)的内部缓冲区,以及一个指向用于在多个访问同一被包装流缓冲区的线程之间同步发出操作的互斥锁的指针(这些互斥锁可能在一个哈希映射中,以指向 std::basic_streambuf 对象的指针作为键)。

像其他 streambuf 类一样,std::basic_syncbuf 通常只通过相应的流 std::osyncstream 访问,而不是直接访问。

提供了用于常见字符类型的几个 typedef

定义于头文件 <syncstream>
类型 定义
std::syncbuf std::basic_syncbuf<char>
std::wsyncbuf std::basic_syncbuf<wchar_t>

目录

[编辑] 成员类型

成员类型 定义
char_type CharT[编辑]
traits_type Traits;如果 Traits::char_type 不是 CharT,则程序格式错误。[编辑]
int_type Traits::int_type[编辑]
pos_type Traits::pos_type[编辑]
off_type Traits::off_type[编辑]
allocator_type Allocator
streambuf_type std::basic_streambuf<CharT, Traits>

[编辑] 成员函数

公开成员函数

构造 basic_syncbuf 对象
(public 成员函数) [编辑]
赋值 basic_syncbuf 对象
(public 成员函数) [编辑]
交换两个 basic_syncbuf 对象
(public 成员函数) [编辑]
销毁 basic_syncbuf 并发出其内部缓冲区
(public 成员函数) [编辑]
原子地将整个内部缓冲区传输到被包装的 streambuf
(public 成员函数) [编辑]
检索被包装的 streambuf 指针
(public 成员函数) [编辑]
检索此 basic_syncbuf 使用的分配器
(public 成员函数) [编辑]
更改当前同步时发出策略
(public 成员函数) [编辑]

受保护的成员函数

根据当前同步时发出策略,要么发出,要么记录挂起的 flush
(public 成员函数) [编辑]

[编辑] 非成员函数

特化 std::swap 算法
(函数模板) [编辑]

继承自 std::basic_streambuf

成员类型

成员类型 定义
char_type CharT[编辑]
traits_type Traits;如果 Traits::char_type 不是 CharT,则程序格式错误。[编辑]
int_type Traits::int_type[编辑]
pos_type Traits::pos_type[编辑]
off_type Traits::off_type[编辑]

成员函数

销毁 basic_streambuf 对象
(std::basic_streambuf<CharT,Traits> 的虚公有成员函数) [编辑]
区域设置
更改关联的区域设置并调用 imbue()
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
获取关联区域设置的副本
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
定位
调用 setbuf()
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
调用 seekoff()
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
调用 seekpos()
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
调用 sync()
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
获取区
获取获取区中立即可用的字符数
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
推进输入序列,然后读取一个字符而不再次推进
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
(C++17 中移除)
从输入序列中读取一个字符并推进序列
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
从输入序列中读取一个字符而不推进序列
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
调用 xsgetn()
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
放置区
将一个字符写入放置区并推进下一个指针
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
调用 xsputn()
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
回放
将一个字符放回输入序列
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]
将输入序列中的下一个指针后退一个位置
(std::basic_streambuf<CharT,Traits> 的公有成员函数) [编辑]

受保护的成员函数

构造 basic_streambuf 对象
(protected 成员函数) [编辑]
(C++11)
替换 basic_streambuf 对象
(protected 成员函数) [编辑]
(C++11)
交换两个 basic_streambuf 对象
(protected 成员函数) [编辑]
区域设置
[virtual]
响应关联区域设置的更改
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
定位
[virtual]
如果允许,用用户定义的数组替换缓冲区
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
[virtual]
使用相对寻址重新定位输入序列、输出序列或两者的下一个指针
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
[virtual]
使用绝对寻址重新定位输入序列、输出序列或两者的下一个指针
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
[virtual]
将缓冲区与关联的字符序列同步
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
获取区
[virtual]
如果已知,获取关联输入序列中可用于输入的字符数
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
[virtual]
从关联输入序列中读取字符到获取区
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
[virtual]
从关联输入序列中读取字符到获取区并推进下一个指针
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
[virtual]
从输入序列中读取多个字符
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
返回获取区起始、当前字符和结尾的指针
(protected 成员函数) [编辑]
推进输入序列中的下一个指针
(protected 成员函数) [编辑]
重新定位输入序列的起始、下一个和结束指针
(protected 成员函数) [编辑]
放置区
[virtual]
向输出序列写入多个字符
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
[virtual]
从放置区向关联输出序列写入字符
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]
返回放置区起始、当前字符和结尾的指针
(protected 成员函数) [编辑]
推进输出序列的下一个指针
(protected 成员函数) [编辑]
重新定位输出序列的起始、下一个和结束指针
(protected 成员函数) [编辑]
回放
[virtual]
将一个字符放回输入序列,可能会修改输入序列
(std::basic_streambuf<CharT,Traits> 的虚保护成员函数) [编辑]

[编辑] 注意

特性测试 标准 特性
__cpp_lib_syncbuf 201803L (C++20) 同步缓冲输出流(std::syncbufstd::osyncstream)和操纵符