VR-Link API Documentation for HLA 1.3
 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) 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 
40 {
41  DtNlFatal = 0,
42  DtNlWarn = 1,
43  DtNlInfo = 2,
46 };
47 
48 
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 
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 
131 
133 
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 
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 
170 
171 };
172 
173 
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 
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 
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 
252 
254  DtOutputStreamBuffer& operator = ( const DtOutputStreamBuffer& );
255 
256 protected:
257 
258  std::string myBuffer;
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 
346 
349 
350 };
351 
352 
363 
374 
375 
382 
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 
420 #ifdef _WIN32
421 
429 
430 DT_DLL_VLUTIL void setFileOutput( const char* filename, int con = 0, int son = 0 );
431 DT_DLL_VLUTIL void closeConsole();
433 
434 #endif
435 
436 
441 DT_DLL_VLUTIL void DtAbort();
442 
444 typedef void (*DtAbortFunc)();
445 
448 
451 
452 #if DT_NO_VSNPRINTF
453 
454 DT_DLL_VLUTIL int vsnprintf( char*, size_t, const char*, va_list );
455 #endif
456 
457 //-------------------------------------------
458 //Inline Function Definitions
459 //-----------------------------------------
460 inline void DtOutputStream::setThreshold( int level )
461 {
462  myThreshold = level;
463 }
464 
465 inline int DtOutputStream::threshold() const
466 {
467  return myThreshold;
468 }
469 
471 {
472 }
473 
475 {
476 }
477 
479 {
480 }
481 
483 {
484 }
485 
487 {
488 }
489 
491 {
492 }
493 
495 {
496 }
497 
498 
499 #ifdef DtUSE_UTILITIES_NAMESPACE
500 }
501 #endif

Document ID: Generated on Tue Mar 1 02:56:17 EST 2016 from SVN revision 162687
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)