source: gsdl/trunk/packages/isis-gdl/Debug.cpp@ 14171

Last change on this file since 14171 was 7139, checked in by mdewsnip, 20 years ago

Added these files back in -- necessary for compiling with Visual C++.

  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1#include "stdafx.h"
2#include "Debug.h"
3
4//---------------------------------------------------------------
5//
6// AssertFailed
7//
8//---------------------------------------------------------------
9#if DEBUG || ASSERTS_THROW
10void AssertFailed(const char* expr, const char* file, int line)
11{
12 /*
13 _TCHAR mesg[512];
14
15 const char* fileName = file + strlen(file); // strip off path
16 while (fileName > file && fileName[-1] != '\\')
17 --fileName;
18
19 _stprintf(mesg, _T("ASSERT(%s) in '%s' at line %d failed."), expr, fileName, line);
20
21 MSG msg; // remove pending quit messages so the message box displays
22 bool quitting = (bool) ::PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
23
24 UINT32 flags = MB_OK + // just an OK button
25 MB_ICONERROR + // display the icon for errors
26 MB_DEFBUTTON1 + // select the OK button
27 MB_TASKMODAL + // don't let the user do anything else in the app
28 MB_SETFOREGROUND; // bring the app to the front
29
30 (void) MessageBox(NULL, mesg, NULL, flags);
31//#if DEBUG
32// if (gBreakOnAssert)
33// BreakStrToDebugger(mesg);
34//#endif
35
36//#if ASSERTS_THROW
37 CString text = L"Internal (Assert) Error: ";
38 AfxThrowUserException( );
39//#endif
40*/
41}
42#endif // DEBUG || ASSERTS_THROW
43
44
45//---------------------------------------------------------------
46//
47// RequireFailed
48//
49//---------------------------------------------------------------
50#if !DEBUG
51void RequireFailed(const char* expr, const char* file, int line)
52{
53 /*
54 char mesg[512];
55
56 const char* fileName = file + strlen(file); // strip off path
57 while (fileName > file && fileName[-1] != '\\')
58 --fileName;
59
60 sprintf(mesg, "There has been a fatal error in '%s' at line %d.", fileName, line);
61
62 MSG msg; // remove pending quit messages so the message box displays
63 bool quitting = (bool) ::PeekMessage(&msg, NULL, WM_QUIT, WM_QUIT, PM_REMOVE);
64
65 UINT32 flags = MB_OK + // just an OK button
66 MB_ICONERROR + // display the icon for errors
67 MB_DEFBUTTON1 + // select the OK button
68 MB_TASKMODAL + // don't let the user do anything else in the app
69 MB_SETFOREGROUND; // bring the app to the front
70
71 (void) MessageBox(NULL, mesg, NULL, flags);
72
73 abort();
74 */
75}
76#endif // !DEBUG
77
78//---------------------------------------------------------------
79//
80// ToStr (bool)
81//
82//---------------------------------------------------------------
83std::wstring ToStr(bool value)
84{
85 return value ? L"true" : L"false";
86}
87
88
89//---------------------------------------------------------------
90//
91// ToStr (char)
92//
93//---------------------------------------------------------------
94std::wstring ToStr(char value)
95{
96 wchar_t str[32];
97 ::swprintf(str, L"%c", value);
98
99 return str;
100}
101
102
103//---------------------------------------------------------------
104//
105// ToStr (int16, int32)
106//
107//---------------------------------------------------------------
108std::wstring ToStr(int16_t value, int32_t fieldWidth)
109{
110 wchar_t str[32];
111 ::swprintf(str, L"%*d", fieldWidth, value);
112
113 return str;
114}
115
116
117//---------------------------------------------------------------
118//
119// ToStr (uint16, int32)
120//
121//---------------------------------------------------------------
122std::wstring ToStr(uint16_t value, int32_t fieldWidth)
123{
124 wchar_t str[32];
125 ::swprintf(str, L"%*d", fieldWidth, value);
126
127 return str;
128}
129
130
131//---------------------------------------------------------------
132//
133// ToStr (int32, int32)
134//
135//---------------------------------------------------------------
136std::wstring ToStr(int32_t value, int32_t fieldWidth)
137{
138 wchar_t str[32];
139 ::swprintf(str, L"%*ld", fieldWidth, value);
140
141 return str;
142}
143
144
145//---------------------------------------------------------------
146//
147// ToStr (uint32, int32)
148//
149//---------------------------------------------------------------
150std::wstring ToStr(uint32_t value, int32_t fieldWidth)
151{
152 wchar_t str[32];
153 ::swprintf(str, L"%*lu", fieldWidth, value);
154
155 return str;
156}
157
158
159//---------------------------------------------------------------
160//
161// ToStr (float, int32)
162//
163//---------------------------------------------------------------
164std::wstring ToStr(float value, int32_t precision)
165{
166 wchar_t str[32];
167 ::swprintf(str, L"%.*f", precision, value);
168
169 return str;
170}
171
172
173//---------------------------------------------------------------
174//
175// ToStr (double, int32)
176//
177//---------------------------------------------------------------
178std::wstring ToStr(double_t value, int32_t precision)
179{
180 wchar_t str[32];
181 ::swprintf(str, L"%.*f", precision, value);
182
183 return str;
184}
185
186
187//---------------------------------------------------------------
188//
189// ToStr (const char*)
190//
191//---------------------------------------------------------------
192std::wstring ToStr(const char* value)
193{
194 wchar_t str[2048];
195 ::swprintf(str, L"%s", value);
196
197 return str;
198}
199
200
201//---------------------------------------------------------------
202//
203// ToStr (std::string)
204//
205//---------------------------------------------------------------
206std::wstring ToStr(const std::string& value)
207{
208 wchar_t str[2048];
209 ::swprintf(str, L"%s", value.c_str());
210
211 return str;
212}
213
Note: See TracBrowser for help on using the repository browser.