🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
BaseParser.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstUtil/StringView.hpp"
25#include <cstdio>
26#include <fstream>
27#include <vector>
28
29AST_NAMESPACE_BEGIN
30
42AST_UTIL_CAPI char* fgetlinetrim(char* buffer, int size, FILE* file);
43
44
45
50AST_UTIL_CAPI bool aIsHashCommentLine(StringView line);
51
52
53
55class AST_UTIL_API BaseParser
56{
57public:
58 BaseParser();
59 BaseParser(StringView filepath);
61
62
63public: // 基础操作
67 void open(StringView filepath);
68
72 bool isOpen() const { return file_ != nullptr; }
73
76 void close();
77
82 void seek(std::streamoff pos, std::ios::seekdir dir);
83
87 std::streamoff tell();
88
92 bool eof() const { return feof(file_) != 0; }
93
100 size_t read(void* buffer, size_t size, size_t pos) const;
101
102public:
106 StringView getLineWithNewline();
107
111 StringView getLine();
112
116 StringView getLineTrim();
117
121 StringView getLineSkipHashComment();
122
123public: // 辅助信息
127 int getLineNumber();
128
132 std::string getFilePath() const;
133
139 void setBorrowedFile(FILE* file);
140
146 void setOwnedFile(FILE* file);
147
149 FILE* getFile() const { return file_; }
150protected:
151 FILE* file_{nullptr};
152 bool fileBorrowed_{false};
153 std::vector<char> lineBuffer_;
154};
155
156
159AST_NAMESPACE_END
解析器基类
定义 BaseParser.hpp:56
bool isOpen() const
是否打开文件
定义 BaseParser.hpp:72
std::vector< char > lineBuffer_
行缓冲区
定义 BaseParser.hpp:153
bool eof() const
是否到达文件末尾
定义 BaseParser.hpp:92
FILE * getFile() const
获取当前解析器使用的文件指针
定义 BaseParser.hpp:149
bool aIsHashCommentLine(StringView line)
判断是否为#注释行
定义 BaseParser.cpp:80
char * fgetlinetrim(char *buffer, int size, FILE *file)
从文件中读取一行文本,跳过行首的空白字符,移除行尾的换行符。
定义 BaseParser.cpp:45