YSTest  PreAlpha_b400_20130424
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
textmgr.h
浏览该文件的文档.
1 /*
2  Copyright by FrankHB 2010 - 2013.
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 "../Core/ystring.h"
32 #include "yftext.h"
33 #include "../Adaptor/ycont.h"
34 
36 
38 
39 /*
40 \brief 文本文件块缓冲区。
41 \since build 145
42 */
44 {
45 public:
52  typedef pair<vector<ucs2_t>, size_t> BlockType;
59  typedef map<size_t, BlockType> MapType;
64  class YF_API Iterator : public std::iterator<
65  std::bidirectional_iterator_tag, ucs2_t,
66  ptrdiff_t, const ucs2_t, const ucs2_t&>
67  {
68  friend class TextFileBuffer;
69 
70  private:
71  TextFileBuffer* pBuffer;
72  //文本读取位置。
73  size_t block;
74  size_t index;
75 
76  public:
80  Iterator(TextFileBuffer* = {}, size_t = 0, size_t = 0) ynothrow;
81 
85  Iterator&
86  operator++() ynothrow;
87 
91  Iterator&
92  operator--() ynothrow;
93 
94  ucs2_t
95  operator*() const ynothrow;
96 
97 
101  YF_API friend bool
102  operator==(const Iterator&, const Iterator&) ynothrow;
103 
104  DefGetter(const ynothrow, TextFileBuffer*, BufferPtr, pBuffer)
105  DefGetter(const ynothrow, size_t, BlockN, block)
106  DefGetter(const ynothrow, size_t, IndexN, index)
107  };
108 
113  static yconstexpr size_t BlockSize = 2048U;
114 
115 protected:
125  size_t nTextSize;
130  size_t nBlock;
135  MapType Map;
136 
137 private:
143  size_t fixed_width;
148  size_t max_width;
149 
150 public:
154  explicit
155  TextFileBuffer(TextFile&);
159  virtual DefEmptyDtor(TextFileBuffer)
160 
165  BlockType&
166  operator[](size_t);
167 
172  DefGetter(const ynothrow, size_t, BlockN, nBlock)
173  DefGetter(const ynothrow, Encoding, Encoding, File.Encoding)
174  DefGetterMem(const ynothrow, size_t, Size, File)
175  DefGetter(const ynothrow, size_t, TextSize, nTextSize)
181  Iterator
182  GetBegin() ynothrow;
188  Iterator
189  GetEnd() ynothrow;
194  Iterator
195  GetIterator(size_t);
200  size_t
201  GetPosition(Iterator);
202 };
203 
204 inline bool
205 operator!=(const TextFileBuffer::Iterator& x, const TextFileBuffer::Iterator y)
206  ynothrow
207 {
208  return !(x == y);
209 }
210 
211 
220 YF_API string
221 CopySliceFrom(TextFileBuffer&, size_t, size_t) ythrow(std::out_of_range);
222 
223 YSL_END_NAMESPACE(Text)
224 
225 YSL_END
226 
227 #endif
228