Skip to content

Commit

Permalink
Adjust file fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
cinience committed Dec 27, 2014
1 parent 3d057c9 commit 12bae13
Show file tree
Hide file tree
Showing 23 changed files with 946 additions and 942 deletions.
2 changes: 1 addition & 1 deletion RedisStudio/AbstractUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AbstraceUI : public CContainerUI, public CNotifyPump
return 0;
}

// 设置窗口句柄
/// 设置窗口句柄
inline void SetHWND(HWND hwnd)
{
m_hWnd = hwnd;
Expand Down
112 changes: 56 additions & 56 deletions RedisStudio/Base/CharacterSet.cpp
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
44 changes: 22 additions & 22 deletions RedisStudio/Base/CharacterSet.h
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
88 changes: 44 additions & 44 deletions RedisStudio/Base/Event.cpp
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
88 changes: 44 additions & 44 deletions RedisStudio/Base/Event.h
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
Loading

0 comments on commit 12bae13

Please sign in to comment.