📄 system_traits.hpp
字号:
}
public:
static int_type get_locale_info(LCID locale, LCTYPE type, char_type *data, int_type cchData)
{
return ::GetLocaleInfoA(locale, type, data, cchData);
}
public:
static size_type get_module_filename(HINSTANCE hModule, char_type* buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
if(0 == cchBuffer)
{
char_type buff[1 + _MAX_PATH];
return get_module_filename(hModule, &buff[0], STLSOFT_NUM_ELEMENTS(buff));
}
return ::GetModuleFileNameA(hModule, buffer, cchBuffer);
}
static size_type get_module_directory(HINSTANCE hModule, char_type* buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
size_type cch = get_module_filename(hModule, buffer, cchBuffer);
if( 0 != cch &&
cch < cchBuffer)
{
buffer[cch] = '\0';
char_type *s = str_rchr(buffer, '\\');
if(NULL != s)
{
*s = '\0';
cch = static_cast<size_type>(s - buffer);
}
}
return cch;
}
static size_type get_system_directory(char_type *buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
return ::GetSystemDirectoryA(buffer, cchBuffer);
}
static size_type get_windows_directory(char_type *buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
return ::GetWindowsDirectoryA(buffer, cchBuffer);
}
public:
static module_type load_library(char_type const* name)
{
WINSTL_ASSERT(NULL != name);
return ::LoadLibraryA(name);
}
static bool_type free_library(module_type hModule)
{
return system_traits_::free_library(hModule);
}
static FARPROC find_symbol(module_type hModule, char const* symbolName)
{
WINSTL_ASSERT(NULL != symbolName);
return system_traits_::find_symbol(hModule, symbolName);
}
static bool_type close_handle(handle_type h)
{
return system_traits_::close_handle(h);
}
public:
static error_type get_last_error()
{
return system_traits_::get_last_error();
}
static void set_last_error(error_type er = error_type())
{
system_traits_::set_last_error(er);
}
public:
static size_type get_environment_variable(char_type const* name, char_type* buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != name);
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
return ::GetEnvironmentVariableA(name, buffer, cchBuffer);
}
static size_type expand_environment_strings(char_type const* src, char_type *dest, size_type cch_dest)
{
WINSTL_ASSERT(NULL != src);
WINSTL_ASSERT(NULL != dest);
return static_cast<size_type>(::ExpandEnvironmentStringsA(src, dest, cch_dest));
}
};
STLSOFT_TEMPLATE_SPECIALISATION
struct system_traits<ws_char_w_t>
{
public:
typedef ws_char_w_t char_type;
typedef ws_size_t size_type;
typedef ws_ptrdiff_t difference_type;
typedef system_traits<char_type> class_type;
typedef ws_int_t int_type;
typedef ws_bool_t bool_type;
typedef HINSTANCE module_type;
typedef HANDLE handle_type;
typedef DWORD error_type;
public:
static char_type *str_copy(char_type *dest, char_type const* src)
{
WINSTL_ASSERT(NULL != dest);
WINSTL_ASSERT(NULL != src);
return ::lstrcpyW(dest, src);
}
static char_type *str_n_copy(char_type *dest, char_type const* src, size_type cch)
{
WINSTL_ASSERT(NULL != dest);
WINSTL_ASSERT(NULL != src);
return ::wcsncpy(dest, src, cch);
}
static char_type *str_cat(char_type *dest, char_type const* src)
{
WINSTL_ASSERT(NULL != dest);
WINSTL_ASSERT(NULL != src);
return ::lstrcatW(dest, src);
}
static char_type *str_n_cat(char_type *dest, char_type const* src, size_type cch)
{
WINSTL_ASSERT(NULL != dest);
WINSTL_ASSERT(NULL != src);
return ::wcsncat(dest, src, cch);
}
static int_type str_compare(char_type const* s1, char_type const* s2)
{
WINSTL_ASSERT(NULL != s1);
WINSTL_ASSERT(NULL != s2);
return ::lstrcmpW(s1, s2);
}
static int_type str_compare_no_case(char_type const* s1, char_type const* s2)
{
WINSTL_ASSERT(NULL != s1);
WINSTL_ASSERT(NULL != s2);
return ::lstrcmpiW(s1, s2);
}
static int_type str_n_compare(char_type const* s1, char_type const* s2, size_type cch)
{
WINSTL_ASSERT(NULL != s1);
WINSTL_ASSERT(NULL != s2);
return ::wcsncmp(s1, s2, cch);
}
static size_type str_len(char_type const* src)
{
WINSTL_ASSERT(NULL != src);
return static_cast<size_type>(::lstrlenW(src));
}
static char_type *str_chr(char_type const* s, char_type ch)
{
WINSTL_ASSERT(NULL != s);
return const_cast<char_type*>(::wcschr(s, ch));
}
static char_type *str_rchr(char_type const* s, char_type ch)
{
WINSTL_ASSERT(NULL != s);
return const_cast<char_type*>(::wcsrchr(s, ch));
}
static char_type *str_str(char_type const* s, char_type const* sub)
{
WINSTL_ASSERT(NULL != s);
WINSTL_ASSERT(NULL != sub);
return const_cast<char_type*>(::wcsstr(s, sub));
}
static char_type *str_pbrk(char_type const* s, char_type const* charSet)
{
WINSTL_ASSERT(NULL != s);
WINSTL_ASSERT(NULL != charSet);
return const_cast<char_type*>(::wcspbrk(s, charSet));
}
static char_type *str_end(char_type const* s)
{
WINSTL_ASSERT(NULL != s);
for(; *s != L'\0'; ++s)
{}
return const_cast<char_type*>(s);
}
public:
static int_type get_locale_info(LCID locale, LCTYPE type, char_type *data, int_type cchData)
{
return ::GetLocaleInfoW(locale, type, data, cchData);
}
public:
static size_type get_module_filename(HINSTANCE hModule, char_type* buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
if(0 == cchBuffer)
{
char_type buff[1 + _MAX_PATH];
size_type cch = get_module_filename(hModule, &buff[0], STLSOFT_NUM_ELEMENTS(buff));
if(0 == str_compare(L"\\\\?\\", buff))
{
return 1 + CONST_NT_MAX_PATH;
}
else
{
return cch;
}
}
return ::GetModuleFileNameW(hModule, buffer, cchBuffer);
}
static size_type get_module_directory(HINSTANCE hModule, char_type* buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
size_type cch = get_module_filename(hModule, buffer, cchBuffer);
if( 0 != cch &&
cch < cchBuffer)
{
buffer[cch] = '\0';
char_type *s = str_rchr(buffer, '\\');
if(NULL != s)
{
*s = '\0';
cch = static_cast<size_type>(s - buffer);
}
}
return cch;
}
static size_type get_system_directory(char_type *buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
return ::GetSystemDirectoryW(buffer, cchBuffer);
}
static size_type get_windows_directory(char_type *buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
return ::GetWindowsDirectoryW(buffer, cchBuffer);
}
public:
static module_type load_library(char_type const* name)
{
WINSTL_ASSERT(NULL != name);
return ::LoadLibraryW(name);
}
static bool_type free_library(module_type hModule)
{
return system_traits_::free_library(hModule);
}
static FARPROC find_symbol(module_type hModule, char const* symbolName)
{
WINSTL_ASSERT(NULL != symbolName);
return system_traits_::find_symbol(hModule, symbolName);
}
public:
static bool_type close_handle(handle_type h)
{
return system_traits_::close_handle(h);
}
public:
static error_type get_last_error()
{
return system_traits_::get_last_error();
}
static void set_last_error(error_type er = error_type())
{
system_traits_::set_last_error(er);
}
public:
static size_type get_environment_variable(char_type const* name, char_type* buffer, size_type cchBuffer)
{
WINSTL_ASSERT(NULL != name);
WINSTL_ASSERT(NULL != buffer || 0 == cchBuffer);
return ::GetEnvironmentVariableW(name, buffer, cchBuffer);
}
static size_type expand_environment_strings(char_type const* src, char_type *dest, size_type cch_dest)
{
WINSTL_ASSERT(NULL != src);
WINSTL_ASSERT(NULL != dest);
return static_cast<size_type>(::ExpandEnvironmentStringsW(src, dest, cch_dest));
}
};
#endif /* STLSOFT_DOCUMENTATION_SKIP_SECTION */
/* /////////////////////////////////////////////////////////////////////////
* Unit-testing
*/
#ifdef STLSOFT_UNITTEST
# include "./unittest/system_traits_unittest_.h"
#endif /* STLSOFT_UNITTEST */
/* ////////////////////////////////////////////////////////////////////// */
#ifndef _WINSTL_NO_NAMESPACE
# if defined(_STLSOFT_NO_NAMESPACE) || \
defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
} // namespace winstl
# else
} // namespace winstl_project
} // namespace stlsoft
# endif /* _STLSOFT_NO_NAMESPACE */
#endif /* !_WINSTL_NO_NAMESPACE */
/* ////////////////////////////////////////////////////////////////////// */
#endif /* WINSTL_INCL_WINSTL_SYSTEM_HPP_SYSTEM_TRAITS */
/* ////////////////////////////////////////////////////////////////////// */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -