🛰️航天仿真算法库 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 explicit 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
107 size_t read(void* buffer, size_t size) const;
108
109public:
113 StringView getLineWithNewline();
114
118 StringView getLine();
119
123 StringView getLineTrim();
124
128 StringView getLineSkipHashComment();
129
130public: // 辅助信息
134 int getLineNumber();
135
139 std::string getFilePath() const;
140
146 void setBorrowedFile(FILE* file);
147
153 void setOwnedFile(FILE* file);
154
156 FILE* getFile() const { return file_; }
157
158protected:
159 std::vector<char>& getLineBuffer() { return lineBuffer_; }
160private:
161 FILE* file_{nullptr};
162 bool fileBorrowed_{false};
163 std::vector<char> lineBuffer_;
164};
165
166
169AST_NAMESPACE_END
解析器基类
定义 BaseParser.hpp:56
bool isOpen() const
是否打开文件
定义 BaseParser.hpp:72
bool eof() const
是否到达文件末尾
定义 BaseParser.hpp:92
FILE * getFile() const
获取当前解析器使用的文件指针
定义 BaseParser.hpp:156
bool aIsHashCommentLine(StringView line)
判断是否为#注释行
定义 BaseParser.cpp:80
char * fgetlinetrim(char *buffer, int size, FILE *file)
从文件中读取一行文本,跳过行首的空白字符,移除行尾的换行符。
定义 BaseParser.cpp:45