VR-Link API Documentation for HLA 1.3
Home
Namespaces
Classes
Files
Examples
Libraries
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
include
vlutil
vlPrint.h
Go to the documentation of this file.
1
/****************************************************************************
2
* Copyright (c) 2015 VT MAK
3
* All rights reserved.
4
****************************************************************************/
5
9
10
#pragma once
11
12
#include <
vlutil/vlMachineTypes.h
>
13
#include <
vlutil/vlMutex.h
>
14
#include <iostream>
15
#include <fstream>
16
#include <vector>
17
#include <ios>
18
19
#ifdef _WIN32
20
#include <winsock2.h>
21
#endif
22
23
24
#ifdef DtUSE_UTILITIES_NAMESPACE
25
namespace
DtUSE_UTILITIES_NAMESPACE
26
{
27
#endif
28
29
35
extern
DT_DLL_VLUTIL
int
DtNotifyLevel
;
36
37
39
enum
DtNotifyLevelType
40
{
41
DtNlFatal
= 0,
42
DtNlWarn
= 1,
43
DtNlInfo
= 2,
44
DtNlVerbose
= 3,
45
DtNlDebug
= 4
46
};
47
48
55
class
DT_DLL_VLUTIL
DtPrinter
56
{
57
public
:
58
60
inline
DtPrinter
();
61
63
inline
DtPrinter
(
const
DtPrinter
& );
64
66
virtual
inline
~
DtPrinter
();
67
71
virtual
void
write(
const
std::string& str,
int
notify_level,
bool
newLine ) = 0;
72
73
};
74
75
80
class
DT_DLL_VLUTIL
DtFilePrinter
:
public
DtPrinter
81
{
82
public
:
83
86
DtFilePrinter
();
87
90
DtFilePrinter
(
const
char
* filename );
91
94
virtual
~
DtFilePrinter
();
95
97
virtual
void
setPrintTimestamps(
bool
doit );
98
102
virtual
void
setLogRollingInterval(
unsigned
int
intervalInSeconds );
103
106
virtual
void
resetFile(
const
char
* filename );
107
109
virtual
bool
isOpen();
110
113
virtual
void
write(
const
std::string& st,
int
notify_level,
bool
newLine );
114
115
protected
:
116
118
virtual
void
cacheFilename(
const
std::string& filename );
119
120
private
:
121
123
DtFilePrinter
(
const
DtFilePrinter
& orig );
124
126
DtFilePrinter
& operator = (
const
DtFilePrinter
& orig );
127
128
protected
:
129
130
DtMutex
myFileLock
;
131
132
bool
myTimestampFlag
;
133
134
time_t
myLogFileOpenTime
;
135
unsigned
int
myLogRollingIndex
;
136
unsigned
int
myLogRollingInterval
;
137
138
std::string
myFilename
;
139
std::string
myFileBase
;
140
std::string
myFileExt
;
141
142
#ifndef __sgi__
143
std::ofstream
myFile
;
144
#else
145
std::fstream myFile;
146
#endif
147
148
};
149
150
154
class
DT_DLL_VLUTIL
DtStdoutPrinter
:
public
DtPrinter
155
{
156
public
:
157
159
inline
DtStdoutPrinter
();
160
162
virtual
inline
~
DtStdoutPrinter
();
163
165
virtual
void
write(
const
std::string& st,
int
notify_level,
bool
newLine );
166
167
protected
:
168
169
DtMutex
myLock
;
170
171
};
172
173
177
class
DT_DLL_VLUTIL
DtStderrPrinter
:
public
DtPrinter
178
{
179
public
:
180
182
inline
DtStderrPrinter
();
183
185
virtual
inline
~
DtStderrPrinter
();
186
188
virtual
void
write(
const
std::string& st,
int
notify_level,
bool
newLine );
189
190
protected
:
191
192
DtMutex
myLock
;
193
194
};
195
196
197
#ifdef _WIN32
198
202
class
DT_DLL_VLUTIL
DtWindowsConsolePrinter :
public
DtPrinter
203
{
204
public
:
205
207
DtWindowsConsolePrinter(
bool
disableClose =
false
);
208
210
virtual
~DtWindowsConsolePrinter();
211
213
virtual
void
write(
const
std::string& st,
int
notify_level,
bool
newLine );
214
215
protected
:
216
217
HANDLE myConsoleHandle;
218
DtMutex
myLock;
219
220
};
221
222
#endif
223
224
226
class
DtOutputStream
;
227
231
class
DT_DLL_VLUTIL
DtOutputStreamBuffer
:
public
std::basic_streambuf<char>
232
{
233
public
:
234
236
DtOutputStreamBuffer
();
237
239
virtual
~
DtOutputStreamBuffer
();
240
241
virtual
void
setOutputStream(
DtOutputStream
* stream );
242
243
protected
:
244
245
virtual
int
sync();
246
virtual
int_type overflow( int_type c );
247
248
private
:
249
251
DtOutputStreamBuffer
(
const
DtOutputStreamBuffer
& );
252
254
DtOutputStreamBuffer
& operator = (
const
DtOutputStreamBuffer
& );
255
256
protected
:
257
258
std::string
myBuffer
;
259
DtMutex
myBufferMutex
;
260
DtOutputStream
*
myOutputStream
;
261
262
};
263
264
282
class
DT_DLL_VLUTIL
DtOutputStream
:
public
std::basic_ostream<char>
283
{
284
public
:
285
290
DtOutputStream
(
DtOutputStreamBuffer
* buffer,
int
& globalThresholdRef,
291
int
threshold = 1,
DtPrinter
* dflt_printer = 0 );
292
294
virtual
~
DtOutputStream
();
295
297
virtual
void
attachPrinter(
DtPrinter
* sink );
298
301
virtual
bool
detachPrinter(
DtPrinter
* sink );
302
305
virtual
void
detachAllPrinters();
306
310
virtual
void
write(
const
std::string& str,
bool
newLine =
false
);
311
314
virtual
void
setThreshold(
int
level );
315
318
virtual
int
threshold()
const
;
319
323
virtual
bool
okToPrint()
const
;
324
326
virtual
void
operator () (
const
char
* s, ... );
327
328
329
private
:
330
332
DtOutputStream
(
const
DtOutputStream
& );
333
335
DtOutputStream
& operator = (
const
DtOutputStream
& );
336
337
protected
:
338
339
typedef
std::vector<DtPrinter*>
PrinterPtrVec
;
340
341
DtOutputStreamBuffer
*
myStreamBuf
;
342
DtMutex
myStreamBufMutex
;
343
PrinterPtrVec
myPrinters
;
344
DtMutex
myPrintersMutex
;
345
int
myThreshold
;
346
348
int
&
myGlobalThresholdReference
;
349
350
};
351
352
362
extern
DT_DLL_VLUTIL
DtStdoutPrinter
DtStandardOutConsole
;
363
373
extern
DT_DLL_VLUTIL
DtStderrPrinter
DtStandardErrorConsole
;
374
375
382
383
extern
DT_DLL_VLUTIL
DtOutputStream
DtFatal
;
384
extern
DT_DLL_VLUTIL
DtOutputStream
DtWarn
;
389
extern
DT_DLL_VLUTIL
DtOutputStream
DtInfo
;
390
extern
DT_DLL_VLUTIL
DtOutputStream
DtVerbose
;
391
extern
DT_DLL_VLUTIL
DtOutputStream
DtDebug
;
393
394
403
404
extern
DT_DLL_VLUTIL
void
DtFatalError
(
const
char
* str, ... );
405
extern
DT_DLL_VLUTIL
void
DtFatalPerror
(
const
char
* str, ... );
406
extern
DT_DLL_VLUTIL
void
DtWarnPerror
(
const
char
* str, ... );
407
extern
DT_DLL_VLUTIL
void
DtFatalNetPerror
(
const
char
* str, ... );
408
extern
DT_DLL_VLUTIL
void
DtWarnNetPerror
(
const
char
* str, ... );
410
411
417
DT_DLL_VLUTIL
void
DtSetVrLinkPrinter
(
DtPrinter
* newPrinter );
418
419
422
DT_DLL_VLUTIL
void
DtPrintEnvironmentVariables
(
DtOutputStream
& os =
DtInfo
);
423
424
#ifdef _WIN32
425
433
434
DT_DLL_VLUTIL
void
setFileOutput(
const
char
* filename,
int
con = 0,
int
son = 0 );
435
DT_DLL_VLUTIL
void
closeConsole();
437
438
#endif
439
440
445
DT_DLL_VLUTIL
void
DtAbort
();
446
448
typedef
void (*
DtAbortFunc
)();
449
451
DT_DLL_VLUTIL
void
DtSetAbortFunc
(
DtAbortFunc
func );
452
454
DT_DLL_VLUTIL
DtAbortFunc
DtGetAbortFunc
();
455
456
#if DT_NO_VSNPRINTF
457
458
DT_DLL_VLUTIL
int
vsnprintf(
char
*,
size_t
,
const
char
*, va_list );
459
#endif
460
461
//-------------------------------------------
462
//Inline Function Definitions
463
//-----------------------------------------
464
inline
void
DtOutputStream::setThreshold
(
int
level )
465
{
466
myThreshold = level;
467
}
468
469
inline
int
DtOutputStream::threshold
()
const
470
{
471
return
myThreshold;
472
}
473
474
inline
DtPrinter::DtPrinter
()
475
{
476
}
477
478
inline
DtPrinter::DtPrinter
(
const
DtPrinter
& )
479
{
480
}
481
482
inline
DtPrinter::~DtPrinter
()
483
{
484
}
485
486
inline
DtStdoutPrinter::DtStdoutPrinter
()
487
{
488
}
489
490
inline
DtStdoutPrinter::~DtStdoutPrinter
()
491
{
492
}
493
494
inline
DtStderrPrinter::DtStderrPrinter
()
495
{
496
}
497
498
inline
DtStderrPrinter::~DtStderrPrinter
()
499
{
500
}
501
502
503
#ifdef DtUSE_UTILITIES_NAMESPACE
504
}
505
#endif
Document ID: Generated on Mon Jun 22 21:18:40 EDT 2020 from SVN revision 213785
Copyright © 2005-2018 MAK Technologies. All Rights Reserved (
www.mak.com
)