CFugue
WinStrUtils.h
1 #ifndef __WINSTRUTILS_H__64B78566_C82A_438c_BA3E_50C763964D7B__
2 #define __WINSTRUTILS_H__64B78566_C82A_438c_BA3E_50C763964D7B__
3 
4 #include "StrUtils.h"
5 
6 //////////////////////////////////////////////////////////////////////////
7 /// WinStrUtils.h is a specialization of Strutils.h for Windows datatypes
8 ///
9 
10 namespace OIL
11 {
12 #ifdef _INC_COMUTIL // if included Comutil.h
13  //template<>
14  //inline StrUtils_Return_Type ToString(const variant_t& varVal)
15  //{
16  // return varVal;
17  //}
18 #endif // _INC_COMUTIL
19 
20 #ifdef GUID_DEFINED // if included GuidDef.h
21  template<>
22  inline StrUtils_Return_Type ToString(const GUID& guid)
23  {
24 #pragma warning(push)
25 #pragma warning(disable:4244) // Disable the nasty "LPVOID to Unsigned long" conversion warning
26  StrUtils_Return_Type strData1 = UnSignedNumber2Str(guid.Data1, sizeof(guid.Data1) * 2, DEFAULT_FILLER, 16, false);
27  StrUtils_Return_Type strData2 = UnSignedNumber2Str(guid.Data2, sizeof(guid.Data2) * 2, DEFAULT_FILLER, 16, false);
28  StrUtils_Return_Type strData3 = UnSignedNumber2Str(guid.Data3, sizeof(guid.Data3) * 2, DEFAULT_FILLER, 16, false);
29  StrUtils_Return_Type strData40 = UnSignedNumber2Str((unsigned int)(guid.Data4[0]), 2, DEFAULT_FILLER, 16, false);
30  StrUtils_Return_Type strData41 = UnSignedNumber2Str((unsigned int)(guid.Data4[1]), 2, DEFAULT_FILLER, 16, false);
31  StrUtils_Return_Type strData42 = UnSignedNumber2Str((unsigned int)(guid.Data4[2]), 2, DEFAULT_FILLER, 16, false);
32  StrUtils_Return_Type strData43 = UnSignedNumber2Str((unsigned int)(guid.Data4[3]), 2, DEFAULT_FILLER, 16, false);
33  StrUtils_Return_Type strData44 = UnSignedNumber2Str((unsigned int)(guid.Data4[4]), 2, DEFAULT_FILLER, 16, false);
34  StrUtils_Return_Type strData45 = UnSignedNumber2Str((unsigned int)(guid.Data4[5]), 2, DEFAULT_FILLER, 16, false);
35  StrUtils_Return_Type strData46 = UnSignedNumber2Str((unsigned int)(guid.Data4[6]), 2, DEFAULT_FILLER, 16, false);
36  StrUtils_Return_Type strData47 = UnSignedNumber2Str((unsigned int)(guid.Data4[7]), 2, DEFAULT_FILLER, 16, false);
37  return strData1 + _T("-") + strData2 + _T("-") + strData3 + _T("-") +
38  strData40 + strData41 + _T("-") + strData42 + strData43 + strData44 + strData45 + strData46 + strData47;
39 #pragma warning(pop)
40  }
41 #endif // GUID_DEFINED
42 
43 
44  #ifdef _OBJBASE_H_ // if included ObjBase.h
45  template<>
46  inline StrUtils_Return_Type ToString(const COMSD& comsd)
47  {
48  const TCHAR* strComSD[] = { _T("SD_LAUNCHPERMISSIONS"), _T("SD_ACCESSPERMISSIONS"), _T("SD_LAUNCHRESTRICTIONS"), _T("SD_ACCESSRESTRICTIONS")};
49  return strComSD[comsd];
50  }
51 #endif // _OBJBASE_H_
52 
53 #ifdef WINVER // if included Windows.h
54 
55 #define DECLARE_HANDLE_TYPE_TO_STRING(name) \
56  template<>\
57  inline StrUtils_Return_Type ToString(const name& _obj)\
58  { \
59  return ToString((void*)_obj); \
60  }
61 
62  DECLARE_HANDLE_TYPE_TO_STRING(HBITMAP)
63  DECLARE_HANDLE_TYPE_TO_STRING(HBRUSH)
64  DECLARE_HANDLE_TYPE_TO_STRING(HCOLORSPACE)
65  DECLARE_HANDLE_TYPE_TO_STRING(HDESK)
66  DECLARE_HANDLE_TYPE_TO_STRING(HENHMETAFILE)
67 #ifdef WINABLE
68  DECLARE_HANDLE_TYPE_TO_STRING(HEVENT)
69 #endif
70  DECLARE_HANDLE_TYPE_TO_STRING(HFONT)
71  DECLARE_HANDLE_TYPE_TO_STRING(HGLRC)
72  DECLARE_HANDLE_TYPE_TO_STRING(HHOOK)
73  DECLARE_HANDLE_TYPE_TO_STRING(HICON)
74  DECLARE_HANDLE_TYPE_TO_STRING(HINSTANCE)
75  DECLARE_HANDLE_TYPE_TO_STRING(HKL)
76  DECLARE_HANDLE_TYPE_TO_STRING(HKEY)
77  DECLARE_HANDLE_TYPE_TO_STRING(HMENU)
78  DECLARE_HANDLE_TYPE_TO_STRING(HMETAFILE)
79  DECLARE_HANDLE_TYPE_TO_STRING(HMONITOR)
80  DECLARE_HANDLE_TYPE_TO_STRING(HRGN)
81  DECLARE_HANDLE_TYPE_TO_STRING(HRSRC)
82  DECLARE_HANDLE_TYPE_TO_STRING(HSPRITE)
83  DECLARE_HANDLE_TYPE_TO_STRING(HSTR)
84  DECLARE_HANDLE_TYPE_TO_STRING(HTASK)
85  DECLARE_HANDLE_TYPE_TO_STRING(HUMPD)
86  DECLARE_HANDLE_TYPE_TO_STRING(HWINSTA)
87  DECLARE_HANDLE_TYPE_TO_STRING(HWND)
88 
89  template<>
90  inline StrUtils_Return_Type ToString<FARPROC>(const FARPROC& fProc)
91  {
92  return ToString((void*)fProc);
93  }
94 
95  //template<>
96  //inline StrUtils_Return_Type ToString(const HINSTANCE& hInstance)
97  //{
98  // return ToString((void*)hInstance);
99  //}
100 
101  //template<>
102  //inline StrUtils_Return_Type ToString(const HWND& hWnd)
103  //{
104  // return ToString((void*)hWnd);
105  //}
106  //#if defined __GNUC__
107  //#if __WORDSIZE == 64
108  //#define __int64 long long
109  //#define __uint64 unsigned long long
110  //#else // wordsize is 32
111  //#include <inttypes.h>
112  //#define __int64 int64_t
113  //#define __uint64 uint64_t
114  //#endif //wordsize
115  //#elif defined _MSC_VER
116  //#define __uint64 unsigned __int64
117  //#else // some unknown compiler
118  //#define __int64 long long
119  //#define __uint64 unsigned long long
120  //#endif // if defined __GNUC__
121 
122  template<>
123  inline StrUtils_Return_Type ToString(const __int64& nNumber)
124  {
125  return SignedNumber2Str(nNumber);
126  }
127 
128  template<>
129  inline StrUtils_Return_Type ToString(const LARGE_INTEGER& liNumber)
130  {
131  return ToString(liNumber.QuadPart);
132  }
133 
134  template<>
135  inline StrUtils_Return_Type ToString(const POINT& Point)
136  {
137  return StrUtils_Return_Type(_T("{")) + ToString(Point.x) + _T(",") + ToString(Point.y) + _T("}");
138  }
139 
140  template<>
141  inline StrUtils_Return_Type ToString(const RECT& rect)
142  {
143  return StrUtils_Return_Type(_T("{")) + ToString(rect.left) + _T(",") + ToString(rect.top) + _T(",") + ToString(rect.right) + _T(",") + ToString(rect.bottom) + _T("}");;
144  }
145 
146  template<>
147  inline StrUtils_Return_Type ToString(const SIZE& Size)
148  {
149  return StrUtils_Return_Type(_T("{")) + ToString(Size.cx) + _T(",") + ToString(Size.cy) + _T("}");
150  }
151 
152 
153  template<>
154  inline StrUtils_Return_Type ToString(const ULARGE_INTEGER& uliNumber)
155  {
156  return ToString(uliNumber.QuadPart);
157  }
158 #endif // ifdef WINVER
159 
160 #ifdef DIRECT3D_VERSION // if included DirectX headers
161  template<>
162  inline StrUtils_Return_Type ToString(const D3DXVECTOR3& Vec)
163  {
164  return StrUtils_Return_Type(_T("{")) + ToString(Vec.x) + _T(",") + ToString(Vec.y) + _T(",") + ToString(Vec.z) + _T("}");
165  }
166 #endif // ifdef DIRECT3D_VERSION
167 } // namespace OIL
168 #endif // __WINSTRUTILS_H__64B78566_C82A_438c_BA3E_50C763964D7B__

CFugue, the C++ Music Programming Library © Copyright 2009 Cenacle Research India Private Limited Gopalakrishna Palem