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
343 public ufm::lang::Iterable<const char> {
344 /* *************************************************************************************
345 * Variable
346 */
347 protected:
351 int vHead;
353 int vTail;
354
355 /* *************************************************************************************
356 * Abstract Method
357 */
358
359 /* *************************************************************************************
360 * Construct Method
361 */
362 public:
368
373 inline LineReader(LineReader&& other) noexcept
374 : vBuffer(other.vBuffer), vHead(other.vHead), vTail(other.vTail) {
375 return;
376 }
377
381 virtual ~LineReader(void) override;
382
383 /* *************************************************************************************
384 * Operator Method
385 */
386
387 /* *************************************************************************************
388 * Override - ufm::lang::Iterable<const char*>
389 */
390 public:
399 virtual void forEach(ufm::func::Consumer<const char&>& action) override;
400
407 virtual const char* elementAt(int index) const override;
408
417 virtual int nextIndex(int index) const override;
418
427
436 virtual ufm::util::Iterator<const char> end(void) override;
437
438 /* *************************************************************************************
439 * Public Method
440 */
441 public:
451 int nextTokenLength(int limit = 0);
452
462 inline bool hasNextToken(int limit = 0) {
463 return (this->nextTokenLength(limit) > 0);
464 }
465
473 bool hasNext(void) const;
474
480 bool hasNextChar(char ch);
481
486 bool hasNextBoolean(void);
487
493 bool hasNextInteger(int limit = 0);
494
500 bool hasNextFloat(int limit = 0);
501
507 int hasNextLine(int limit = 0);
508
514 bool nextBoolean(bool& result);
515
522 int nextLine(ufm::lang::Appendable& appendable, int limit = 0);
523
530 inline int nextLine(void* pointer, int length) {
531 ufm::io::SimpleWriter v = ufm::io::SimpleWriter(pointer, length);
532 return this->nextLine(v);
533 }
534
541 bool nextInteger(int& result, int limit = 0);
542
549 bool nextFloat(float& result, int limit = 0);
550
556 bool nextChar(char& result);
557
564 int next(ufm::lang::Appendable& appendable, int limit = 0);
565
572 int skip(char pattern, int limit = 0);
573
579 inline int skipAll(void) {
580 return this->skip(0x00, 0);
581 }
582
588 int skipNextToken(int limit = 0);
589
595 int skipNextLine(int limit = 0);
596
601 inline int avariable(void) const {
602 return (this->vHead - this->vTail);
603 }
604
605 /* *************************************************************************************
606 * Protected Method
607 */
608
609 /* *************************************************************************************
610 * Private Method
611 */
612
613 /* *************************************************************************************
614 * Static Variable
615 */
616
617 /* *************************************************************************************
618 * Static Method
619 */
620};
621
622/* ***************************************************************************************
623 * End of file
624 */
625
626#endif /* MFRAME_AF2E5877_9D22_411F_8FFD_E0FC2E55CC9F */
提供資料寫入功能的簡易實現類
Definition SimpleWriter.h:43
動態記憶體管理類別
Definition Memory.h:38
物件基底類別
Definition Object.h:63
迭代器類別,提供遍歷集合元素的標準介面。
Definition Iterator.h:257
行資料讀取器,提供從緩衝區解析多種資料類型的功能。
Definition LineReader.h:343
bool hasNextToken(int limit=0)
判斷緩衝區是否有下一個 token。
Definition LineReader.h:462
int skipNextLine(int limit=0)
跳過當前行直到下一行(遇到換行符)。
LineReader(LineReader &&other) noexcept
移動建構子
Definition LineReader.h:373
int avariable(void) const
取得緩衝區可讀取的位元組數。
Definition LineReader.h:601
bool hasNextBoolean(void)
判斷緩衝區是否有可解析的布林值(true/false)。
int vHead
當前讀取位置索引
Definition LineReader.h:351
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:530
bool nextChar(char &result)
讀取下一個字元,並移除。
virtual ufm::util::Iterator< const char > begin(void) override
取得目前插入位置。
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:579
virtual ~LineReader(void) override
解構子,釋放資源
bool hasNextFloat(int limit=0)
判斷緩衝區是否有可解析的浮點數。
ufm::lang::Memory vBuffer
用於存儲資料的記憶體緩衝區
Definition LineReader.h:349
int hasNextLine(int limit=0)
判斷緩衝區是否有完整的一行(遇到換行符)。
int vTail
緩衝區尾部索引
Definition LineReader.h:353
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