YSTest: TextManager.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

TextManager.h
浏览该文件的文档.
1 /*
2 © 2010-2018, 2020 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
70 : public ystdex::bidirectional_iteratable<iterator, const char16_t&>
71 {
72 friend class TextFileBuffer;
73
74 public:
75 using iterator_category = std::bidirectional_iterator_tag;
76 using value_type = char16_t;
77 using difference_type = ptrdiff_t;
78 using pointer = const char16_t*;
79 using reference = const char16_t&;
80
81 private:
83 TextFileBuffer* p_buffer;
84 //文本读取位置。
85 size_t block;
86 size_t index;
87
88 public:
92 iterator(TextFileBuffer* = {}, size_t = 0, size_t = 0) ynothrow;
93
97 iterator&
98 operator++() ynothrow;
99
103 iterator&
104 operator--() ynothrow;
105
107 reference
108 operator*() const;
109
113 YF_API YB_PURE friend bool
114 operator==(const iterator&, const iterator&) ynothrow;
115
117 DefGetter(const ynothrow, observer_ptr<TextFileBuffer>, BufferPtr,
118 make_observer(p_buffer))
119 DefGetter(const ynothrow, size_t, BlockN, block)
120 DefGetter(const ynothrow, size_t, IndexN, index)
121 };
122 using const_iterator = iterator;
124
129 static yconstexpr const size_t BlockSize = 2048U;
130
131 protected:
136 std::streambuf& File;
137
138 private:
140
141 size_t fsize;
142 Encoding encoding;
143 size_t bl;
145
147 size_t n_text_size;
150 size_t n_block;
152 MapType buffer{};
154
155 private:
161 size_t fixed_width;
166 size_t max_width;
167
168 public:
176 explicit
177 TextFileBuffer(std::streambuf&, Encoding = CharSet::Null);
178
185 BlockType&
186 operator[](size_t);
187
192 DefGetter(const ynothrow, size_t, BlockN, n_block)
193 DefGetter(const ynothrow, Encoding, Encoding, encoding)
194 DefGetter(const ynothrow, size_t, Size, fsize)
195 DefGetter(const ynothrow, size_t, TextSize, n_text_size)
196
201 iterator
202 GetIterator(size_t);
207 size_t
208 GetPosition(iterator);
209
215 void
216 Seek(std::streamoff);
217
219
220
224 iterator
225 begin() ynothrow;
226
231 iterator
232 end() ynothrow;
234 };
235
236
244 YF_API u16string
245 CopySliceFrom(TextFileBuffer&, size_t, size_t);
246
247 } // namespace Text;
248
249 } // namespace YSLib;
250
251 #endif
252
YSLib::Drawing::buffer
The boundary is out of the buffer
Definition: YDraw.h:118
YSLib::Text::TextFileBuffer::iterator::value_type
char16_t value_type
Definition: TextManager.h:76
YSLib::Drawing::Size
屏幕区域大小。
Definition: YGDIBase.h:536
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
ystdex::cpp2017::basic_string
Definition: string.hpp:77
YSLib::Text::TextFileBuffer::iterator::block
size_t block
Definition: TextManager.h:85
YSLib::Text::TextFileBuffer::iterator::reference
const char16_t & reference
Definition: TextManager.h:79
CHRLib::CharSet::Null
@ Null
空字符集。
Definition: Encoding.h:63
CHRLib::CharSet::Encoding
Encoding
字符流编码标识。
Definition: Encoding.h:59
YF_API
#define YF_API
Definition: Platform.h:56
ystdex::map
映射容器。
Definition: map.hpp:79
YSLib::Text::TextFileBuffer::iterator
目标编码迭代器类型。
Definition: TextManager.h:71
ystdex::details::ebases
Definition: operators.hpp:108
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:405
ystdex::cpp2017::end
auto end(_tRange &c) -> decltype(c.end())
Definition: range.hpp:345
std
Definition: optional.h:982
YSLib::Text::TextFileBuffer::BlockType
pair< vector< char16_t >, size_t > BlockType
缓冲区块类型。
Definition: TextManager.h:56
YSLib::Text::TextFileBuffer::iterator::pointer
const char16_t * pointer
Definition: TextManager.h:78
YSLib::Text::TextFileBuffer::iterator::index
size_t index
Definition: TextManager.h:86
YSLib::Text::TextFileBuffer::iterator::difference_type
ptrdiff_t difference_type
Definition: TextManager.h:77
YSLib::Text::TextFileBuffer
文本文件块缓冲区。
Definition: TextManager.h:48
YSLib::Text::TextFileBuffer::DefGetter
DefGetter(const ynothrow, size_t, BlockN, n_block) DefGetter(const ynothrow
取缓冲区块数。
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
iterator_op.hpp
迭代器操作。
YSLib::Text::TextFileBuffer::max_width
size_t max_width
最大编码每字符的字节数。
Definition: TextManager.h:166
YModules.h
YSLib 用户界面模块配置文件。
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:169
YSLib::Text::TextFileBuffer::iterator::p_buffer
TextFileBuffer * p_buffer
Definition: TextManager.h:83
CHRLib::char16_t
YB_ATTR_nodiscard YB_PURE char16_t((*c_ptr<< CHAR_BIT)|c_ptr[1])) YB_ATTR_nodiscard YB_PURE inline PDefH(char16_t
取 c_ptr 指向的小端序双字节字符。
YSLib::Text::TextFileBuffer::fixed_width
size_t fixed_width
固定编码每字符的字节数。
Definition: TextManager.h:161
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::Text::CopySliceFrom
YF_API u16string CopySliceFrom(TextFileBuffer &, size_t, size_t)
从文本文件缓冲区复制指定字节位置起始的字符串。
Definition: TextManager.cpp:347
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
YSLib::Text::TextFileBuffer::iterator::iterator_category
std::bidirectional_iterator_tag iterator_category
Definition: TextManager.h:75
ystdex::cpp2017::begin
auto begin(_tRange &c) -> decltype(c.begin())
Definition: range.hpp:323