YSTest: MinGW32.h 源文件

YSTest PreAlpha_b500_20140530 The YSLib Test Project

- 首页
- 相关页面
- 模块
- 命名空间
- 类
- 文件

- 文件列表
- 文件成员

全部 类 命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义 组 页
E/include/YCLib/MinGW32.h
浏览该文件的文档.
1 /*
2 © 2013 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
29 #ifndef YCL_MinGW32_INC_MinGW32_h_
30 #define YCL_MinGW32_INC_MinGW32_h_ 1
31
32 #include "YCLib/ycommon.h"
33 #include <YCLib/NativeAPI.h>
34 #include "YSLib/Core/yexcept.h" // for YSLib::LoggedEvent;
35
36 #if !YCL_MinGW32
37 # error "This file is only for MinGW32."
38 #endif
39
45 #undef GetObject
46
47 namespace platform_ex
48 {
49
55 class YF_API Exception : public YSLib::LoggedEvent
56 {
57 public:
59 Exception(const std::string& = "unknown host exception",
60 LevelType = {}) ynothrow;
61 };
62
67 inline namespace Windows
68 {
69
75 class YF_API Win32Exception : public Exception
76 {
77 public:
79
80 using ErrorCode = ::DWORD;
81
82 private:
83 ErrorCode err;
84
85 public:
90 Win32Exception(ErrorCode, const std::string& = "Win32 exception",
91 LevelType = {}) ynothrow;
92
93 DefGetter(const ynothrow, ErrorCode, ErrorCode, err)
95 DefGetter(const ynothrow, std::string, Message, FormatMessage(err))
96
97 explicit DefCvt(const ynothrow, ErrorCode, err)
98
103 static std::string
104 FormatMessage(ErrorCode) ynothrow;
106 };
107
112 # define YF_Raise_Win32Exception(...) \
113 { \
114 const auto err(::GetLastError()); \
115 \
116 throw platform_ex::Windows::Win32Exception(err, __VA_ARGS__); \
117 }
118
119
125 YF_API bool
126 CheckWine();
127
128
129 // TODO: Add more Windows specific APIs.
130
136 YF_API std::string
137 UTF8ToMBCS(const char*, std::size_t, int = CP_ACP);
138 inline std::string
139 UTF8ToMBCS(const char* str, int cp = CP_ACP)
140 {
141 return UTF8ToMBCS(str, ystdex::ntctslen(str), cp);
142 }
143 inline std::string
144 UTF8ToMBCS(const std::string& str, int cp = CP_ACP)
145 {
146 return UTF8ToMBCS(str.c_str(), str.length(), cp);
147 }
148
149 YF_API std::string
150 WCSToMBCS(const wchar_t*, std::size_t, int = CP_ACP);
151 inline std::string
152 WCSToMBCS(const wchar_t* str, int cp = CP_ACP)
153 {
154 return WCSToMBCS(str, ystdex::ntctslen(str), cp);
155 }
156 inline std::string
157 WCSToMBCS(const std::wstring& str, int cp = CP_ACP)
158 {
159 return WCSToMBCS(str.c_str(), str.length(), cp);
160 }
161
162 YF_API std::wstring
163 MBCSToWCS(const char*, std::size_t, int = CP_ACP);
164 inline std::wstring
165 MBCSToWCS(const char* str, int cp = CP_ACP)
166 {
167 return MBCSToWCS(str, ystdex::ntctslen(str), cp);
168 }
169 inline std::wstring
170 MBCSToWCS(const std::string& str, int cp = CP_ACP)
171 {
172 return MBCSToWCS(str.c_str(), str.length(), cp);
173 }
175
176
182 class YF_API RegisterKey
183 {
184 private:
185 ::HKEY h_key;
186
187 public:
188 RegisterKey(::HKEY h_parent, const wchar_t* key)
189 {
190 if(!::RegOpenKeyEx(h_parent, key, 0, KEY_READ, &h_key))
191 YF_Raise_Win32Exception("RegOpenKeyEx");
192 }
193 ~RegisterKey()
194 {
195 ::RegCloseKey(h_key);
196 }
197
198 DefGetter(const ynothrow, ::HKEY, Key, h_key)
199 };
200
201 } // namespace Windows;
202
203 } // namespace platform_ex;
204
205 #endif
206
platform_ex::Windows::MBCSToWCS
std::wstring MBCSToWCS(const char *str, std::size_t len, int cp)
Definition: MinGW32.cpp:124
ystdex::ntctslen
size_t ntctslen(const _tChar *s)
计算简单 NTCTS 长度。
Definition: cstring.h:109
platform_ex::Windows::RegisterKey::~RegisterKey
~RegisterKey()
Definition: E/include/YCLib/MinGW32.h:193
ycommon.h
平台相关的公共组件无关函数与宏定义集合。
platform_ex::Windows::RegisterKey::RegisterKey
RegisterKey(::HKEY h_parent, const wchar_t *key)
Definition: E/include/YCLib/MinGW32.h:188
platform_ex::Windows::err
err(ec)
Definition: MinGW32.cpp:51
YF_API
#define YF_API
Definition: Platform.h:64
platform_ex::Windows::DefGetter
DefGetter(const ynothrow,::HKEY, Key, h_key)}
platform_ex::Windows::RegisterKey::h_key
::HKEY h_key
Definition: E/include/YCLib/MinGW32.h:185
platform_ex::Windows::RegisterKey
注册表键。
Definition: E/include/YCLib/MinGW32.h:182
YSLib::Drawing::size_t
size_t
Definition: ygdi.h:352
platform_ex::Windows::Win32Exception::ErrorCode
::DWORD ErrorCode
Definition: include/YCLib/MinGW32.h:65
YSLib::Exception
std::exception Exception
YSLib 异常基类。
Definition: yexcept.h:44
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
YSLib::string
GSStringTemplate< char >::basic_string string
Definition: ycont.h:164
platform_ex::Windows::Win32Exception
Win32 错误引起的宿主异常。
Definition: include/YCLib/MinGW32.h:60
platform::Descriptions::RecordLevel
RecordLevel
记录等级。
Definition: ycommon.h:69
platform_ex::Windows::WCSToMBCS
std::string WCSToMBCS(const wchar_t *str, std::size_t len, int cp)
Definition: MinGW32.cpp:113
platform_ex::Windows::CheckWine
YF_API bool CheckWine()
判断是否在 Wine 环境下运行。
Definition: MinGW32.cpp:80
YSLib::LoggedEvent
记录日志的异常事件类。
Definition: yexcept.h:58
platform_ex::Exception
宿主异常。
Definition: E/include/YCLib/MinGW32.h:55
DefCvt
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:164
YF_Raise_Win32Exception
#define YF_Raise_Win32Exception(...)
按 ::GetLastError 的结果和指定参数抛出 Windows::Win32Exception 对象。
Definition: E/include/YCLib/MinGW32.h:112
platform_ex::Windows::UTF8ToMBCS
YF_API std::string UTF8ToMBCS(const char *, std::size_t, int=CP_ACP)
yexcept.h
异常处理模块。
YSLib::UI::Styles::Key
pair< std::type_index, StyleItem > Key
标识查找样式的键。
Definition: ystyle.h:253
NativeAPI.h
通用平台应用程序接口描述。