YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
textmgr.h
浏览该文件的文档.
1 /*
2  © 2010-2014 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_textmgr_h_
29 #define YSL_INC_Service_textmgr_h_ 1
30 
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YString
33 #include YFM_YSLib_Service_TextFile
34 #include YFM_YSLib_Adaptor_YContainer
35 
36 namespace YSLib
37 {
38 
39 namespace Text
40 {
41 
42 /*
43 \brief 文本文件块缓冲区。
44 \since build 145
45 */
47 {
48 public:
55  using BlockType = pair<vector<ucs2_t>, size_t>;
62  using MapType = map<size_t, BlockType>;
68  class YF_API iterator : public std::iterator<
69  std::bidirectional_iterator_tag, ucs2_t, ptrdiff_t, const ucs2_t*,
70  const ucs2_t&>
71  {
72  friend class TextFileBuffer;
73 
74  private:
77  //文本读取位置。
78  size_t block;
79  size_t index;
80 
81  public:
85  iterator(TextFileBuffer* = {}, size_t = 0, size_t = 0) ynothrow;
86 
90  iterator&
91  operator++() ynothrow;
92 
96  iterator&
97  operator--() ynothrow;
98 
100  reference
101  operator*() const;
102 
106  YF_API friend bool
107  operator==(const iterator&, const iterator&) ynothrow;
108 
109  DefGetter(const ynothrow, TextFileBuffer*, BufferPtr, p_buffer)
110  DefGetter(const ynothrow, size_t, BlockN, block)
111  DefGetter(const ynothrow, size_t, IndexN, index)
112  };
113  using const_iterator = iterator;
115 
120  static yconstexpr size_t BlockSize = 2048U;
121 
122 protected:
132  size_t nTextSize;
137  size_t nBlock;
142  MapType Map;
143 
144 private:
150  size_t fixed_width;
155  size_t max_width;
156 
157 public:
161  explicit
162  TextFileBuffer(TextFile&);
166  virtual DefDeDtor(TextFileBuffer)
167 
172  BlockType&
173  operator[](size_t);
174 
179  DefGetter(const ynothrow, size_t, BlockN, nBlock)
180  DefGetter(const ynothrow, Encoding, Encoding, File.Encoding)
181  DefGetterMem(const ynothrow, size_t, Size, File)
182  DefGetter(const ynothrow, size_t, TextSize, nTextSize)
183 
188  iterator
189  GetIterator(size_t);
194  size_t
195  GetPosition(iterator);
196 
198 
199 
203  iterator
204  begin() ynothrow;
205 
210  iterator
211  end() ynothrow;
213 };
214 
215 /*
216 \relates TextFileBuffer::iterator
217 \since build 460
218 */
219 inline bool
220 operator!=(const TextFileBuffer::iterator& x, const TextFileBuffer::iterator y)
221  ynothrow
222 {
223  return !(x == y);
224 }
225 
226 
235 YF_API string
236 CopySliceFrom(TextFileBuffer&, size_t, size_t) ythrow(std::out_of_range);
237 
238 } // namespace Text;
239 
240 } // namespace YSLib;
241 
242 #endif
243 
#define DefDeDtor(_t)
定义默认析构函数。
Definition: YBaseMacro.h:146
目标编码迭代器类型。
Definition: textmgr.h:68
文本文件类。
Definition: TextFile.h:56
#define YF_API
Definition: Platform.h:64
文件基类。
Definition: File.h:43
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:180
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
#define ythrow(...)
YSLib 动态异常规范:根据是否使用异常规范宏指定或忽略动态异常规范。
Definition: ydef.h:476
map< size_t, BlockType > MapType
缓冲映射类型。
Definition: textmgr.h:62
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:462
#define DefGetterMem(_q, _t, _n, _m)
Definition: YBaseMacro.h:185
屏幕区域大小。
Definition: ygdibase.h:249
string CopySliceFrom(TextFileBuffer &buf, size_t pos, size_t len) ythrow(std
Definition: textmgr.cpp:258
pair< vector< ucs2_t >, size_t > BlockType
缓冲区块类型。
Definition: textmgr.h:55