YSTest: TextManager.h 源文件

YSTest PreAlpha_b800_20170810 The YSLib Test Project

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

- 文件列表
- 文件成员

TextManager.h
浏览该文件的文档.
1 /*
2 © 2010-2017 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 YSL_INC_Service_TextManager_h_
29 #define YSL_INC_Service_TextManager_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YString
33 #include YFM_YSLib_Service_TextFile
34 #include <ystdex/iterator_op.hpp> // for ystdex::bidirectional_iteratable;
35 #include <streambuf> // for std::streambuf;
36
37 namespace YSLib
38 {
39
40 namespace Text
41 {
42
47 class YF_API TextFileBuffer
48 {
49 public:
56 using BlockType = pair<vector<char16_t>, size_t>;
63 using MapType = map<size_t, BlockType>;
69 class YF_API iterator : public std::iterator<
70 std::bidirectional_iterator_tag, char16_t, ptrdiff_t, const char16_t*,
71 const char16_t&>, public ystdex::bidirectional_iteratable<
72 TextFileBuffer::iterator, const char16_t&>
73 {
74 friend class TextFileBuffer;
75
76 private:
78 TextFileBuffer* p_buffer;
79 //文本读取位置。
80 size_t block;
81 size_t index;
82
83 public:
87 iterator(TextFileBuffer* = {}, size_t = 0, size_t = 0) ynothrow;
88
92 iterator&
93 operator++() ynothrow;
94
98 iterator&
99 operator--() ynothrow;
100
102 reference
103 operator*() const;
104
108 YF_API friend bool
109 operator==(const iterator&, const iterator&) ynothrow;
110
112 DefGetter(const ynothrow, observer_ptr<TextFileBuffer>, BufferPtr,
113 make_observer(p_buffer))
114 DefGetter(const ynothrow, size_t, BlockN, block)
115 DefGetter(const ynothrow, size_t, IndexN, index)
116 };
117 using const_iterator = iterator;
119
124 static yconstexpr const size_t BlockSize = 2048U;
125
126 protected:
131 std::streambuf& File;
132
133 private:
135
136 size_t fsize;
137 Encoding encoding;
138 size_t bl;
140
142 size_t n_text_size;
145 size_t n_block;
147 MapType buffer{};
149
150 private:
156 size_t fixed_width;
161 size_t max_width;
162
163 public:
171 explicit
172 TextFileBuffer(std::streambuf&, Encoding = CharSet::Null);
173
180 BlockType&
181 operator[](size_t);
182
187 DefGetter(const ynothrow, size_t, BlockN, n_block)
188 DefGetter(const ynothrow, Encoding, Encoding, encoding)
189 DefGetter(const ynothrow, size_t, Size, fsize)
190 DefGetter(const ynothrow, size_t, TextSize, n_text_size)
191
196 iterator
197 GetIterator(size_t);
202 size_t
203 GetPosition(iterator);
204
210 void
211 Seek(std::streamoff);
212
214
215
219 iterator
220 begin() ynothrow;
221
226 iterator
227 end() ynothrow;
229 };
230
231
239 YF_API string
240 CopySliceFrom(TextFileBuffer&, size_t, size_t);
241
242 } // namespace Text;
243
244 } // namespace YSLib;
245
246 #endif
247
YSLib::Drawing::buffer
The boundary is out of the buffer
Definition: YDraw.h:118
YModules.h
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:326
ystdex::details::ebases
Definition: operators.hpp:100
YSLib::Text::TextFileBuffer::max_width
size_t max_width
最大编码每字符的字节数。
Definition: TextManager.h:161
YSLib::Text::TextFileBuffer::iterator::block
size_t block
Definition: TextManager.h:80
YSLib::Text::TextFileBuffer::iterator::p_buffer
TextFileBuffer * p_buffer
Definition: TextManager.h:78
Text
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:679
CHRLib::CharSet::Null
空字符集。
Definition: Encoding.h:63
ystdex::cpp2011::end
_type * end(_type(&&array)[_vN])
Definition: range.hpp:54
YSLib::Text::TextFileBuffer
文本文件块缓冲区。
Definition: TextManager.h:47
YSLib::Text::CopySliceFrom
YF_API string CopySliceFrom(TextFileBuffer &, size_t, size_t)
从文本文件缓冲区复制指定字节位置起始的字符串。
Definition: TextManager.cpp:347
YF_API
#define YF_API
Definition: Platform.h:56
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YSLib::Text::TextFileBuffer::fixed_width
size_t fixed_width
固定编码每字符的字节数。
Definition: TextManager.h:156
std
Definition: memory.hpp:1183
iterator_op.hpp
迭代器操作。
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::Text::TextFileBuffer::iterator
目标编码迭代器类型。
Definition: TextManager.h:69
YSLib::Text::TextFileBuffer::BlockType
pair< vector< char16_t >, size_t > BlockType
缓冲区块类型。
Definition: TextManager.h:56
CHRLib::CharSet::Encoding
Encoding
字符流编码标识。
Definition: Encoding.h:58
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::Text::TextFileBuffer::iterator::index
size_t index
Definition: TextManager.h:81
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
YSLib::Text::TextFileBuffer::MapType
map< size_t, BlockType > MapType
缓冲映射类型。
Definition: TextManager.h:63