mFrame
載入中...
搜尋中...
無符合項目
LineReader.h
1
7#ifndef MFRAME_AF2E5877_9D22_411F_8FFD_E0FC2E55CC9F
8#define MFRAME_AF2E5877_9D22_411F_8FFD_E0FC2E55CC9F
9
10/* ***************************************************************************************
11 * Include
12 */
13
14//----------------------------------------------------------------------------------------
15#include "./../io/ByteBuffer.h"
16#include "./../io/SimpleWriter.h"
17#include "./../lang/Iterable.h"
18#include "./../lang/NonCopyable.h"
19#include "./../util/Iterator.h"
20
21//----------------------------------------------------------------------------------------
22
23/* ***************************************************************************************
24 * Namespace
25 */
26namespace ufm::util {
27 class LineReader;
28} // namespace ufm::util
29
30/* ***************************************************************************************
31 * Class/Interface/Struct/Enum
32 */
33
58 public ufm::lang::Iterable<const char> {
59 /* *************************************************************************************
60 * Variable
61 */
62 protected:
63 ufm::lang::Memory vBuffer;
64 int vHead;
65 int vTail;
66
67 /* *************************************************************************************
68 * Abstract Method
69 */
70
71 /* *************************************************************************************
72 * Construct Method
73 */
74 public:
79 LineReader(ufm::lang::Memory buffer) noexcept;
80
85 inline LineReader(int bufferSize = 128) noexcept
86 : LineReader(ufm::lang::Memory(bufferSize)) {
87 return;
88 }
89
94 inline LineReader(LineReader&& other) noexcept
95 : vBuffer(other.vBuffer), vHead(other.vHead), vTail(other.vTail) {
96 return;
97 }
98
102 virtual ~LineReader(void) override;
103
104 /* *************************************************************************************
105 * Operator Method
106 */
107
108 /* *************************************************************************************
109 * Override - ufm::lang::Iterable<const char*>
110 */
111 public:
120 virtual void forEach(ufm::func::Consumer<const char&>& action) override;
121
128 virtual const char* elementAt(int index) const override;
129
138 virtual int nextIndex(int index) const override;
139
148
157 virtual ufm::util::Iterator<const char> end(void) override;
158
159 /* *************************************************************************************
160 * Public Method
161 */
162 public:
172 int nextTokenLength(int limit = 0);
173
183 inline bool hasNextToken(int limit = 0) {
184 return (this->nextTokenLength(limit) > 0);
185 }
186
194 bool hasNext(void) const;
195
201 bool hasNextChar(char ch);
202
207 bool hasNextBoolean(void);
208
214 bool hasNextInteger(int limit = 0);
215
221 bool hasNextFloat(int limit = 0);
222
228 int hasNextLine(int limit = 0);
229
235 bool nextBoolean(bool& result);
236
243 int nextLine(ufm::lang::Appendable& appendable, int limit = 0);
244
251 inline int nextLine(void* pointer, int length) {
252 ufm::io::SimpleWriter v = ufm::io::SimpleWriter(pointer, length);
253 return this->nextLine(v);
254 }
255
262 bool nextInteger(int& result, int limit = 0);
263
270 bool nextFloat(float& result, int limit = 0);
271
277 bool nextChar(char& result);
278
285 int next(ufm::lang::Appendable& appendable, int limit = 0);
286
293 int skip(char pattern, int limit = 0);
294
300 inline int skipAll(void) {
301 return this->skip(0x00, 0);
302 }
303
309 int skipNextToken(int limit = 0);
310
316 int skipNextLine(int limit = 0);
317
322 inline int avariable(void) const {
323 return (this->vHead - this->vTail);
324 }
325
326 /* *************************************************************************************
327 * Protected Method
328 */
329
330 /* *************************************************************************************
331 * Private Method
332 */
333
334 /* *************************************************************************************
335 * Static Variable
336 */
337
338 /* *************************************************************************************
339 * Static Method
340 */
341};
342
343/* ***************************************************************************************
344 * End of file
345 */
346
347#endif /* MFRAME_AF2E5877_9D22_411F_8FFD_E0FC2E55CC9F */
提供資料寫入功能的簡易實現類
Definition SimpleWriter.h:43
存儲資料的類別,提供動態記憶體管理功能。
Definition Memory.h:44
物件基底類別
Definition Object.h:63
[Class] 迭代器介面
Definition Iterator.h:42
行資料讀取器,提供從緩衝區解析字串、數值、布林等多種型態的資料。
Definition LineReader.h:58
bool hasNextToken(int limit=0)
判斷緩衝區是否有下一個 token。
Definition LineReader.h:183
int skipNextLine(int limit=0)
跳過當前行直到下一行(遇到換行符)。
LineReader(LineReader &&other) noexcept
移動建構子
Definition LineReader.h:94
int avariable(void) const
取得緩衝區可讀取的位元組數。
Definition LineReader.h:322
bool hasNextBoolean(void)
判斷緩衝區是否有可解析的布林值(true/false)。
int vHead
當前讀取位置索引
Definition LineReader.h:64
bool nextBoolean(bool &result)
讀取下一個布林值(true/false),並移除。
virtual void forEach(ufm::func::Consumer< const char & > &action) override
遍歷集合中所有元素,對每個元素執行指定操作。 若所有元素處理完畢或操作中發生異常則停止。
int nextLine(void *pointer, int length)
讀取下一行字串,寫入指定記憶體區。
Definition LineReader.h:251
bool nextChar(char &result)
讀取下一個字元,並移除。
virtual ufm::util::Iterator< const char > begin(void) override
取得目前插入位置。
LineReader(int bufferSize=128) noexcept
使用指定緩衝區大小構造 LineReader 物件
Definition LineReader.h:85
bool nextFloat(float &result, int limit=0)
讀取下一個浮點數,並移除。
bool hasNextChar(char ch)
判斷緩衝區是否有指定字元。
virtual int nextIndex(int index) const override
返回當前索引的下一個有效索引。
bool hasNext(void) const
判斷緩衝區是否有下一個字元。
int skipAll(void)
跳過指定長度的字元。
Definition LineReader.h:300
virtual ~LineReader(void) override
解構子,釋放資源
bool hasNextFloat(int limit=0)
判斷緩衝區是否有可解析的浮點數。
int hasNextLine(int limit=0)
判斷緩衝區是否有完整的一行(遇到換行符)。
int vTail
緩衝區尾部索引
Definition LineReader.h:65
bool hasNextInteger(int limit=0)
判斷緩衝區是否有可解析的整數。
virtual const char * elementAt(int index) const override
獲取集合中指定索引處的元素。
int nextTokenLength(int limit=0)
取得下一個 token 的長度。
int skipNextToken(int limit=0)
跳過當前字串直到分隔符。
int nextLine(ufm::lang::Appendable &appendable, int limit=0)
讀取下一行字串,並寫入指定 appendable。
virtual ufm::util::Iterator< const char > end(void) override
取得 Scanner 結尾迭代器。
int next(ufm::lang::Appendable &appendable, int limit=0)
讀取下一個字串,並寫入指定 appendable。
bool nextInteger(int &result, int limit=0)
讀取下一個整數,並移除。
int skip(char pattern, int limit=0)
跳過直到遇到指定字元或達到限制。
LineReader(ufm::lang::Memory buffer) noexcept
使用現有緩衝區構造 LineReader 物件
Definition Iterable.h:28
[Interface] 消費者函數式介面模板
Definition Consumer.h:43
資料附加介面 (Appendable)
Definition Appendable.h:43
[Interface] 定義可迭代集合介面
Definition Iterable.h:49
禁止複製的結構
Definition NonCopyable.h:38