🛰️航天仿真算法库 SpaceAST 0.4.0
载入中...
搜索中...
未找到
IO.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstUtil/StringView.hpp"
25#include <cwchar> // for wchar_t, wprintf, ...
26#include <cstdio> // for std::fopen, std::printf, ...
27#include <cstdarg> // for va_list, va_start, va_end
28#include <string> // for std::string
29
30// 只有当启用命名空间且定义了AST_ENABLE_OVERRIDE_STDLIB时,才覆盖标准库的函数
31// 避免在极端情况下的名称冲突,例如using namespace std; using namespace ast; 虽然这不是推荐的做法
32
33#if defined AST_BUILD_LIB && defined AST_ENABLE_NAMESPACE
34# ifndef AST_ENABLE_OVERRIDE_STDLIB
35# define AST_ENABLE_OVERRIDE_STDLIB
36# endif // !AST_ENABLE_OVERRIDE_STDLIB
37#endif
38
39
40
41AST_NAMESPACE_BEGIN
42
49namespace posix{
50
51using std::FILE;
52
53#ifdef _WIN32
54
59AST_UTIL_API
60std::FILE* fopen(const char* filepath, const char* mode);
61
62
68AST_UTIL_API
69FILE* freopen(const char* filepath, const char* mode, FILE* stream);
70
71
76AST_UTIL_API
77int vprintf(const char* format, va_list args);
78
84AST_UTIL_API
85int vfprintf(FILE* stream, const char* format, va_list args);
86
91AST_UTIL_API
92int printf(const char* format, ...);
93
99AST_UTIL_API
100int fprintf(FILE* stream, const char* format, ...);
101
102
107AST_UTIL_API
108int wprintf(const wchar_t* format, ...);
109
115AST_UTIL_API
116int fwprintf(FILE* stream, const wchar_t* format, ...);
117
122AST_UTIL_API
123wint_t fgetwc(FILE *stream);
124
125
134AST_UTIL_API
135char* fgets(char* buf, int size, FILE* stream);
136
137#else
138using std::fopen;
139using std::freopen;
140using std::vprintf;
141using std::vfprintf;
142using std::printf;
143using std::fprintf;
144using std::wprintf;
145using std::fwprintf;
146using std::fgetwc;
147using std::fgets;
148
149#endif
150}
151
152
153#ifdef AST_ENABLE_OVERRIDE_STDLIB // 是否覆盖标准库的函数
154using namespace posix;
155#endif
156
157
169AST_UTIL_CAPI errc_t aUriFetch(StringView uri, std::string& filepath);
170
171
182AST_UTIL_CAPI std::FILE* uriopen(const char* uri, const char* mode);
183
184
185A_ALWAYS_INLINE
186std::FILE* ast_fopen(const char* filepath, const char* mode)
187{
188 return posix::fopen(filepath, mode);
189}
190
191
192A_ALWAYS_INLINE
193FILE* ast_freopen(const char* filepath, const char* mode, FILE* stream)
194{
195 return posix::freopen(filepath, mode, stream);
196}
197
198
199
200A_ALWAYS_INLINE
201int ast_vprintf(const char* format, va_list args)
202{
203 return posix::vprintf(format, args);
204}
205
206
207AST_UTIL_CAPI int ast_printf(const char* format, ...);
208
209
214AST_UTIL_CAPI int aPrintLink(StringView text, StringView link);
215
216
220AST_UTIL_CAPI int aCurrentLineNumber(std::FILE* file);
221
222
227AST_UTIL_CAPI errc_t aGetFilePath(std::FILE* file, std::string& filepath);
228
229
233A_ALWAYS_INLINE std::string aGetFilePath(std::FILE* file)
234{
235 std::string filepath;
236 errc_t rc = aGetFilePath(file, filepath);
237 A_UNUSED(rc);
238 return filepath;
239}
240
241
242
247AST_NAMESPACE_END
248
int aCurrentLineNumber(std::FILE *file)
获取文件当前行号
定义 IO.cpp:687
int aPrintLink(StringView text, StringView link)
打印链接
定义 IO.cpp:677
errc_t aGetFilePath(std::FILE *file, std::string &filepath)
获取文件路径
定义 IO.cpp:724
std::FILE * uriopen(const char *uri, const char *mode)
打开URI(统一资源标识符)对应的文件 例如 https://example.com/file.txt 、file:///path/to/file.txt 等 也支持传入普通文件路径,即与 fopen ...
定义 IO.cpp:630
errc_t aUriFetch(StringView uri, std::string &filepath)
解析URI(统一资源标识符)并返回其对应的本地文件路径
定义 IO.cpp:579