🛰️航天仿真算法库 SpaceAST 0.3.1
载入中...
搜索中...
未找到
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
118
119
120#else
121using std::fopen;
122using std::freopen;
123using std::vprintf;
124using std::vfprintf;
125using std::printf;
126using std::fprintf;
127using std::wprintf;
128using std::fwprintf;
129
130#endif
131}
132
133
134#ifdef AST_ENABLE_OVERRIDE_STDLIB // 是否覆盖标准库的函数
135using namespace posix;
136#endif
137
138
150AST_UTIL_CAPI errc_t aUriFetch(StringView uri, std::string& filepath);
151
152
163AST_UTIL_CAPI std::FILE* uriopen(const char* uri, const char* mode);
164
165
166A_ALWAYS_INLINE
167std::FILE* ast_fopen(const char* filepath, const char* mode)
168{
169 return posix::fopen(filepath, mode);
170}
171
172
173A_ALWAYS_INLINE
174FILE* ast_freopen(const char* filepath, const char* mode, FILE* stream)
175{
176 return posix::freopen(filepath, mode, stream);
177}
178
179
180
181A_ALWAYS_INLINE
182int ast_vprintf(const char* format, va_list args)
183{
184 return posix::vprintf(format, args);
185}
186
187
188AST_UTIL_CAPI int ast_printf(const char* format, ...);
189
190
195AST_UTIL_CAPI int aPrintLink(StringView text, StringView link);
196
197
201AST_UTIL_CAPI int aCurrentLineNumber(std::FILE* file);
202
203
208AST_UTIL_CAPI errc_t aGetFilePath(std::FILE* file, std::string& filepath);
209
210
214A_ALWAYS_INLINE std::string aGetFilePath(std::FILE* file)
215{
216 std::string filepath;
217 errc_t rc = aGetFilePath(file, filepath);
218 A_UNUSED(rc);
219 return filepath;
220}
221
222
223
228AST_NAMESPACE_END
229
int aCurrentLineNumber(std::FILE *file)
获取文件当前行号
定义 IO.cpp:484
int aPrintLink(StringView text, StringView link)
打印链接
定义 IO.cpp:474
errc_t aGetFilePath(std::FILE *file, std::string &filepath)
获取文件路径
定义 IO.cpp:521
std::FILE * uriopen(const char *uri, const char *mode)
打开URI(统一资源标识符)对应的文件 例如 https://example.com/file.txt 、file:///path/to/file.txt 等 也支持传入普通文件路径,即与 fopen ...
定义 IO.cpp:427
errc_t aUriFetch(StringView uri, std::string &filepath)
解析URI(统一资源标识符)并返回其对应的本地文件路径
定义 IO.cpp:376