forked from cinience/RedisStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
946 additions
and
942 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,56 @@ | ||
#include "StdAfx.h" | ||
#include "CharacterSet.h" | ||
|
||
namespace Base { | ||
|
||
std::string CharacterSet::UnicodeConvert( const std::wstring& strWide, UINT uCodePage ) | ||
{ | ||
std::string strANSI; | ||
int iLen = ::WideCharToMultiByte(uCodePage, 0, strWide.c_str(), -1, NULL, 0, NULL, NULL); | ||
|
||
if (iLen > 1) | ||
{ | ||
strANSI.resize(iLen-1); | ||
::WideCharToMultiByte(uCodePage, 0, strWide.c_str(), -1, &strANSI[0], iLen, NULL, NULL); | ||
} | ||
|
||
return strANSI; | ||
} | ||
|
||
std::string CharacterSet::UnicodeToUTF8( const std::wstring& strWide ) | ||
{ | ||
return UnicodeConvert(strWide, CP_UTF8); | ||
} | ||
|
||
std::string CharacterSet::UnicodeToANSI( const std::wstring& strWide ) | ||
{ | ||
return UnicodeConvert(strWide, CP_ACP); | ||
} | ||
|
||
std::wstring CharacterSet::ANSIToUnicode( const std::string& str ) | ||
{ | ||
int uniocedeLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); | ||
wchar_t* pUnicode = new wchar_t[uniocedeLen + 1]; | ||
memset(pUnicode, 0 ,(uniocedeLen+1)*sizeof(wchar_t)); | ||
::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, (LPWSTR)pUnicode, uniocedeLen); | ||
|
||
wstring rt = (wchar_t*) pUnicode; | ||
delete pUnicode; | ||
|
||
return rt; | ||
} | ||
|
||
std::wstring CharacterSet::UTF8ToUnicode( const std::string& str ) | ||
{ | ||
int uniocedeLen = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), NULL, 0); | ||
wchar_t* pUnicode = new wchar_t[uniocedeLen + 1]; | ||
memset(pUnicode, 0 ,(uniocedeLen+1)*sizeof(wchar_t)); | ||
::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), (LPWSTR)pUnicode, uniocedeLen); | ||
|
||
wstring rt = (wchar_t*) pUnicode; | ||
delete pUnicode; | ||
|
||
return rt; | ||
} | ||
|
||
} // namespace Base | ||
#include "StdAfx.h" | ||
#include "CharacterSet.h" | ||
|
||
namespace Base { | ||
|
||
std::string CharacterSet::UnicodeConvert( const std::wstring& strWide, UINT uCodePage ) | ||
{ | ||
std::string strANSI; | ||
int iLen = ::WideCharToMultiByte(uCodePage, 0, strWide.c_str(), -1, NULL, 0, NULL, NULL); | ||
|
||
if (iLen > 1) | ||
{ | ||
strANSI.resize(iLen-1); | ||
::WideCharToMultiByte(uCodePage, 0, strWide.c_str(), -1, &strANSI[0], iLen, NULL, NULL); | ||
} | ||
|
||
return strANSI; | ||
} | ||
|
||
std::string CharacterSet::UnicodeToUTF8( const std::wstring& strWide ) | ||
{ | ||
return UnicodeConvert(strWide, CP_UTF8); | ||
} | ||
|
||
std::string CharacterSet::UnicodeToANSI( const std::wstring& strWide ) | ||
{ | ||
return UnicodeConvert(strWide, CP_ACP); | ||
} | ||
|
||
std::wstring CharacterSet::ANSIToUnicode( const std::string& str ) | ||
{ | ||
int uniocedeLen = ::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, NULL, 0); | ||
wchar_t* pUnicode = new wchar_t[uniocedeLen + 1]; | ||
memset(pUnicode, 0 ,(uniocedeLen+1)*sizeof(wchar_t)); | ||
::MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, (LPWSTR)pUnicode, uniocedeLen); | ||
|
||
wstring rt = (wchar_t*) pUnicode; | ||
delete pUnicode; | ||
|
||
return rt; | ||
} | ||
|
||
std::wstring CharacterSet::UTF8ToUnicode( const std::string& str ) | ||
{ | ||
int uniocedeLen = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), NULL, 0); | ||
wchar_t* pUnicode = new wchar_t[uniocedeLen + 1]; | ||
memset(pUnicode, 0 ,(uniocedeLen+1)*sizeof(wchar_t)); | ||
::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.size(), (LPWSTR)pUnicode, uniocedeLen); | ||
|
||
wstring rt = (wchar_t*) pUnicode; | ||
delete pUnicode; | ||
|
||
return rt; | ||
} | ||
|
||
} // namespace Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
#ifndef Base_CharacterSet_INCLUDED | ||
#define Base_CharacterSet_INCLUDED | ||
|
||
namespace Base { | ||
|
||
class CharacterSet | ||
{ | ||
public: | ||
static std::string UnicodeConvert(const std::wstring& strWide, UINT uCodePage); | ||
|
||
static std::string UnicodeToUTF8(const std::wstring& strWide); | ||
|
||
static std::string UnicodeToANSI(const std::wstring& strWide); | ||
|
||
static std::wstring ANSIToUnicode(const std::string& str); | ||
|
||
static std::wstring UTF8ToUnicode(const std::string& str); | ||
|
||
}; | ||
|
||
} // namespace Base | ||
|
||
#ifndef Base_CharacterSet_INCLUDED | ||
#define Base_CharacterSet_INCLUDED | ||
|
||
namespace Base { | ||
|
||
class CharacterSet | ||
{ | ||
public: | ||
static std::string UnicodeConvert(const std::wstring& strWide, UINT uCodePage); | ||
|
||
static std::string UnicodeToUTF8(const std::wstring& strWide); | ||
|
||
static std::string UnicodeToANSI(const std::wstring& strWide); | ||
|
||
static std::wstring ANSIToUnicode(const std::string& str); | ||
|
||
static std::wstring UTF8ToUnicode(const std::string& str); | ||
|
||
}; | ||
|
||
} // namespace Base | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
#include "StdAfx.h" | ||
#include "Event.h" | ||
|
||
namespace Base { | ||
|
||
Event::Event(bool autoReset) | ||
{ | ||
_event = CreateEventW(NULL, autoReset ? FALSE : TRUE, FALSE, NULL); | ||
if (!_event) | ||
throw std::exception("cannot create event"); | ||
} | ||
|
||
|
||
Event::~Event() | ||
{ | ||
CloseHandle(_event); | ||
} | ||
|
||
|
||
void Event::wait() | ||
{ | ||
switch (WaitForSingleObject(_event, INFINITE)) | ||
{ | ||
case WAIT_OBJECT_0: | ||
return; | ||
default: | ||
throw std::exception("wait for event failed"); | ||
} | ||
} | ||
|
||
|
||
bool Event::wait(long milliseconds) | ||
{ | ||
switch (WaitForSingleObject(_event, milliseconds + 1)) | ||
{ | ||
case WAIT_TIMEOUT: | ||
return false; | ||
case WAIT_OBJECT_0: | ||
return true; | ||
default: | ||
throw std::exception("wait for event failed"); | ||
} | ||
} | ||
|
||
#include "StdAfx.h" | ||
#include "Event.h" | ||
|
||
namespace Base { | ||
|
||
Event::Event(bool autoReset) | ||
{ | ||
_event = CreateEventW(NULL, autoReset ? FALSE : TRUE, FALSE, NULL); | ||
if (!_event) | ||
throw std::exception("cannot create event"); | ||
} | ||
|
||
|
||
Event::~Event() | ||
{ | ||
CloseHandle(_event); | ||
} | ||
|
||
|
||
void Event::wait() | ||
{ | ||
switch (WaitForSingleObject(_event, INFINITE)) | ||
{ | ||
case WAIT_OBJECT_0: | ||
return; | ||
default: | ||
throw std::exception("wait for event failed"); | ||
} | ||
} | ||
|
||
|
||
bool Event::wait(long milliseconds) | ||
{ | ||
switch (WaitForSingleObject(_event, milliseconds + 1)) | ||
{ | ||
case WAIT_TIMEOUT: | ||
return false; | ||
case WAIT_OBJECT_0: | ||
return true; | ||
default: | ||
throw std::exception("wait for event failed"); | ||
} | ||
} | ||
|
||
} //namespace Base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
#ifndef Base_Event_INCLUDED | ||
#define Base_Event_INCLUDED | ||
|
||
#include <Windows.h> | ||
#include <exception> | ||
|
||
namespace Base { | ||
class Event | ||
{ | ||
public: | ||
Event(bool autoReset); | ||
~Event(); | ||
void set(); | ||
void wait(); | ||
bool wait(long milliseconds); | ||
void reset(); | ||
|
||
private: | ||
HANDLE _event; | ||
}; | ||
|
||
|
||
// | ||
// inlines | ||
// | ||
inline void Event::set() | ||
{ | ||
if (!SetEvent(_event)) | ||
{ | ||
throw std::exception("cannot signal event"); | ||
} | ||
} | ||
|
||
|
||
inline void Event::reset() | ||
{ | ||
if (!ResetEvent(_event)) | ||
{ | ||
throw std::exception("cannot reset event"); | ||
} | ||
} | ||
|
||
} //namespace Base | ||
|
||
#ifndef Base_Event_INCLUDED | ||
#define Base_Event_INCLUDED | ||
|
||
#include <Windows.h> | ||
#include <exception> | ||
|
||
namespace Base { | ||
class Event | ||
{ | ||
public: | ||
Event(bool autoReset); | ||
~Event(); | ||
void set(); | ||
void wait(); | ||
bool wait(long milliseconds); | ||
void reset(); | ||
|
||
private: | ||
HANDLE _event; | ||
}; | ||
|
||
|
||
// | ||
// inlines | ||
// | ||
inline void Event::set() | ||
{ | ||
if (!SetEvent(_event)) | ||
{ | ||
throw std::exception("cannot signal event"); | ||
} | ||
} | ||
|
||
|
||
inline void Event::reset() | ||
{ | ||
if (!ResetEvent(_event)) | ||
{ | ||
throw std::exception("cannot reset event"); | ||
} | ||
} | ||
|
||
} //namespace Base | ||
|
||
#endif |
Oops, something went wrong.