VR-Link API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vlPrint.h
Go to the documentation of this file.
1 /****************************************************************************
2  * Copyright (c) 1992-2026 MAK Technologies, Inc
3  * All rights reserved.
4  ****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vlutil/vlMachineTypes.h>
13 #include <vlutil/vlMutex.h>
14 #include <vlutil/vlString.h>
15 #include <iostream>
16 #include <fstream>
17 #include <vector>
18 #include <ios>
19 
20 
21 #ifdef _WIN32
22 #include <winsock2.h>
23 #endif
24 
25 
26 #ifdef DtUSE_UTILITIES_NAMESPACE
27 namespace DtUSE_UTILITIES_NAMESPACE
28 {
29 #endif
30 
31 
37 extern DT_DLL_VLUTIL int DtNotifyLevel;
38 
39 
42 {
43  DtNlFatal = 0,
44  DtNlWarn = 1,
45  DtNlInfo = 2,
48 };
49 
50 
58 {
59 public:
60 
62  inline DtPrinter();
63 
65  inline DtPrinter( const DtPrinter& );
66 
68  virtual inline ~DtPrinter();
69 
73  virtual void write( const std::string& str, int notify_level, bool newLine ) = 0;
74 
75 };
76 
77 
83 {
84 public:
85 
88  DtFilePrinter();
89 
92  DtFilePrinter( const char* filename );
93 
96  virtual ~DtFilePrinter();
97 
99  virtual void setPrintTimestamps( bool doit );
100 
104  virtual void setLogRollingInterval( unsigned int intervalInSeconds );
105 
108  virtual void resetFile( const char* filename );
109 
111  virtual bool isOpen();
112 
115  virtual void write( const std::string& st, int notify_level, bool newLine );
116 
117 protected:
118 
120  virtual void cacheFilename( const std::string& filename );
121 
122 private:
123 
125  DtFilePrinter( const DtFilePrinter& orig );
126 
128  DtFilePrinter& operator = ( const DtFilePrinter& orig );
129 
130 protected:
131 
133 
135 
137  unsigned int myLogRollingIndex;
138  unsigned int myLogRollingInterval;
139 
140  std::string myFilename;
141  std::string myFileBase;
142  std::string myFileExt;
143 
144 #ifndef __sgi__
145  std::ofstream myFile;
146 #else
147  std::fstream myFile;
148 #endif
149 
150 };
151 
152 
157 {
158 public:
159 
161  inline DtStdoutPrinter();
162 
164  virtual inline ~DtStdoutPrinter();
165 
167  virtual void write( const std::string& st, int notify_level, bool newLine );
168 
169 protected:
170 
172 
173 };
174 
175 
180 {
181 public:
182 
184  inline DtStderrPrinter();
185 
187  virtual inline ~DtStderrPrinter();
188 
190  virtual void write( const std::string& st, int notify_level, bool newLine );
191 
192 protected:
193 
195 
196 };
197 
198 
199 #ifdef _WIN32
200 
204 class DT_DLL_VLUTIL DtWindowsConsolePrinter : public DtPrinter
205 {
206 public:
207 
209  DtWindowsConsolePrinter( bool disableClose = false );
210 
212  virtual ~DtWindowsConsolePrinter();
213 
215  virtual void write( const std::string& st, int notify_level, bool newLine );
216 
217 protected:
218 
219  HANDLE myConsoleHandle;
220  DtMutex myLock;
221 
222 };
223 
224 #endif
225 
226 
228 class DtOutputStream;
229 
233 class DT_DLL_VLUTIL DtOutputStreamBuffer : public std::basic_streambuf<char>
234 {
235 public:
236 
239 
241  virtual ~DtOutputStreamBuffer();
242 
243  virtual void setOutputStream( DtOutputStream* stream );
244 
245 protected:
246 
247  virtual int sync();
248  virtual int_type overflow( int_type c );
249 
250 private:
251 
254 
256  DtOutputStreamBuffer& operator = ( const DtOutputStreamBuffer& );
257 
258 protected:
259 
260  std::string myBuffer;
263 
264 };
265 
266 
284 class DT_DLL_VLUTIL DtOutputStream : public std::basic_ostream<char>
285 {
286 public:
287 
292  DtOutputStream( DtOutputStreamBuffer* buffer, int& globalThresholdRef,
293  int threshold = 1, DtPrinter* dflt_printer = 0 );
294 
296  virtual ~DtOutputStream();
297 
299  virtual void attachPrinter( DtPrinter* sink );
300 
303  virtual bool detachPrinter( DtPrinter* sink );
304 
307  virtual void detachAllPrinters();
308 
312  virtual void write( const std::string& str, bool newLine = false );
313 
316  virtual void setThreshold( int level );
317 
320  virtual int threshold() const;
321 
325  virtual bool okToPrint() const;
326 
328  virtual void operator () ( const char* s, ... );
329 
330 
331 private:
332 
334  DtOutputStream( const DtOutputStream& );
335 
337  DtOutputStream& operator = ( const DtOutputStream& );
338 
339 protected:
340 
341  typedef std::vector<DtPrinter*> PrinterPtrVec;
342 
348 
351 
352 };
353 
354 
365 
376 
377 
384 
395 
404 
405 extern DT_DLL_VLUTIL void DtFatalError( const char* str, ... );
406 extern DT_DLL_VLUTIL void DtFatalPerror( const char* str, ... );
407 extern DT_DLL_VLUTIL void DtWarnPerror( const char* str, ... );
408 extern DT_DLL_VLUTIL void DtFatalNetPerror( const char* str, ... );
409 extern DT_DLL_VLUTIL void DtWarnNetPerror( const char* str, ... );
411 
419 
420 extern DT_DLL_VLUTIL DtString DtFormatPrintString( const DtOutputStream& os, const char* fmt, ... );
421 extern DT_DLL_VLUTIL DtString DtFormatPrintString( const DtOutputStream& os, const DtString& str );
423 
429 DT_DLL_VLUTIL void DtSetVrLinkPrinter( DtPrinter* newPrinter );
430 
431 
435 
436 #ifdef _WIN32
437 
445 
446 DT_DLL_VLUTIL void setFileOutput( const char* filename, int con = 0, int son = 0 );
447 DT_DLL_VLUTIL void closeConsole();
449 
450 #endif
451 
452 
457 DT_DLL_VLUTIL void DtAbort();
458 
460 typedef void (*DtAbortFunc)();
461 
464 
467 
468 #if DT_NO_VSNPRINTF
469 DT_DLL_VLUTIL int vsnprintf( char*, size_t, const char*, va_list );
471 #endif
472 
473 //-------------------------------------------
474 //Inline Function Definitions
475 //-----------------------------------------
476 inline void DtOutputStream::setThreshold( int level )
477 {
478  myThreshold = level;
479 }
480 
481 inline int DtOutputStream::threshold() const
482 {
483  return myThreshold;
484 }
485 
487 {
488 }
489 
491 {
492 }
493 
495 {
496 }
497 
499 {
500 }
501 
503 {
504 }
505 
507 {
508 }
509 
511 {
512 }
513 
514 
515 #ifdef DtUSE_UTILITIES_NAMESPACE
516 }
517 #endif
class DtStderrPrinter is a subclass of DtPrinter which copies all input received from DtOutputStream ...
Definition: vlPrint.h:179
void DtSetVrLinkPrinter(DtPrinter *newPrinter)
DtSetVrLinkPrinter is provided for backwards compatibility.
This file contains the declaration of DtMutex.
DtOutputStream DtFatal
These DtOutputStream instances are used for all print messaging in VR-Link.
DtPrinter()
Default CTOR.
Definition: vlPrint.h:486
DtStdoutPrinter()
Default CTOR.
Definition: vlPrint.h:498
unsigned int myLogRollingInterval
Definition: vlPrint.h:138
void DtSetAbortFunc(DtAbortFunc func)
bool myTimestampFlag
Definition: vlPrint.h:134
DtPrinter is an abstract base class which provides an interface for output.
Definition: vlPrint.h:57
Contains the DtString class declaration.
DtFilePrinter is a subclass of DtPrinter which opens a file and dumps all information received from D...
Definition: vlPrint.h:82
DtMutex myFileLock
Definition: vlPrint.h:132
Definition: vlPrint.h:46
std::string myFilename
Definition: vlPrint.h:140
DtStderrPrinter DtStandardErrorConsole
This class is a basic DtPrinter instance which can be used with DtOutputStream instances.
virtual ~DtPrinter()
Virtual DTOR.
Definition: vlPrint.h:494
void DtWarnPerror(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
DtMutex myPrintersMutex
Definition: vlPrint.h:346
DtStdoutPrinter is a subclass of DtPrinter which copies all input received from DtOutputStream to the...
Definition: vlPrint.h:156
virtual ~DtStdoutPrinter()
Virtual DTOR.
Definition: vlPrint.h:502
DtOutputStreamBuffer is the internal buffer for DtOutputStream.
Definition: vlPrint.h:233
DtOutputStream * myOutputStream
Definition: vlPrint.h:262
std::string myFileBase
Definition: vlPrint.h:141
virtual ~DtStderrPrinter()
Virtual DTOR.
Definition: vlPrint.h:510
DtOutputStreamBuffer * myStreamBuf
Definition: vlPrint.h:343
void(* DtAbortFunc)()
Definition: vlPrint.h:460
DtStdoutPrinter DtStandardOutConsole
This class is a basic DtPrinter instance which can be used with DtOutputStream instances.
Definition: vlPrint.h:43
int & myGlobalThresholdReference
This is the global value we compare myThreshold to.
Definition: vlPrint.h:350
int DtNotifyLevel
DtNotifyLevel is used to control the level of diagnostics output by VR-Link.
int myThreshold
Definition: vlPrint.h:347
DtMutex myLock
Definition: vlPrint.h:171
PrinterPtrVec myPrinters
Definition: vlPrint.h:345
instances of DtMutex are used to provide a platform independent mutual exclusion mechanism ...
Definition: vlMutex.h:31
DtOutputStream DtVerbose
These DtOutputStream instances are used for all print messaging in VR-Link.
DtOutputStream is used for all toolkit output.
Definition: vlPrint.h:284
void DtFatalNetPerror(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
DtOutputStream DtWarn
These DtOutputStream instances are used for all print messaging in VR-Link.
void DtFatalPerror(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
void DtAbort()
DtAbort() exits the program.
std::vector< DtPrinter * > PrinterPtrVec
Definition: vlPrint.h:341
void DtPrintEnvironmentVariables(DtOutputStream &os=DtInfo)
Print the environment variables If notifyLevel isn&#39;t specified, function will use DtNlInfo as appropr...
DtString DtFormatPrintString(const DtOutputStream &os, const char *fmt,...)
Formats a printf-style string into a DtString.
DtOutputStream DtInfo
DtInfo is an global instance of a DtOutputStream.
Definition: vlPrint.h:47
Definition: vlPrint.h:44
virtual void setThreshold(int level)
Sets the threshold required for sending string output to all attached printer.
Definition: vlPrint.h:476
DtAbortFunc DtGetAbortFunc()
std::string myFileExt
Definition: vlPrint.h:142
DtStderrPrinter()
Default CTOR.
Definition: vlPrint.h:506
time_t myLogFileOpenTime
Definition: vlPrint.h:136
DtNotifyLevelType
Default is DtNlInfo.
Definition: vlPrint.h:41
Instances of DtString are used to represent strings.
Definition: vlString.h:38
std::string myBuffer
Definition: vlPrint.h:260
void DtFatalError(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
DtMutex myStreamBufMutex
Definition: vlPrint.h:344
unsigned int myLogRollingIndex
Definition: vlPrint.h:137
virtual int threshold() const
Returns the current threshold required to send string output to all attached printers.
Definition: vlPrint.h:481
DtMutex myBufferMutex
Definition: vlPrint.h:261
void DtWarnNetPerror(const char *str,...)
These functions print messages using DtOutputStreams depending on the notify level.
Definition: vlPrint.h:45
DtMutex myLock
Definition: vlPrint.h:194
This file contains typedefs for machine dependant types.
std::ofstream myFile
Definition: vlPrint.h:145
#define DT_DLL_VLUTIL
Definition: vlMachineTypes.h:121
DtOutputStream DtDebug
These DtOutputStream instances are used for all print messaging in VR-Link.

Document ID: Generated on Mon Sep 28 00:09:32 EDT 2026 from SVN revision 295353
Copyright © 1992-2025 MAK Technologies. All Rights Reserved (www.mak.com)