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 
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 
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 
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 
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  }
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 
std::wstring MBCSToWCS(const char *str, std::size_t len, int cp)
Definition: MinGW32.cpp:124
size_t ntctslen(const _tChar *s)
计算简单 NTCTS 长度。
Definition: cstring.h:109
平台相关的公共组件无关函数与宏定义集合。
RegisterKey(::HKEY h_parent, const wchar_t *key)
#define YF_API
Definition: Platform.h:64
DefGetter(const ynothrow,::HKEY, Key, h_key)}
std::exception Exception
YSLib 异常基类。
Definition: yexcept.h:44
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
GSStringTemplate< char >::basic_string string
Definition: ycont.h:164
Win32 错误引起的宿主异常。
RecordLevel
记录等级。
Definition: ycommon.h:69
std::string WCSToMBCS(const wchar_t *str, std::size_t len, int cp)
Definition: MinGW32.cpp:113
YF_API bool CheckWine()
判断是否在 Wine 环境下运行。
Definition: MinGW32.cpp:80
记录日志的异常事件类。
Definition: yexcept.h:58
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:164
#define YF_Raise_Win32Exception(...)
按 ::GetLastError 的结果和指定参数抛出 Windows::Win32Exception 对象。
YF_API std::string UTF8ToMBCS(const char *, std::size_t, int=CP_ACP)
异常处理模块。
pair< std::type_index, StyleItem > Key
标识查找样式的键。
Definition: ystyle.h:253
通用平台应用程序接口描述。