YSTest  PreAlpha_b500_20140530
The YSLib Test Project
 全部  命名空间 文件 函数 变量 类型定义 枚举 枚举值 友元 宏定义  
include/YCLib/MinGW32.h
浏览该文件的文档.
1 /*
2  © 2013-2014 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/YModules.h"
33 #include YFM_YCLib_Host
34 #if !YCL_MinGW32
35 # error "This file is only for MinGW32."
36 #endif
37 
43 #undef GetObject
44 
45 namespace platform_ex
46 {
47 
52 inline namespace Windows
53 {
54 
61 {
62 public:
64 
65  using ErrorCode = ::DWORD;
66 
67 private:
69 
70 public:
75  Win32Exception(ErrorCode, const std::string& = "Win32 exception",
76  LevelType = {}) ynothrow;
77 
78  DefGetter(const ynothrow, ErrorCode, ErrorCode, err)
80  DefGetter(const ynothrow, std::string, Message, FormatMessage(err))
81 
82  explicit DefCvt(const ynothrow, ErrorCode, err)
83 
88  static std::string
89  FormatMessage(ErrorCode) ynothrow;
91 };
92 
97 # define YF_Raise_Win32Exception(...) \
98  { \
99  const auto err(::GetLastError()); \
100  \
101  throw platform_ex::Windows::Win32Exception(err, __VA_ARGS__); \
102  }
103 
104 
110 YF_API bool
111 CheckWine();
112 
113 
114 // TODO: Add more Windows specific APIs.
115 
126 MBCSToMBCS(const char*, std::size_t, int = CP_UTF8, int = CP_ACP);
127 inline PDefH(std::string, MBCSToMBCS, const char* str, int cp_src = CP_UTF8,
128  int cp_dst = CP_ACP)
129  ImplRet(Windows::MBCSToMBCS(str, ystdex::ntctslen(str), cp_src, cp_dst))
130 inline PDefH(std::string, MBCSToMBCS, const std::string& str,
131  int cp_src = CP_UTF8, int cp_dst = CP_ACP)
132  ImplRet(Windows::MBCSToMBCS(str.c_str(), str.length(), cp_src, cp_dst))
133 
134 YF_API std::string
135 WCSToMBCS(const wchar_t*, std::size_t, int = CP_ACP);
136 inline PDefH(std::string, WCSToMBCS, const wchar_t* str, int cp = CP_ACP)
137  ImplRet(Windows::WCSToMBCS(str, ystdex::ntctslen(str), cp))
138 inline PDefH(std::string, WCSToMBCS, const std::wstring& str, int cp = CP_ACP)
139  ImplRet(Windows::WCSToMBCS(str.c_str(), str.length(), cp))
140 
141 YF_API std::wstring
142 MBCSToWCS(const char*, std::size_t, int = CP_ACP);
143 inline PDefH(std::wstring, MBCSToWCS, const char* str, int cp = CP_ACP)
144  ImplRet(Windows::MBCSToWCS(str, ystdex::ntctslen(str), cp))
145 inline PDefH(std::wstring, MBCSToWCS, const std::string& str, int cp = CP_ACP)
146  ImplRet(Windows::MBCSToWCS(str.c_str(), str.length(), cp))
148 
149 
155 class YF_API RegisterKey
156 {
157 private:
158  ::HKEY h_key;
159 
160 public:
161  RegisterKey(::HKEY h_parent, const wchar_t* key)
162  {
163  if(!::RegOpenKeyExW(h_parent, key, 0, KEY_READ, &h_key))
164  YF_Raise_Win32Exception("RegOpenKeyEx");
165  }
167  {
168  ::RegCloseKey(h_key);
169  }
170 
171  DefGetter(const ynothrow, ::HKEY, Key, h_key)
172 };
173 
174 } // namespace Windows;
175 
176 } // namespace platform_ex;
177 
178 #endif
179 
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
#define ImplRet(...)
Definition: YBaseMacro.h:97
#define YF_API
Definition: Platform.h:64
DefGetter(const ynothrow,::HKEY, Key, h_key)}
YF_API std::string MBCSToMBCS(const char *, std::size_t, int=CP_UTF8, int=CP_ACP)
转换第一个 int 参数指定编码的字符串为第二个 int 参数指定的编码。
Definition: MinGW32.cpp:98
#define ynothrow
YSLib 无异常抛出保证:若支持 noexcept 关键字, 指定特定的 noexcept 异常规范。
Definition: ydef.h:514
GSStringTemplate< char >::basic_string string
Definition: ycont.h:164
#define YF_Raise_Win32Exception(...)
按 ::GetLastError 的结果和指定参数抛出 Windows::Win32Exception 对象。
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
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:164
RegisterKey(::HKEY h_parent, const wchar_t *key)
注册表键。
pair< std::type_index, StyleItem > Key
标识查找样式的键。
Definition: ystyle.h:253