Boost C++ 库

…世界上最受推崇、设计最精良的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu, C++ Coding Standards

read_until (24 个重载中的第 16 个) - Boost C++ 函数库
PrevUpHomeNext

将数据读取到 streambuf 中,直到函数对象指示匹配。

template<
    typename SyncReadStream,
    typename Allocator,
    typename MatchCondition>
std::size_t read_until(
    SyncReadStream & s,
    boost::asio::basic_streambuf< Allocator > & b,
    MatchCondition match_condition,
    boost::system::error_code & ec,
    constraint_t< is_match_condition< MatchCondition >::value >  = 0);

此函数用于将数据读取到指定的 streambuf 中,直到用户定义的匹配条件函数对象应用于 streambuf 中包含的数据时,指示匹配成功。调用将阻塞,直到以下任一条件为真

  • 匹配条件函数对象返回一个 `std::pair`,其中第二个元素求值为 true。
  • 发生错误。

此操作通过零次或多次调用流的 read_some 函数来实现。如果匹配条件函数对象已指示匹配,则函数会立即返回。

参数

s

要从中读取数据的流。类型必须支持 SyncReadStream 概念。

b

一个 streambuf 对象,数据将被读取到其中。

match_condition

将要调用的函数对象,用于确定是否存在匹配。函数对象的签名必须为:

pair<iterator, bool> match_condition(iterator begin, iterator end);

其中 iterator 代表类型

buffers_iterator<basic_streambuf<Allocator>::const_buffers_type>

迭代器参数 beginend 定义了要扫描以确定是否存在匹配的字节范围。返回值中的 first 成员是一个迭代器,标记了匹配函数已消耗的字节的末尾之后的一个位置。此迭代器用于计算匹配条件后续调用的 begin 参数。返回值的 second 成员为 true(如果找到匹配),否则为 false。

ec

用于指示发生何种错误(如果有)。

返回值

匹配函数已完全消耗的 streambuf 的 get 区域中的字节数。如果发生错误,则返回 0。

备注

在成功的 read_until 操作后,streambuf 可能包含超出匹配函数对象数据的其他数据。应用程序通常会将这些数据保留在 streambuf 中,供后续的 read_until 操作检查。

备注

is_match_condition 类型特征的默认实现对具有 result_type 类型的函数指针和函数对象求值为 true。它必须为其他用户定义的函数对象进行特化。


PrevUpHomeNext