YSTest: streambuf.hpp 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

streambuf.hpp
浏览该文件的文档.
1 /*
2 © 2015-2016 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YB_INC_ystdex_streambuf_hpp_
29 #define YB_INC_ystdex_streambuf_hpp_ 1
30
31 #include "algorithm.hpp" // for ystdex::equal;
32 #include <streambuf> // for std::basic_streambuf;
33 #include <iterator> // for std::istreambuf_iterator;
34
35 namespace ystdex
36 {
37
43 template<typename _tChar, class _tTraits>
44 bool
45 streambuf_equal(std::basic_streambuf<_tChar, _tTraits>& a,
46 std::basic_streambuf<_tChar, _tTraits>& b)
47 {
48 using iter_type = std::istreambuf_iterator<_tChar, _tTraits>;
49
50 return
51 ystdex::equal(iter_type(&a), iter_type(), iter_type(&b), iter_type());
52 }
53
54
56
57
61 template<typename _tChar, class _tTraits = std::char_traits<_tChar>>
62 class basic_membuf : public std::basic_streambuf<_tChar, _tTraits>
63 {
64 public:
65 using char_type = _tChar;
66 using int_type = typename _tTraits::int_type;
67 using pos_type = typename _tTraits::pos_type;
68 using off_type = typename _tTraits::off_type;
69 using traits_type = _tTraits;
70
71 YB_NONNULL(2)
72 basic_membuf(const char_type* buf, size_t size)
73 {
74 yconstraint(buf);
75 // NOTE: This should be safe since get area is not used to be written.
76 const auto p(const_cast<char_type*>(buf));
77
78 this->setg(p, p, p + size);
79 }
80 };
81
82 using membuf = basic_membuf<char>;
83 using wmembuf = basic_membuf<wchar_t>;
85
86 } // namespace ystdex;
87
88 #endif
89
algorithm.hpp
泛型算法。
ystdex::basic_membuf::pos_type
typename _tTraits::pos_type pos_type
Definition: streambuf.hpp:67
YSLib::Text::buf
const char * buf
Definition: TextFile.h:81
ystdex::basic_membuf::off_type
typename _tTraits::off_type off_type
Definition: streambuf.hpp:68
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:167
ystdex::basic_membuf::int_type
typename _tTraits::int_type int_type
Definition: streambuf.hpp:66
ystdex::cpp2014::equal
bool equal(_tIn1 first1, _tIn1 last1, _tIn2 first2, _tIn2 last2, _fBiPred binary_pred)
Definition: algorithm.hpp:181
ystdex::basic_membuf::char_type
_tChar char_type
Definition: streambuf.hpp:65
ystdex
特性测试宏。
Definition: ydef.h:822
ystdex::basic_membuf::traits_type
_tTraits traits_type
Definition: streambuf.hpp:69
ystdex::basic_membuf
内存中储存不具有所有权的只读流缓冲。
Definition: streambuf.hpp:62
ystdex::size
auto size(const _tRange &c) -> decltype(c.size())
类容器访问。
Definition: range.hpp:233
ystdex::streambuf_equal
bool streambuf_equal(std::basic_streambuf< _tChar, _tTraits > &a, std::basic_streambuf< _tChar, _tTraits > &b)
比较指定流缓冲区的内容相等。
Definition: streambuf.hpp:45
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:88
CHRLib::p
const auto p(d)