🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
IO.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include <cwchar> // for wchar_t, wprintf, ...
25#include <cstdio> // for std::fopen, std::printf, ...
26#include <cstdarg> // for va_list, va_start, va_end
27#include <string> // for std::string
28
29// 只有当启用命名空间且定义了AST_ENABLE_OVERRIDE_STDLIB时,才覆盖标准库的函数
30// 避免在极端情况下的名称冲突,例如using namespace std; using namespace ast; 虽然这不是推荐的做法
31
32#if defined AST_BUILD_LIB && defined AST_ENABLE_NAMESPACE
33# ifndef AST_ENABLE_OVERRIDE_STDLIB
34# define AST_ENABLE_OVERRIDE_STDLIB
35# endif // !AST_ENABLE_OVERRIDE_STDLIB
36#endif
37
38
39
40AST_NAMESPACE_BEGIN
41
48namespace posix{
49
50using std::FILE;
51
52#ifdef _WIN32
53
58AST_UTIL_API
59std::FILE* fopen(const char* filepath, const char* mode);
60
61
67AST_UTIL_API
68FILE* freopen(const char* filepath, const char* mode, FILE* stream);
69
70
75AST_UTIL_API
76int vprintf(const char* format, va_list args);
77
82AST_UTIL_API
83int printf(const char* format, ...);
84
90AST_UTIL_API
91int fprintf(FILE* stream, const char* format, ...);
92
93
98AST_UTIL_API
99int wprintf(const wchar_t* format, ...);
100
106AST_UTIL_API
107int fwprintf(FILE* stream, const wchar_t* format, ...);
108
109
110
111#else
112using std::fopen;
113using std::freopen;
114using std::vprintf;
115using std::printf;
116using std::fprintf;
117using std::wprintf;
118using std::fwprintf;
119
120#endif
121}
122
123
124#ifdef AST_ENABLE_OVERRIDE_STDLIB // 是否覆盖标准库的函数
125using namespace posix;
126#endif
127
128A_ALWAYS_INLINE
129std::FILE* ast_fopen(const char* filepath, const char* mode)
130{
131 return posix::fopen(filepath, mode);
132}
133
134
135A_ALWAYS_INLINE
136FILE* ast_freopen(const char* filepath, const char* mode, FILE* stream)
137{
138 return posix::freopen(filepath, mode, stream);
139}
140
141
142
143A_ALWAYS_INLINE
144int ast_vprintf(const char* format, va_list args)
145{
146 return posix::vprintf(format, args);
147}
148
149
150AST_UTIL_CAPI int ast_printf(const char* format, ...);
151
152
153
157AST_UTIL_CAPI int aCurrentLineNumber(std::FILE* file);
158
159
164AST_UTIL_CAPI errc_t aGetFilePath(std::FILE* file, std::string& filepath);
165
166
170A_ALWAYS_INLINE std::string aGetFilePath(std::FILE* file)
171{
172 std::string filepath;
173 errc_t rc = aGetFilePath(file, filepath);
174 A_UNUSED(rc);
175 return filepath;
176}
177
178
179
184AST_NAMESPACE_END
185
int aCurrentLineNumber(std::FILE *file)
获取文件当前行号
定义 IO.cpp:182
errc_t aGetFilePath(std::FILE *file, std::string &filepath)
获取文件路径
定义 IO.cpp:219