YSTest: TextManager.h 源文件

YSTest PreAlpha_b700_20160611 The YSLib Test Project

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

- 文件列表
- 文件成员

TextManager.h
浏览该文件的文档.
1 /*
2 © 2010-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 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
36 namespace YSLib
37 {
38
39 namespace Text
40 {
41
46 class YF_API TextFileBuffer
47 {
48 public:
55 using BlockType = pair<vector<char16_t>, size_t>;
62 using MapType = map<size_t, BlockType>;
68 class YF_API iterator : public std::iterator<
69 std::bidirectional_iterator_tag, char16_t, ptrdiff_t, const char16_t*,
70 const char16_t&>, public ystdex::bidirectional_iteratable<
71 TextFileBuffer::iterator, const char16_t&>
72 {
73 friend class TextFileBuffer;
74
75 private:
77 TextFileBuffer* p_buffer;
78 //文本读取位置。
79 size_t block;
80 size_t index;
81
82 public:
86 iterator(TextFileBuffer* = {}, size_t = 0, size_t = 0) ynothrow;
87
91 iterator&
92 operator++() ynothrow;
93
97 iterator&
98 operator--() ynothrow;
99
101 reference
102 operator*() const;
103
107 YF_API friend bool
108 operator==(const iterator&, const iterator&) ynothrow;
109
111 DefGetter(const ynothrow, observer_ptr<TextFileBuffer>, BufferPtr,
112 make_observer(p_buffer))
113 DefGetter(const ynothrow, size_t, BlockN, block)
114 DefGetter(const ynothrow, size_t, IndexN, index)
115 };
116 using const_iterator = iterator;
118
123 static yconstexpr const size_t BlockSize = 2048U;
124
125 protected:
130 std::istream& File;
131
132 private:
134
135 size_t fsize;
136 Encoding encoding;
137 size_t bl;
139
141 size_t n_text_size;
144 size_t n_block;
146 MapType buffer{};
148
149 private:
155 size_t fixed_width;
160 size_t max_width;
161
162 public:
171 explicit
172 TextFileBuffer(std::istream&, 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
206
207
211 iterator
212 begin() ynothrow;
213
218 iterator
219 end() ynothrow;
221 };
222
223
231 YF_API string
232 CopySliceFrom(TextFileBuffer&, size_t, size_t);
233
234 } // namespace Text;
235
236 } // namespace YSLib;
237
238 #endif
239
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:653
ystdex::details::ebases
Definition: operators.hpp:100
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:45
YSLib::Text::TextFileBuffer::iterator::p_buffer
TextFileBuffer * p_buffer
Definition: TextManager.h:77
CHRLib::CharSet::Null
空字符集。
Definition: Encoding.h:63
YSLib::Text::TextFileBuffer::iterator
目标编码迭代器类型。
Definition: TextManager.h:68
CHRLib::CharSet::Encoding
Encoding
字符流编码标识。
Definition: Encoding.h:58
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:240
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:168
YModules.h
YSLib::Text::TextFileBuffer::fixed_width
size_t fixed_width
固定编码每字符的字节数。
Definition: TextManager.h:155
std
Definition: memory.hpp:1100
YSLib::Text::TextFileBuffer::max_width
size_t max_width
最大编码每字符的字节数。
Definition: TextManager.h:160
YSLib::Text::TextFileBuffer::iterator::index
size_t index
Definition: TextManager.h:80
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:293
YSLib::Drawing::buffer
The boundary is out of the buffer
Definition: YDraw.h:118
YSLib::Text::TextFileBuffer::MapType
map< size_t, BlockType > MapType
缓冲映射类型。
Definition: TextManager.h:62
iterator_op.hpp
迭代器操作。
Text
YSLib::Text::TextFileBuffer
文本文件块缓冲区。
Definition: TextManager.h:46
YSLib::Text::CopySliceFrom
YF_API string CopySliceFrom(TextFileBuffer &, size_t, size_t)
从文本文件缓冲区复制指定字节位置起始的字符串。
Definition: TextManager.cpp:324
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: memory.hpp:1042
YF_API
#define YF_API
Definition: Platform.h:56
ystdex::cpp2011::begin
_type * begin(_type(&&array)[_vN])
Definition: range.hpp:46
YSLib::Text::TextFileBuffer::BlockType
pair< vector< char16_t >, size_t > BlockType
缓冲区块类型。
Definition: TextManager.h:55
ystdex::cpp2011::end
_type * end(_type(&&array)[_vN])
Definition: range.hpp:54
YSLib::Text::TextFileBuffer::iterator::block
size_t block
Definition: TextManager.h:79