• R/O
  • SSH
  • HTTPS

ppregnessem: Commit


Commit MetaInfo

Revision115 (tree)
Time2010-07-26 01:04:26
Authorkamoya

Log Message

dummy:

ToString / std::to_string wrapper
ConvertString<T>

Common/NsmInfoUtility.cpp -> Common/NsmInfoUtility.h

cosmetics

Change Summary

Incremental Difference

--- trunk/StrRsc/src/OptionDlg.cpp (revision 114)
+++ trunk/StrRsc/src/OptionDlg.cpp (revision 115)
@@ -1,4 +1,5 @@
1-#include <vector>
1+#include "OptionDlg.h"
2+
23 #include <shlwapi.h>
34 #if defined(_MSC_VER)
45 #pragma comment(lib, "shlwapi.lib")
@@ -8,7 +9,6 @@
89 #include "../../Common/StrResource.h"
910
1011 #include "DlgOption.h"
11-#include "OptionDlg.h"
1212
1313 #define RS_OK TEXT("Ok")
1414 #define RS_CANCEL TEXT("Cancel")
--- trunk/StrRsc/src/StrRsc.cpp (revision 114)
+++ trunk/StrRsc/src/StrRsc.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "StrRsc.h"
2+
13 #include <algorithm>
24 #include <vector>
35 #include <windows.h>
@@ -11,9 +13,7 @@
1113 #include "../../Common/StrResource.h"
1214
1315 #include "OptionDlg.h"
14-#include "StrRscConfig.h"
1516 #include "StrRscConsts.h"
16-#include "StrRsc.h"
1717
1818 HINSTANCE g_hInstance;
1919
--- trunk/StrRsc/src/OptionDlg.h (revision 114)
+++ trunk/StrRsc/src/OptionDlg.h (revision 115)
@@ -1,6 +1,7 @@
11 #ifndef OPTIONDLG_H
22 #define OPTIONDLG_H
33
4+#include <vector>
45 #include <windows.h>
56
67 #include "../../Common/tstring.h"
--- trunk/StrRsc/src/StrRsc.h (revision 114)
+++ trunk/StrRsc/src/StrRsc.h (revision 115)
@@ -8,6 +8,8 @@
88 #include "../../Common/NsmPluginMain.h"
99 #include "../../Common/StrRscTypes.h"
1010
11+#include "StrRscConfig.h"
12+
1113 namespace Regnessem
1214 {
1315 namespace AddIn
--- trunk/StrRsc/src/StrRscConfig.cpp (revision 114)
+++ trunk/StrRsc/src/StrRscConfig.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "StrRscConfig.h"
2+
13 #include <windows.h>
24 #include <shlwapi.h>
35 #if defined(_MSC_VER)
@@ -6,8 +8,6 @@
68
79 #include "../../Common/dummy.h"
810
9-#include "StrRscConfig.h"
10-
1111 namespace Regnessem
1212 {
1313 namespace AddIn
--- trunk/ProfMan/src/ProfMan.cpp (revision 114)
+++ trunk/ProfMan/src/ProfMan.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "ProfMan.h"
2+
13 #include <algorithm>
24 #include <sstream>
35 #include <deque>
@@ -11,7 +13,6 @@
1113 #include "../../Common/dummy.h"
1214
1315 #include "ProfManConsts.h"
14-#include "ProfMan.h"
1516
1617 HINSTANCE g_hInstance;
1718
--- trunk/ClientSocket/src/OptionDlg.cpp (revision 114)
+++ trunk/ClientSocket/src/OptionDlg.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "OptionDlg.h"
2+
13 #include <vector>
24 #include <sstream>
35
@@ -6,7 +8,6 @@
68
79 #include "ClientSocketConsts.h"
810 #include "DlgOption.h"
9-#include "OptionDlg.h"
1011
1112 extern HINSTANCE g_hInstance;
1213
@@ -62,7 +63,7 @@
6263 }
6364
6465 SetDlgItemText(hDialog,IDC_EDPROXYHOST,ProxyHost.c_str());
65- SetDlgItemText(hDialog,IDC_EDPROXYPORT,ToString(ProxyPort).c_str());
66+ SetDlgItemText(hDialog,IDC_EDPROXYPORT,ToString(static_cast<unsigned>(ProxyPort)).c_str());
6667
6768 SendDlgItemMessage(hDialog,IDC_CBPROXYTYPE,CB_INSERTSTRING,static_cast<WPARAM>(-1),reinterpret_cast<LPARAM>(TEXT("HTTP")));
6869 SendDlgItemMessage(hDialog,IDC_CBPROXYTYPE,CB_INSERTSTRING,static_cast<WPARAM>(-1),reinterpret_cast<LPARAM>(TEXT("SOCKS4")));
--- trunk/ClientSocket/src/OptionDlg.h (revision 114)
+++ trunk/ClientSocket/src/OptionDlg.h (revision 115)
@@ -3,6 +3,8 @@
33
44 #include <windows.h>
55
6+#include "../../Common/tstring.h"
7+
68 namespace Regnessem
79 {
810 namespace AddIn
--- trunk/ClientSocket/src/NsmClientSocket.cpp (revision 114)
+++ trunk/ClientSocket/src/NsmClientSocket.cpp (revision 115)
@@ -2,15 +2,16 @@
22 #pragma comment(lib, "ws2_32.lib")
33 #endif
44
5+#include <winsock2.h>
6+#include "NsmClientSocket.h"
7+
58 #include <sstream>
69
7-#include <winsock2.h>
810 #include <ws2tcpip.h>
911
1012 #include "../../Common/dummy.h"
1113
1214 #include "ClientSocketConsts.h"
13-#include "NsmClientSocket.h"
1415
1516 extern HINSTANCE g_hInstance;
1617
--- trunk/ClientSocket/src/ClientSocket.cpp (revision 114)
+++ trunk/ClientSocket/src/ClientSocket.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "ClientSocket.h"
2+
13 #include <algorithm>
24
35 #include "../../Common/dummy.h"
@@ -6,7 +8,6 @@
68
79 #include "ClientSocketConsts.h"
810 #include "OptionDlg.h"
9-#include "ClientSocket.h"
1011
1112 #ifdef NDEBUG
1213 #define RgnOutputDebugString(str)
--- trunk/ClientSocket/src/NsmClientSocket.h (revision 114)
+++ trunk/ClientSocket/src/NsmClientSocket.h (revision 115)
@@ -3,6 +3,7 @@
33
44 #include <vector>
55
6+#include "../../Common/tstring.h"
67 #include "../../Common/LockList.h"
78 #include "../../Common/ClientSocketTypes.h"
89
--- trunk/ClientSocket/src/ClientSocketConfig.cpp (revision 114)
+++ trunk/ClientSocket/src/ClientSocketConfig.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "ClientSocketConfig.h"
2+
13 #include <vector>
24 #include <sstream>
35
@@ -7,7 +9,6 @@
79 #include "../../Common/dummy.h"
810
911 #include "ClientSocketConsts.h"
10-#include "ClientSocketConfig.h"
1112
1213 namespace Regnessem
1314 {
--- trunk/FileIO/src/OptionDlg.cpp (revision 114)
+++ trunk/FileIO/src/OptionDlg.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "OptionDlg.h"
2+
13 #include <vector>
24
35 #include <shlobj.h>
@@ -6,7 +8,6 @@
68
79 #include "FileIOConfig.h"
810 #include "DlgOption.h"
9-#include "OptionDlg.h"
1011
1112 extern HINSTANCE g_hInstance;
1213
--- trunk/FileIO/src/OptionDlg.h (revision 114)
+++ trunk/FileIO/src/OptionDlg.h (revision 115)
@@ -3,6 +3,8 @@
33
44 #include <windows.h>
55
6+#include "../../Common/tstring.h"
7+
68 namespace Regnessem
79 {
810 namespace AddIn
--- trunk/FileIO/src/FileIO.cpp (revision 114)
+++ trunk/FileIO/src/FileIO.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "FileIO.h"
2+
13 #include <algorithm>
24
35 #include <shobjidl.h>
@@ -11,9 +13,7 @@
1113 #include "../../Common/NsmInfoUtility.h"
1214
1315 #include "OptionDlg.h"
14-#include "FileIOConfig.h"
1516 #include "FileIOConsts.h"
16-#include "FileIO.h"
1717
1818 HINSTANCE g_hInstance;
1919
--- trunk/FileIO/src/FileIO.h (revision 114)
+++ trunk/FileIO/src/FileIO.h (revision 115)
@@ -9,6 +9,7 @@
99 #include "../../Common/LockList.h"
1010
1111 #include "FileIOTypes.h"
12+#include "FileIOConfig.h"
1213
1314 namespace Regnessem
1415 {
--- trunk/Common/NsmInfoUtility.cpp (revision 114)
+++ trunk/Common/NsmInfoUtility.cpp (nonexistent)
@@ -1,193 +0,0 @@
1-#include <algorithm>
2-
3-#include "dummy.h"
4-#include "UNsmConsts.h"
5-#include "NsmInfoUtility.h"
6-
7-namespace Regnessem
8-{
9- namespace Common
10- {
11- namespace NsmInfoUtility
12- {
13- template <int Type> struct NsmInfoValueType;
14- template <> struct NsmInfoValueType<NMIT_STRING> { typedef char Type; };
15- template <> struct NsmInfoValueType<NMIT_WIDESTRING> { typedef wchar_t Type; };
16- template <> struct NsmInfoValueType<NMIT_INTEGER> { typedef INT32 Type; };
17- template <> struct NsmInfoValueType<NMIT_BOOL> { typedef unsigned char Type; };
18- template <> struct NsmInfoValueType<NMIT_INT64> { typedef INT64 Type; };
19-
20- template <int InfoType>
21- inline int IntegerToNsmInfo(TNsmInfo *nsmInfo, typename NsmInfoValueType<InfoType>::Type value)
22- {
23- typedef typename NsmInfoValueType<InfoType>::Type T;
24-
25- if(!nsmInfo)
26- return 0;
27-
28- if(!nsmInfo->lpBuffer)
29- return 0;
30-
31- if(nsmInfo->nBufferSize < sizeof(T))
32- return 0;
33-
34- nsmInfo->nType = InfoType;
35- *static_cast<T*>(nsmInfo->lpBuffer) = value;
36-
37- return sizeof(T);
38- }
39-
40- template <int InfoType>
41- inline int StringToNsmInfo(TNsmInfo *nsmInfo, const std::basic_string<typename NsmInfoValueType<InfoType>::Type> &str)
42- {
43- typedef typename NsmInfoValueType<InfoType>::Type T;
44-
45- if(!nsmInfo)
46- return 0;
47-
48- if(!nsmInfo->lpBuffer)
49- return 0;
50-
51- if(nsmInfo->nBufferSize < sizeof(T))
52- return 0;
53-
54- nsmInfo->nType = InfoType;
55- typename std::basic_string<T>::size_type len
56- = std::min<typename std::basic_string<T>::size_type>(nsmInfo->nBufferSize / sizeof(T) - 1, str.size());
57-
58-#ifdef _MSC_VER
59- str._Copy_s(static_cast<T*>(nsmInfo->lpBuffer), nsmInfo->nBufferSize / sizeof(T), len);
60-#else
61- str.copy(static_cast<T*>(nsmInfo->lpBuffer), len);
62-#endif
63-
64- static_cast<T*>(nsmInfo->lpBuffer)[len] = T();
65- return static_cast<int>((len + 1) * sizeof(T));
66- }
67-
68- template <int InfoType>
69- inline typename NsmInfoValueType<InfoType>::Type NsmInfoToInteger(const TNsmInfo *nsmInfo)
70- {
71- typedef typename NsmInfoValueType<InfoType>::Type T;
72-
73- if(!nsmInfo)
74- return 0;
75-
76- if(!nsmInfo->lpBuffer)
77- return 0;
78-
79- if(nsmInfo->nBufferSize < sizeof(T))
80- return 0;
81-
82- if(nsmInfo->nType == InfoType)
83- return *static_cast<T*>(nsmInfo->lpBuffer);
84-
85- return 0;
86- }
87-
88- //----
89-
90- int StrToNsmInfo(const PNsmInfo nsmInfo, const std::string &value)
91- {
92- return StringToNsmInfo<NMIT_STRING>(nsmInfo, value);
93- }
94-
95- int StrToNsmInfo(const PNsmInfo nsmInfo, const std::wstring &value)
96- {
97- return StringToNsmInfo<NMIT_WIDESTRING>(nsmInfo, value);
98- }
99-
100- int IntToNsmInfo(const PNsmInfo nsmInfo, const INT32 value)
101- {
102- return IntegerToNsmInfo<NMIT_INTEGER>(nsmInfo, value);
103- }
104-
105- int Int64ToNsmInfo(const PNsmInfo nsmInfo, const INT64 value)
106- {
107- return IntegerToNsmInfo<NMIT_INT64>(nsmInfo, value);
108- }
109-
110- int BoolToNsmInfo(const PNsmInfo nsmInfo, const bool value)
111- {
112- return IntegerToNsmInfo<NMIT_BOOL>(nsmInfo, value ? 1 : 0);
113- }
114-
115- //-----------------------------------------------------------------------------------------------
116-
117- const std::size_t NsmInfoStrMaxLength = 1024 * 100;
118-
119- std::string NsmInfoToStrA(const TNsmInfo *const nsmInfo)
120- {
121- if(!nsmInfo)
122- return std::string();
123-
124- if(!nsmInfo->lpBuffer)
125- return std::string();
126-
127- switch(nsmInfo->nType)
128- {
129- case NMIT_STRING:
130- if(sizeof(char) <= nsmInfo->nBufferSize)
131- {
132- const char *const begin = static_cast<char*>(nsmInfo->lpBuffer);
133- return std::string(begin, std::find(begin, begin + NsmInfoStrMaxLength, char()));
134- }
135- break;
136- case NMIT_WIDESTRING:
137- if(sizeof(wchar_t) <= nsmInfo->nBufferSize)
138- {
139- const wchar_t *const begin = static_cast<wchar_t*>(nsmInfo->lpBuffer);
140- return w2c(std::wstring(begin, std::find(begin, begin + NsmInfoStrMaxLength, wchar_t())));
141- }
142- break;
143- }
144-
145- return std::string();
146- }
147-
148- std::wstring NsmInfoToStrW(const TNsmInfo *const nsmInfo)
149- {
150- if(!nsmInfo)
151- return std::wstring();
152-
153- if(!nsmInfo->lpBuffer)
154- return std::wstring();
155-
156- switch(nsmInfo->nType)
157- {
158- case NMIT_STRING:
159- if(sizeof(char) <= nsmInfo->nBufferSize)
160- {
161- const char *const begin = static_cast<char*>(nsmInfo->lpBuffer);
162- return c2w(std::string(begin, std::find(begin, begin + NsmInfoStrMaxLength, char())));
163- }
164- break;
165- case NMIT_WIDESTRING:
166- if(sizeof(wchar_t) <= nsmInfo->nBufferSize)
167- {
168- const wchar_t *const begin = static_cast<wchar_t*>(nsmInfo->lpBuffer);
169- return std::wstring(begin, std::find(begin, begin + NsmInfoStrMaxLength, wchar_t()));
170- }
171- break;
172- }
173-
174- return std::wstring();
175- }
176-
177- INT32 NsmInfoToInt(const TNsmInfo *const nsmInfo)
178- {
179- return NsmInfoToInteger<NMIT_INTEGER>(nsmInfo);
180- }
181-
182- INT64 NsmInfoToInt64(const TNsmInfo *const nsmInfo)
183- {
184- return NsmInfoToInteger<NMIT_INT64>(nsmInfo);
185- }
186-
187- bool NsmInfoToBool(const TNsmInfo *const nsmInfo)
188- {
189- return NsmInfoToInteger<NMIT_BOOL>(nsmInfo) != 0;
190- }
191- }
192- }
193-}
--- trunk/Common/dummy.h (revision 114)
+++ trunk/Common/dummy.h (revision 115)
@@ -7,31 +7,42 @@
77
88 #include "tstring.h"
99
10-std::tstring PtrToHex(const void *const value);
10+std::tstring PtrToHex(const void* value);
1111
12+namespace dummy_private
13+{
14+ template <typename T> struct to_string_type {};
15+ template <> struct to_string_type<int> { typedef long long cast_type; };
16+ template <> struct to_string_type<long> { typedef long long cast_type; };
17+ template <> struct to_string_type<long long> { typedef long long cast_type; };
18+ template <> struct to_string_type<unsigned> { typedef unsigned long long cast_type; };
19+ template <> struct to_string_type<unsigned long> { typedef unsigned long long cast_type; };
20+ template <> struct to_string_type<unsigned long long> { typedef unsigned long long cast_type; };
21+}
22+
1223 template <typename T>
13-std::string ToStringA(T value)
24+std::string ToStringA(T val)
1425 {
15- std::stringstream strm;
16- strm << value;
17- return strm.str();
26+ return std::to_string(static_cast<typename dummy_private::to_string_type<T>::cast_type>(val));
1827 }
1928
2029 template <typename T>
21-std::wstring ToStringW(T value)
30+std::wstring ToStringW(T val)
2231 {
23- std::wstringstream strm;
24- strm << value;
25- return strm.str();
32+ return std::to_wstring(static_cast<typename dummy_private::to_string_type<T>::cast_type>(val));
2633 }
2734
35+template <typename T>
36+Regnessem::tstring ToString(T val)
37+{
2838 #ifdef UNICODE
29-#define ToString ToStringW
39+ return ToStringW(val);
3040 #else
31-#define ToString ToStringA
41+ return ToStringA(val);
3242 #endif
43+}
3344
34-std::tstring TimeToStr(time_t);
45+std::tstring TimeToStr(std::time_t t);
3546
3647 std::tstring ExtractFileName(const std::tstring &fileName);
3748 std::tstring ExtractFilePath(const std::tstring &fileName);
@@ -38,24 +49,34 @@
3849
3950 bool ForceDirectories(const std::tstring &dirPath);
4051
41-const std:: string w2c(const std::wstring &src);
42-const std::wstring c2w(const std:: string &src);
52+std:: string w2c(const std::wstring &src);
53+std::wstring c2w(const std:: string &src);
4354
44-inline const std::wstring& w2w(const std::wstring &src){return src;}
45-inline const std:: string& c2c(const std:: string &src){return src;}
55+namespace dummy_private
56+{
57+ inline std:: string t2x(const std::wstring &str){return w2c(str);}
58+ inline std::wstring t2x(const std:: string &str){return c2w(str);}
59+}
4660
47-#ifdef UNICODE
48-#define w2t w2w
49-#define c2t c2w
50-#define t2c w2c
51-#define t2w w2w
52-#else
53-#define w2t w2c
54-#define c2t c2c
55-#define t2c c2c
56-#define t2w c2w
57-#endif
61+template <typename T, typename U>
62+std::basic_string<T> ConvertString(const std::basic_string<U> &str,
63+ typename std::enable_if<std::is_same<T, U>::value>::type* = 0)
64+{
65+ return str;
66+}
5867
68+template <typename T, typename U>
69+std::basic_string<T> ConvertString(const std::basic_string<U> &str,
70+ typename std::enable_if<!std::is_same<T, U>::value>::type* = 0)
71+{
72+ return dummy_private::t2x(str);
73+}
74+
75+inline Regnessem::tstring w2t(const std::wstring &src){return ConvertString<Regnessem::tstring::value_type>(src);}
76+inline Regnessem::tstring c2t(const std:: string &src){return ConvertString<Regnessem::tstring::value_type>(src);}
77+inline std:: string t2c(const Regnessem::tstring &src){return ConvertString<char>(src);}
78+inline std::wstring t2w(const Regnessem::tstring &src){return ConvertString<wchar_t>(src);}
79+
5980 #if defined(WINCE)
6081 // compatibility
6182 #define GWLP_WNDPROC (-4)
--- trunk/Common/NsmInfoUtility.h (revision 114)
+++ trunk/Common/NsmInfoUtility.h (revision 115)
@@ -1,6 +1,11 @@
11 #ifndef NSMINFOUTILITY_H
22 #define NSMINFOUTILITY_H
33
4+#include <cstdint>
5+#include <algorithm>
6+
7+#include "dummy.h"
8+#include "UNsmConsts.h"
49 #include "NsmTypes.h"
510 #include "tstring.h"
611
@@ -10,26 +15,170 @@
1015 {
1116 namespace NsmInfoUtility
1217 {
13- int StrToNsmInfo(const PNsmInfo nsmInfo, const std::string &value); // std::string -> TNsmInfo
14- int StrToNsmInfo(const PNsmInfo nsmInfo, const std::wstring &value); // std::wstring -> TNsmInfo
15- int IntToNsmInfo(const PNsmInfo nsmInfo, const INT32 value); // INT32 -> TNsmInfo
16- int Int64ToNsmInfo(const PNsmInfo nsmInfo, const INT64 value); // INT64 -> TNsmInfo
17- int BoolToNsmInfo(const PNsmInfo nsmInfo, const bool value); // bool -> TNsmInfo
18+ template <int Type> struct NsmInfoValueType;
19+ template <> struct NsmInfoValueType<NMIT_STRING> { typedef char Type; };
20+ template <> struct NsmInfoValueType<NMIT_WIDESTRING> { typedef wchar_t Type; };
21+ template <> struct NsmInfoValueType<NMIT_INTEGER> { typedef std::int32_t Type; };
22+ template <> struct NsmInfoValueType<NMIT_BOOL> { typedef unsigned char Type; };
23+ template <> struct NsmInfoValueType<NMIT_INT64> { typedef std::int64_t Type; };
1824
19- std::string NsmInfoToStrA(const TNsmInfo *const nsmInfo); // TNsmInfo -> std::string
20- std::wstring NsmInfoToStrW(const TNsmInfo *const nsmInfo); // TNsmInfo -> std::wstring
21- INT32 NsmInfoToInt(const TNsmInfo *const nsmInfo); // TNsmInfo -> INT32
22- INT64 NsmInfoToInt64(const TNsmInfo *const nsmInfo); // TNsmInfo -> INT64
23- bool NsmInfoToBool(const TNsmInfo *const nsmInfo); // TNsmInfo -> bool
25+ inline bool CheckPtr(const TNsmInfo *nsmInfo)
26+ {
27+ if(!nsmInfo)
28+ return false;
2429
25- inline std::tstring NsmInfoToStr(const TNsmInfo *const nsmInfo)
30+ if(!nsmInfo->lpBuffer)
31+ return false;
32+
33+ return true;
34+ }
35+
36+ template <typename T>
37+ bool CheckBuff(const TNsmInfo *nsmInfo)
2638 {
27-#ifdef UNICODE
28- return NsmInfoToStrW(nsmInfo);
39+ if(!CheckPtr(nsmInfo))
40+ return false;
41+
42+ if(nsmInfo->nBufferSize < sizeof(T))
43+ return false;
44+
45+ return true;
46+ }
47+
48+ template <int InfoType>
49+ int IntegerToNsmInfo(TNsmInfo *nsmInfo, typename NsmInfoValueType<InfoType>::Type value)
50+ {
51+ typedef typename NsmInfoValueType<InfoType>::Type T;
52+
53+ if(!CheckBuff<T>(nsmInfo))
54+ return 0;
55+
56+ nsmInfo->nType = InfoType;
57+ *static_cast<T*>(nsmInfo->lpBuffer) = value;
58+
59+ return sizeof(T);
60+ }
61+
62+ template <int InfoType>
63+ int StringToNsmInfo(TNsmInfo *nsmInfo, const std::basic_string<typename NsmInfoValueType<InfoType>::Type> &str)
64+ {
65+ typedef typename NsmInfoValueType<InfoType>::Type T;
66+
67+ if(!CheckBuff<T>(nsmInfo))
68+ return 0;
69+
70+ nsmInfo->nType = InfoType;
71+ auto len = std::min<typename std::basic_string<T>::size_type>(nsmInfo->nBufferSize / sizeof(T) - 1, str.size());
72+
73+#ifdef _MSC_VER
74+ str._Copy_s(static_cast<T*>(nsmInfo->lpBuffer), nsmInfo->nBufferSize / sizeof(T), len);
2975 #else
30- return NsmInfoToStrA(nsmInfo);
76+ str.copy(static_cast<T*>(nsmInfo->lpBuffer), len);
3177 #endif
78+
79+ static_cast<T*>(nsmInfo->lpBuffer)[len] = T();
80+ return static_cast<int>((len + 1) * sizeof(T));
3281 }
82+
83+ template <int InfoType>
84+ typename NsmInfoValueType<InfoType>::Type NsmInfoToInteger(const TNsmInfo *nsmInfo)
85+ {
86+ typedef typename NsmInfoValueType<InfoType>::Type T;
87+
88+ if(!CheckBuff<T>(nsmInfo))
89+ return T();
90+
91+ if(nsmInfo->nType != InfoType)
92+ return T();
93+
94+ return *static_cast<T*>(nsmInfo->lpBuffer);
95+ }
96+
97+ template <typename T>
98+ std::basic_string<T> NsmInfoToString(const TNsmInfo *nsmInfo)
99+ {
100+ static const std::size_t NsmInfoStrMaxLength = 1024 * 100;
101+
102+ if(!CheckPtr(nsmInfo))
103+ return std::basic_string<T>();
104+
105+ switch(nsmInfo->nType)
106+ {
107+ case NMIT_STRING:
108+ if(sizeof(char) <= nsmInfo->nBufferSize)
109+ {
110+ const char *const begin = static_cast<char*>(nsmInfo->lpBuffer);
111+ return ConvertString<T>(std::string(begin, std::find(begin, begin + NsmInfoStrMaxLength, char())));
112+ }
113+ break;
114+ case NMIT_WIDESTRING:
115+ if(sizeof(wchar_t) <= nsmInfo->nBufferSize)
116+ {
117+ const wchar_t *const begin = static_cast<wchar_t*>(nsmInfo->lpBuffer);
118+ return ConvertString<T>(std::wstring(begin, std::find(begin, begin + NsmInfoStrMaxLength, wchar_t())));
119+ }
120+ break;
121+ }
122+
123+ return std::basic_string<T>();
124+ }
125+
126+ //-----------------------------------------------------------------------------------------------
127+
128+ inline int StrToNsmInfo(TNsmInfo *nsmInfo, const std::string &value)
129+ {
130+ return StringToNsmInfo<NMIT_STRING>(nsmInfo, value);
131+ }
132+
133+ inline int StrToNsmInfo(TNsmInfo *nsmInfo, const std::wstring &value)
134+ {
135+ return StringToNsmInfo<NMIT_WIDESTRING>(nsmInfo, value);
136+ }
137+
138+ inline int IntToNsmInfo(TNsmInfo *nsmInfo, std::int32_t value)
139+ {
140+ return IntegerToNsmInfo<NMIT_INTEGER>(nsmInfo, value);
141+ }
142+
143+ inline int Int64ToNsmInfo(TNsmInfo *nsmInfo, std::int64_t value)
144+ {
145+ return IntegerToNsmInfo<NMIT_INT64>(nsmInfo, value);
146+ }
147+
148+ inline int BoolToNsmInfo(TNsmInfo *nsmInfo, bool value)
149+ {
150+ return IntegerToNsmInfo<NMIT_BOOL>(nsmInfo, value ? 1 : 0);
151+ }
152+
153+ inline std::string NsmInfoToStrA(const TNsmInfo *nsmInfo)
154+ {
155+ return NsmInfoToString<char>(nsmInfo);
156+ }
157+
158+ inline std::wstring NsmInfoToStrW(const TNsmInfo *nsmInfo)
159+ {
160+ return NsmInfoToString<wchar_t>(nsmInfo);
161+ }
162+
163+ inline std::tstring NsmInfoToStr(const TNsmInfo *nsmInfo)
164+ {
165+ return NsmInfoToString<tstring::value_type>(nsmInfo);
166+ }
167+
168+ inline std::int32_t NsmInfoToInt(const TNsmInfo *nsmInfo)
169+ {
170+ return NsmInfoToInteger<NMIT_INTEGER>(nsmInfo);
171+ }
172+
173+ inline std::int64_t NsmInfoToInt64(const TNsmInfo *nsmInfo)
174+ {
175+ return NsmInfoToInteger<NMIT_INT64>(nsmInfo);
176+ }
177+
178+ inline bool NsmInfoToBool(const TNsmInfo *nsmInfo)
179+ {
180+ return NsmInfoToInteger<NMIT_BOOL>(nsmInfo) != 0;
181+ }
33182 }
34183 }
35184 }
--- trunk/Common/StrResource.cpp (revision 114)
+++ trunk/Common/StrResource.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "StrResource.h"
2+
13 #include <cstring>
24 #include <vector>
35
@@ -9,7 +11,6 @@
911 #include "dummy.h"
1012 #include "StrRscCommonConsts.h"
1113 #include "StrRscTypes.h"
12-#include "StrResource.h"
1314
1415 extern HINSTANCE g_hInstance;
1516
@@ -19,12 +20,12 @@
1920 {
2021 namespace StrRsc
2122 {
22- std::auto_ptr<StrResource> g_StrResource;
23+ std::unique_ptr<StrResource> g_StrResource;
2324
2425 StrResource::StrResource(const TNsmPluginInitInfo& initInfo)
25- :PluginName(t2c(GetPluginName())),
26- InitInfo(initInfo),
27- SvcChecked(false)
26+ :PluginName(t2c(GetPluginName()))
27+ ,InitInfo(initInfo)
28+ ,SvcChecked()
2829 {}
2930
3031 std::tstring StrResource::DecodeCrLf(const std::tstring &source)
--- trunk/Common/NsmPluginMain.cpp (revision 114)
+++ trunk/Common/NsmPluginMain.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "NsmPluginMain.h"
2+
13 #include <vector>
24
35 #include <shlwapi.h>
@@ -6,7 +8,6 @@
68 #endif
79
810 #include "dummy.h"
9-#include "NsmPluginMain.h"
1011
1112 extern HINSTANCE g_hInstance;
1213
--- trunk/Common/StrResource.h (revision 114)
+++ trunk/Common/StrResource.h (revision 115)
@@ -35,7 +35,7 @@
3535 std::tstring GetLocalStr(const std::tstring &section, const std::tstring &key, const std::tstring &defStr);
3636 };
3737
38- extern std::auto_ptr<StrResource> g_StrResource;
38+ extern std::unique_ptr<StrResource> g_StrResource;
3939 }
4040 }
4141 }
--- trunk/Common/dummy.cpp (revision 114)
+++ trunk/Common/dummy.cpp (revision 115)
@@ -1,15 +1,12 @@
1-//#include <locale>
2-#include <stdexcept>
3-#include <vector>
4-#include <iomanip>
1+#include "dummy.h"
52
63 #include <cassert>
74 #include <cstdarg>
85 #include <cstdio>
6+#include <stdexcept>
7+#include <vector>
8+#include <iomanip>
99
10-#include "NsmTypes.h"
11-#include "dummy.h"
12-
1310 #if defined(_WINDOWS)
1411 #include <windows.h>
1512 #include <shlwapi.h>
@@ -24,6 +21,9 @@
2421
2522 static iconv_t ic_c2w = 0, ic_w2c = 0;
2623 #endif
24+
25+#include "NsmTypes.h"
26+
2727 #ifdef WINCE
2828 struct tm *__cdecl localtime(const time_t *t)
2929 {
@@ -49,7 +49,7 @@
4949
5050 #endif
5151
52-const std::wstring c2w(const std::string &src)
52+std::wstring c2w(const std::string &src)
5353 {
5454 #ifdef _WINDOWS
5555 int bufSize = MultiByteToWideChar(CP_THREAD_ACP, 0, src.c_str(), -1, NULL, 0);
@@ -72,7 +72,7 @@
7272 #endif
7373 }
7474
75-const std::string w2c(const std::wstring &src)
75+std::string w2c(const std::wstring &src)
7676 {
7777 #ifdef _WINDOWS
7878 int bufSize = WideCharToMultiByte(CP_THREAD_ACP, 0, src.c_str(), -1, NULL, 0, NULL, NULL);
@@ -101,7 +101,7 @@
101101 将来的には消す必要あり
102102 */
103103
104-std::tstring PtrToHex(const void *const value)
104+std::tstring PtrToHex(const void* value)
105105 {
106106 std::tstringstream strm;
107107 strm << std::hex << std::setfill(TEXT('0')) << std::setw(sizeof(void*) * 2) << value;
@@ -108,13 +108,13 @@
108108 return strm.str();
109109 }
110110
111-std::tstring TimeToStr(time_t t){
111+std::tstring TimeToStr(std::time_t t)
112+{
112113 TCHAR buffer[16];
113114 #if defined(_MSC_VER) && !defined(WINCE)
114- //TODO:エラーチェックはとりあえず放置
115115 tm tmp;
116- localtime_s(&tmp,&t);
117- _tcsftime(buffer,ARRAYSIZE(buffer),TEXT("%H:%M:%S"), &tmp);
116+ localtime_s(&tmp, &t);
117+ _tcsftime(buffer, ARRAYSIZE(buffer), TEXT("%H:%M:%S"), &tmp);
118118 #else
119119 _tcsftime(buffer,sizeof(buffer)/sizeof(buffer[0]),TEXT("%H:%M:%S"), localtime(&t));
120120 #endif
--- trunk/nsmsgs/src/APCQueue.cpp (revision 114)
+++ trunk/nsmsgs/src/APCQueue.cpp (revision 115)
@@ -1,6 +1,7 @@
1-#include "UNsmCom.h"
21 #include "APCQueue.h"
32
3+#include "UNsmCom.h"
4+
45 #if defined(WIN32) && !defined(WINCE)
56 namespace Regnessem
67 {
@@ -20,7 +21,7 @@
2021
2122 LONG_PTR ApcQueue::Call(HNsmService serviceHandle, WPARAM wParam, LPARAM lParam)
2223 {
23- CallServiceInfo cSInfo = {0};
24+ CallServiceInfo cSInfo = {};
2425 cSInfo.ServiceHandle = serviceHandle;
2526 cSInfo.wParam = wParam;
2627 cSInfo.lParam = lParam;
--- trunk/nsmsgs/src/nsmsgs.cpp (revision 114)
+++ trunk/nsmsgs/src/nsmsgs.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "nsmsgs.h"
2+
13 #include <algorithm>
24 #if defined(_WINDOWS)
35 #include <windows.h>
@@ -8,7 +10,6 @@
810 #include "../../Common/tstring.h"
911 #include "../../Common/dummy.h"
1012
11-#include "nsmsgs.h"
1213 #include "UFrmNsmMain.h"
1314 #include "UFrmNsmMainDebug.h"
1415 #include "UNsmCom.h"
@@ -114,9 +115,8 @@
114115 #else
115116 g_NsmCom.DebugMode = false;
116117 #endif
118+ std::unique_ptr<NsmMain> FrmNsmMain; //仮置き
117119
118- std::auto_ptr<NsmMain> FrmNsmMain; //仮置き
119-
120120 if (!g_NsmCom.DebugMode)
121121 {
122122 FrmNsmMain.reset(new NsmMain());
--- trunk/nsmsgs/src/UNsmCom.cpp (revision 114)
+++ trunk/nsmsgs/src/UNsmCom.cpp (revision 115)
@@ -1,9 +1,10 @@
1+#include "UNsmCom.h"
2+
13 #include <algorithm>
24
35 #include "../../Common/dummy.h"
46
57 #include "APCQueue.h"
6-#include "UNsmCom.h"
78
89 namespace Regnessem
910 {
@@ -12,11 +13,11 @@
1213 NsmCom g_NsmCom;
1314 // -----------------------------------------------------------------------------
1415 NsmCom::NsmCom()
15- :MainThreadID(GetCurrentThreadId()),
16- DebugMode(false),
17- OnLog(NULL),
18- OnServiceListChange(NULL),
19- OnEventListChange(NULL)
16+ :MainThreadID(GetCurrentThreadId())
17+ ,DebugMode()
18+ ,OnLog()
19+ ,OnServiceListChange()
20+ ,OnEventListChange()
2021 {
2122 DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &MainThreadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
2223 DebugWindow.reset();
@@ -261,17 +262,17 @@
261262
262263 TNsmPluginInitInfo NsmComHelper::GetPluginInitInfo()
263264 {
264- TNsmPluginInitInfo q;
265- q.cbSize = sizeof(TNsmPluginInitInfo);
266- q.CreateNsmService = CreateNsmService;
267- q.GetService = GetService;
268- q.CallService = CallService;
269- q.CreateNsmEvent = CreateNsmEvent;
270- q.GetEvent = GetEvent;
271- q.NotifyEvent = NotifyEvent;
272- q.HookEvent = HookEvent;
273- q.UnhookEvent = UnhookEvent;
274- return q;
265+ TNsmPluginInitInfo info;
266+ info.cbSize = sizeof(info);
267+ info.CreateNsmService = CreateNsmService;
268+ info.GetService = GetService;
269+ info.CallService = CallService;
270+ info.CreateNsmEvent = CreateNsmEvent;
271+ info.GetEvent = GetEvent;
272+ info.NotifyEvent = NotifyEvent;
273+ info.HookEvent = HookEvent;
274+ info.UnhookEvent = UnhookEvent;
275+ return info;
275276 }
276277 }
277278 }
--- trunk/nsmsgs/src/UNsmSystem.cpp (revision 114)
+++ trunk/nsmsgs/src/UNsmSystem.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "UNsmSystem.h"
2+
13 #include <cassert>
24 #include <algorithm>
35
@@ -9,7 +11,6 @@
911 #include "UNsmCom.h"
1012 #include "ModuleUtility.h"
1113 #include "resource.h"
12-#include "UNsmSystem.h"
1314
1415 namespace Regnessem
1516 {
@@ -308,7 +309,7 @@
308309 FILE*fp = popen(("dir "+path).c_str(),"r");
309310 char buf[256];
310311 while(fscanf(fp,"%255s",buf)==1){
311- std::auto_ptr<TNsmPlugin> t(buf));
312+ std::unique_ptr<TNsmPlugin> t(buf));
312313
313314 if(t->DllHandle != NULL &&
314315 t->PluginInfo.ApiVersion == NSM_API_VERSION &&
--- trunk/nsmsgs/src/UFrmNsmMain.cpp (revision 114)
+++ trunk/nsmsgs/src/UFrmNsmMain.cpp (revision 115)
@@ -1,4 +1,4 @@
1-/* NSM SYSTEM メインウィンドウ */
1+#include "UFrmNsmMain.h"
22
33 #include <algorithm>
44
@@ -13,7 +13,6 @@
1313
1414 #include "nsmsgs.h"
1515 #include "UNsmSystem.h"
16-#include "UFrmNsmMain.h"
1716
1817 #define RS_ERROR_NOUIMODULE TEXT("UI モジュールが見つかりませんでした。\nPlugins フォルダ内に UI モジュールが存在するか確認してください。")
1918
--- trunk/nsmsgs/src/UNsmPlugin.cpp (revision 114)
+++ trunk/nsmsgs/src/UNsmPlugin.cpp (revision 115)
@@ -1,3 +1,5 @@
1+#include "UNsmPlugin.h"
2+
13 #if !defined(_WINDOWS)
24 #include <iostream>
35 #endif
@@ -5,7 +7,6 @@
57 #include "../../Common/UNsmConsts.h"
68 #include "../../Common/dummy.h"
79
8-#include "UNsmPlugin.h"
910 #include "DllUtils.h"
1011
1112 namespace Regnessem
--- trunk/nsmsgs/src/UNsmConnection.cpp (revision 114)
+++ trunk/nsmsgs/src/UNsmConnection.cpp (revision 115)
@@ -1,9 +1,8 @@
1+#include "UNsmConnection.h"
12
23 #include "../../Common/dummy.h"
34 #include "../../Common/UNsmConsts.h"
45
5-#include "UNsmConnection.h"
6-
76 namespace Regnessem
87 {
98 namespace System
--- trunk/nsmsgs/src/UFrmNsmMainDebug.cpp (revision 114)
+++ trunk/nsmsgs/src/UFrmNsmMainDebug.cpp (revision 115)
@@ -2,6 +2,8 @@
22 #pragma comment(lib, "comctl32.lib")
33 #endif
44
5+#include "UFrmNsmMainDebug.h"
6+
57 #include <ctime>
68 #include <windowsx.h>
79 #include <windows.h>
@@ -14,7 +16,6 @@
1416 #include "UNsmSystem.h"
1517 #include "resource.h"
1618 #include "nsmsgs.h"
17-#include "UFrmNsmMainDebug.h"
1819
1920 namespace Regnessem
2021 {
--- trunk/nsmsgs/src/UNsmMemberList.cpp (revision 114)
+++ trunk/nsmsgs/src/UNsmMemberList.cpp (revision 115)
@@ -2,11 +2,11 @@
22 // MSN7 表示メッセージ対応済み
33 // MSN7 表示アイコン仮対応
44
5+#include "UNsmMemberList.h"
6+
57 #include "../../Common/UNsmConsts.h"
68 #include "../../Common/dummy.h"
79
8-#include "UNsmMemberList.h"
9-
1010 namespace Regnessem
1111 {
1212 namespace System
--- trunk/nsmsgs/src/ModuleUtility.cpp (revision 114)
+++ trunk/nsmsgs/src/ModuleUtility.cpp (revision 115)
@@ -8,19 +8,19 @@
88
99 std::tstring ModuleUtility::ExtractModuleType(const std::tstring &moduleName)
1010 {
11- return moduleName.substr(0,moduleName.find(Delimiter));
11+ return moduleName.substr(0, moduleName.find(Delimiter));
1212 }
1313
1414 std::tstring ModuleUtility::ExtractProtocolName(const std::tstring &moduleName)
1515 {
1616 std::tstring::size_type p = moduleName.find(Delimiter);
17- return moduleName.substr(p==moduleName.npos ? p : ++p);
17+ return moduleName.substr(p == moduleName.npos ? p : ++p);
1818 }
1919
2020 std::tstring ModuleUtility::ExtractAddInName(const std::tstring &moduleName)
2121 {
2222 std::tstring::size_type p = moduleName.find(Delimiter);
23- return moduleName.substr(p==moduleName.npos ? p : ++p);
23+ return moduleName.substr(p == moduleName.npos ? p : ++p);
2424 }
2525 }
2626 }
--- trunk/nsmsgs/src/UNsmCom.h (revision 114)
+++ trunk/nsmsgs/src/UNsmCom.h (revision 115)
@@ -30,7 +30,7 @@
3030
3131 //----
3232
33- std::auto_ptr<NsmMainDebug> DebugWindow;
33+ std::unique_ptr<NsmMainDebug> DebugWindow;
3434
3535 //----
3636
--- trunk/MSNP10/src/Connection.h (revision 114)
+++ trunk/MSNP10/src/Connection.h (revision 115)
@@ -28,7 +28,7 @@
2828 typedef Common::DelphiCompatible::NotifyEvent NotifyEvent;
2929 typedef std::vector<std::string> CommandParam;
3030
31- std::auto_ptr<AddIn::ClientSocket::ClientSocketUtil> Socket;
31+ std::unique_ptr<AddIn::ClientSocket::ClientSocketUtil> Socket;
3232 int MembersCount;
3333 int ListCount;
3434 int GroupsCount;
@@ -46,7 +46,7 @@
4646 Common::DelphiCompatible::TTimer PingTimer;
4747
4848 // パスワード情報取得用のスレッド
49- std::auto_ptr<MsnAuthThread> AuthThread;
49+ std::unique_ptr<MsnAuthThread> AuthThread;
5050
5151 // アカウント毎の情報
5252 std::string SYNString1;
--- trunk/MSNP10/src/MSNP10.h (revision 114)
+++ trunk/MSNP10/src/MSNP10.h (revision 115)
@@ -29,7 +29,7 @@
2929 MsnThreadFileSessionList m_FileSessions;
3030 TSimpleTimer *m_TypingTimer;
3131
32- std::auto_ptr<Common::NsmInfoUtility::NsmGetSetInfo> GetSetInfo;
32+ std::unique_ptr<Common::NsmInfoUtility::NsmGetSetInfo> GetSetInfo;
3333
3434 HNsmEvent HComLogEvent; //TODO: rename
3535 std::vector<std::tstring> m_HandWriteList;
--- trunk/MSNP10/src/Session.h (revision 114)
+++ trunk/MSNP10/src/Session.h (revision 115)
@@ -26,7 +26,7 @@
2626 typedef Common::DelphiCompatible::NotifyEvent NotifyEvent;
2727
2828 // プロパティフィールド
29- std::auto_ptr<AddIn::ClientSocket::ClientSocketUtil> Socket;
29+ std::unique_ptr<AddIn::ClientSocket::ClientSocketUtil> Socket;
3030 std::string Host;
3131 unsigned short Port;
3232 MsnMemberList Members;
Show on old repository browser