VR-Link API Documentation for DIS
vlPrint.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 *******************************************************************************/
8 #pragma once
9 
10 #include "vlMachineTypes.h"
11 #include "vlMutex.h"
12 #include <iostream>
13 #include <ios>
14 #include <fstream>
15 #include <vector>
16 
17 
18 #ifdef _WIN32
19 #include <winsock2.h>
20 #endif
21 
22 #ifdef DtUSE_UTILITIES_NAMESPACE
23 namespace DtUSE_UTILITIES_NAMESPACE
24 {
25 #endif
26 
27 
33 extern DT_DLL_VLUTIL int DtNotifyLevel;
34 
35 
38 {
44 };
45 
53 {
54 
55 public:
56  inline DtPrinter();
57  inline DtPrinter(const DtPrinter &);
58  virtual inline ~DtPrinter();
59 
62  virtual void write( const std::string &str, int notify_level) =0;
63 
64 };
65 
71 {
72 public:
74  DtFilePrinter(const char* filename);
75 
77  DtFilePrinter();
78 
81  virtual ~DtFilePrinter();
82 
85  virtual void resetFile(const char* filename);
86 
88  virtual bool isOpen();
89 
90  virtual void write(const std::string &st, int notify_level);
91 
92 protected:
93  DtFilePrinter(const DtFilePrinter& orig);
94  DtFilePrinter& operator=(const DtFilePrinter& orig);
95 
96 protected:
98 #ifndef __sgi__
99  std::ofstream myFile;
100 #else
101  std::fstream myFile;
102 #endif
103 };
104 
109 {
110 public:
111  inline DtStdoutPrinter();
112  virtual inline ~DtStdoutPrinter();
113  virtual void write( const std::string &st, int notify_level );
114 protected:
116 };
117 
122 {
123 public:
124  inline DtStderrPrinter();
125  virtual inline ~DtStderrPrinter();
126  virtual void write( const std::string &st, int notify_level );
127 protected:
129 };
130 
131 #ifdef _WIN32
132 
133 
134 
135 class DT_DLL_VLUTIL DtWindowsConsolePrinter : public DtPrinter
136 {
137 public:
138  DtWindowsConsolePrinter(bool disableClose = false);
139  virtual ~DtWindowsConsolePrinter();
140  virtual void write( const std::string &st, int notify_level );
141 
142 protected:
143 
144  HANDLE myConsoleHandle;
145  DtMutex myLock;
146 
147 };
148 #endif
149 
152 class DtOutputStream;
153 
157 class DT_DLL_VLUTIL DtOutputStreamBuffer : public std::basic_streambuf< char >
158 {
159 
160 public:
161 
163  virtual ~DtOutputStreamBuffer();
164 
165 private:
166 
170  DtOutputStreamBuffer & operator=(const DtOutputStreamBuffer &);
171 
172 public:
173 
174  virtual void setOutputStream( DtOutputStream *stream );
175 
176 protected:
177 
178  virtual int_type overflow( int_type c );
179  virtual int sync();
180 
181  std::string myBuffer;
184 
185 };
186 
204 class DT_DLL_VLUTIL DtOutputStream : public std::basic_ostream< char >
205 {
206 
207 public:
208 
209  //Constructor takes a pointer to a variable to use to check against a
210  //global threshold. Each DtOutputStreamBuffer needs to also have a
211  //unique DtOutputStreamBuffer which should be created before
212  //the DtOutputStream that uses it is created.
214  int &globalThresholdRef,
215  int threshold = 1,
216  DtPrinter *dflt_printer = 0);
217 
218  virtual ~DtOutputStream();
219 
221  virtual void attachPrinter(DtPrinter *sink );
222 
225  virtual bool detachPrinter(DtPrinter *sink );
226 
229  virtual void detachAllPrinters();
230 
232  virtual void write( const std::string &str );
233 
236  virtual void setThreshold( int level );
239  virtual int threshold() const;
240 
241 
245 #ifdef _WIN32
246  bool okToPrint() const;
247 #else
248  virtual bool okToPrint() const;
249 #endif
250 
252  virtual void operator()(const char *s, ...);
253 
254 
255 protected:
256 
257  typedef std::vector<DtPrinter*> PrinterPtrVec;
258 
259 protected:
260 
266 
269 
270 private:
273 
275  DtOutputStream & operator=(const DtOutputStream &);
276 
277 };
278 
279 
290 
301 
302 
303 
310 
321 
322 
331 
332 extern DT_DLL_VLUTIL void DtFatalError(const char * str, ...);
333 extern DT_DLL_VLUTIL void DtFatalPerror(const char * str, ...);
334 extern DT_DLL_VLUTIL void DtWarnPerror(const char * str, ...);
335 extern DT_DLL_VLUTIL void DtFatalNetPerror(const char * str, ...);
336 extern DT_DLL_VLUTIL void DtWarnNetPerror(const char * str, ...);
338 
344 DT_DLL_VLUTIL void DtSetVrLinkPrinter(DtPrinter* newPrinter);
345 
346 #ifdef _WIN32
347 
348 
349 
350 
351 
352 
353 
354 
355 DT_DLL_VLUTIL void setFileOutput(const char *filename, int con=0, int son=0);
356 DT_DLL_VLUTIL void closeConsole();
358 #endif
359 
360 
365 DT_DLL_VLUTIL void DtAbort();
366 
368 typedef void (*DtAbortFunc)();
369 
372 
375 
376 #if DT_NO_VSNPRINTF
377 
378 DT_DLL_VLUTIL int vsnprintf( char*, size_t, const char*, va_list );
379 #endif
380 
381 //-------------------------------------------
382 //Inline Function Definitions
383 //-----------------------------------------
384 inline void DtOutputStream::setThreshold( int level )
385 {
386  myThreshold = level;
387 }
388 
389 inline int DtOutputStream::threshold() const
390 {
391  return myThreshold;
392 }
393 
395 {
396 }
397 
399 {
400 }
401 
403 {
404 }
405 
407 {
408 }
409 
411 {
412 }
413 
415 {
416 }
417 
419 {
420 }
421 
422 #ifdef _WIN32
423 inline bool DtOutputStream::okToPrint() const
424 {
425  return (threshold() <= myGlobalThresholdReference);
426 }
427 #endif
428 
429 #ifdef DtUSE_UTILITIES_NAMESPACE
430 }
431 #endif
432 

Document ID: Generated on Wed Aug 14 15:35:11 EDT 2013 from SVN revision 130445
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)