Skip to content

Commit 1a76af8

Browse files
committed
Refactoring for usage of STL classes
1 parent 3a11728 commit 1a76af8

File tree

6 files changed

+19
-29
lines changed

6 files changed

+19
-29
lines changed

SimpleCom/SerialSetup.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void SimpleCom::SerialSetup::initialize() {
131131
delete[] DeviceName;
132132
}
133133

134-
static void AddStringToComboBox(HWND hCombo, SimpleCom::TString str) {
134+
static void AddStringToComboBox(HWND hCombo, TString str) {
135135
LRESULT result = SendMessage(hCombo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(str.c_str()));
136136
if (result == CB_ERR) {
137137
throw SimpleCom::WinAPIException(_T("CB_ERR"), _T("AddStringToComboBox"));
@@ -145,7 +145,7 @@ static void InitializeDialog(HWND hDlg, SimpleCom::SerialSetup *setup) {
145145
// Initialize serial configuration.
146146
// Initial value is for serial console of Raspberry Pi.
147147

148-
SimpleCom::TString text_str;
148+
TString text_str;
149149

150150
HWND hComboSerialDevice = GetDlgItem(hDlg, IDC_SERIAL_DEVICE);
151151
if (hComboSerialDevice == NULL) {
@@ -386,11 +386,7 @@ void SimpleCom::SerialSetup::ParseArguments(int argc, LPCTSTR argv[]) {
386386
}
387387
}
388388
else {
389-
#ifdef _UNICODE
390-
std::wregex re(_T("^COM\\d+$"));
391-
#else
392-
std::regex re("^COM\\d+$");
393-
#endif
389+
TRegex re(_T("^COM\\d+$"));
394390
if (std::regex_match(argv[i], re)) {
395391
SetPort(argv[i]);
396392
}

SimpleCom/SerialSetup.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ namespace SimpleCom {
4242
constexpr explicit StopBits(const int value, LPCTSTR str) noexcept : EnumValue(value, str) {};
4343
};
4444

45-
#ifdef UNICODE
46-
typedef std::wstring TString;
47-
#else /* UNICODE */
48-
typedef std::string TString;
49-
#endif /* UNICODE */
50-
5145
typedef std::map<TString, TString> TDeviceMap;
5246

5347
/*

SimpleCom/SimpleCom.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ static HWND GetParentWindow() {
191191

192192
}
193193

194-
static void InitSerialPort(SimpleCom::TString &device, DCB *dcb) {
195-
SimpleCom::TString title = _T("SimpleCom: ") + device;
194+
static void InitSerialPort(TString &device, DCB *dcb) {
195+
TString title = _T("SimpleCom: ") + device;
196196
CALL_WINAPI_WITH_DEBUGLOG(SetConsoleTitle(title.c_str()), TRUE, __FILE__, __LINE__)
197197

198198
CALL_WINAPI_WITH_DEBUGLOG(SetCommState(hSerial, dcb), TRUE, __FILE__, __LINE__)
@@ -260,7 +260,7 @@ class HandleHandler {
260260
int _tmain(int argc, LPCTSTR argv[])
261261
{
262262
DCB dcb;
263-
SimpleCom::TString device;
263+
TString device;
264264
HWND parent_hwnd = GetParentWindow();
265265

266266
// Serial port configuration

SimpleCom/WinAPIException.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ SimpleCom::WinAPIException::WinAPIException(DWORD error_code, LPCTSTR error_capt
3434
_sntprintf_s(fallback_error_text, sizeof(fallback_error_text) / sizeof(TCHAR), _T("Error occured (%#x)"), _error_code);
3535
_error_text = fallback_error_text;
3636

37-
#ifdef _UNICODE
38-
std::wstringstream msg;
39-
#else
40-
std::stringstream msg;
41-
#endif
37+
TStringStream msg;
4238
msg << _T("Error occurred in FormatMessage (") << std::showbase << std::hex << errcode << _T(")");
4339
debug::log(msg.str().c_str());
4440
}

SimpleCom/debug.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,10 @@
2020

2121
#include "stdafx.h"
2222

23-
#ifdef _UNICODE
24-
#define SS_CLASS std::wstringstream
25-
#else
26-
#define SS_CLASS std::stringstream
27-
#endif
28-
2923
#define CALL_WINAPI_WITH_DEBUGLOG(func_call, expected, file, line) \
3024
if (func_call != expected) { \
3125
SimpleCom::WinAPIException e(GetLastError(), nullptr); \
32-
SS_CLASS ss; \
26+
TStringStream ss; \
3327
ss << file << _T(":") << line << _T(": ") << e.GetErrorText() << std::endl; \
3428
SimpleCom::debug::log(ss.str().c_str()); \
3529
}

SimpleCom/stdafx.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,14 @@
1616
#include <map>
1717
#include <regex>
1818
#include <sstream>
19-
#include <string>
19+
#include <string>
20+
21+
#ifdef _UNICODE
22+
typedef std::wstring TString;
23+
typedef std::wstringstream TStringStream;
24+
typedef std::wregex TRegex;
25+
#else
26+
typedef std::string TString;
27+
typedef std::stringstream TStringStream;
28+
typedef std::regex TRegex;
29+
#endif

0 commit comments

Comments
 (0)