VR-Link API Documentation for HLA Evolved
vlPrint.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002 ** Copyright (c) 1992-2010 VT MAK
00003 ** All rights reserved.
00004 *******************************************************************************/
00008 #pragma once
00009 
00010 #include "vlMachineTypes.h"
00011 #include "vlMutex.h"
00012 #include <iostream>
00013 #include <ios>
00014 #include <fstream>
00015 #include <vector>
00016 
00017 
00018 #ifdef _WIN32
00019 #include <winsock2.h>
00020 #endif
00021 
00022 #ifdef DtUSE_UTILITIES_NAMESPACE
00023 namespace DtUSE_UTILITIES_NAMESPACE
00024 {
00025 #endif
00026 
00027 
00033 extern DT_DLL_VLUTIL int DtNotifyLevel;  
00034 
00035 
00037 enum DtNotifyLevelType
00038 { 
00039    DtNlFatal     =0,
00040    DtNlWarn      =1,
00041    DtNlInfo      =2,
00042    DtNlVerbose   =3,
00043    DtNlDebug     =4 
00044 };
00045 
00052 class DT_DLL_VLUTIL DtPrinter
00053 {
00054 
00055 public:
00056    inline DtPrinter();
00057    inline DtPrinter(const DtPrinter &);
00058    virtual inline  ~DtPrinter();
00059 
00062    virtual void  write( const std::string &str, int notify_level) =0;
00063 
00064 };
00065 
00070 class DT_DLL_VLUTIL DtFilePrinter : public DtPrinter
00071 {
00072 public:
00074    DtFilePrinter(const char* filename);
00075 
00077    DtFilePrinter();
00078 
00081    virtual ~DtFilePrinter();
00082 
00085    virtual void resetFile(const char* filename);
00086 
00088    virtual bool isOpen();
00089 
00090    virtual void write(const std::string &st, int notify_level);
00091 
00092 protected:
00093    DtFilePrinter(const DtFilePrinter& orig);
00094    DtFilePrinter& operator=(const DtFilePrinter& orig);
00095 
00096 protected:
00097   DtMutex myFileLock;
00098 #ifndef __sgi__
00099    std::ofstream myFile;
00100 #else
00101    std::fstream myFile;
00102 #endif
00103 };
00104 
00108 class DT_DLL_VLUTIL DtStdoutPrinter : public DtPrinter
00109 {
00110 public:
00111    inline DtStdoutPrinter();
00112    virtual inline  ~DtStdoutPrinter(); 
00113    virtual void  write( const std::string &st, int notify_level );
00114 protected:
00115    DtMutex myLock;
00116 };
00117 
00121 class DT_DLL_VLUTIL DtStderrPrinter : public DtPrinter
00122 {
00123 public:
00124    inline DtStderrPrinter();
00125    virtual inline   ~DtStderrPrinter();
00126    virtual void  write( const std::string &st, int notify_level );
00127 protected:
00128    DtMutex myLock;
00129 };
00130 
00131 #ifdef _WIN32
00132 
00133 
00134 
00135 class DT_DLL_VLUTIL DtWindowsConsolePrinter : public DtPrinter
00136 {
00137 public:
00138    DtWindowsConsolePrinter(bool disableClose = false);
00139    virtual ~DtWindowsConsolePrinter(); 
00140    virtual void  write( const std::string &st, int notify_level );
00141 
00142 protected:
00143 
00144    HANDLE myConsoleHandle;
00145    DtMutex myLock;
00146    
00147 };
00148 #endif
00149 
00152 class DtOutputStream;
00153 
00157 class DT_DLL_VLUTIL DtOutputStreamBuffer : public std::basic_streambuf< char >
00158 {
00159 
00160 public:
00161 
00162    DtOutputStreamBuffer();
00163    virtual ~DtOutputStreamBuffer();
00164 
00165 private:
00166 
00168    DtOutputStreamBuffer(const DtOutputStreamBuffer&);
00170    DtOutputStreamBuffer & operator=(const DtOutputStreamBuffer &);
00171 
00172 public:
00173 
00174    virtual void setOutputStream( DtOutputStream *stream );
00175 
00176 protected:
00177 
00178    virtual int_type  overflow( int_type c );
00179    virtual int sync();
00180    
00181    std::string        myBuffer;
00182    DtMutex            myBufferMutex;
00183    DtOutputStream    *myOutputStream;
00184 
00185 };
00186 
00204 class DT_DLL_VLUTIL DtOutputStream : public std::basic_ostream< char >
00205 {
00206 
00207 public:
00208 
00209    //Constructor takes a pointer to a variable to use to check against a
00210    //global threshold. Each DtOutputStreamBuffer needs to also have a 
00211    //unique DtOutputStreamBuffer which should be created before 
00212    //the DtOutputStream that uses it is created.
00213    DtOutputStream(DtOutputStreamBuffer *b,
00214                   int &globalThresholdRef,
00215                   int threshold = 1,
00216                   DtPrinter *dflt_printer = 0);
00217 
00218    virtual ~DtOutputStream();
00219 
00221    virtual void attachPrinter(DtPrinter *sink );
00222 
00225    virtual bool detachPrinter(DtPrinter *sink );
00226 
00229    virtual void detachAllPrinters();
00230 
00232    virtual void write( const std::string &str );
00233 
00236    virtual void setThreshold( int level );
00239    virtual int  threshold() const;
00240 
00241 
00245 #ifdef _WIN32
00246    bool okToPrint() const;
00247 #else
00248    virtual bool okToPrint() const;
00249 #endif
00250 
00252    virtual void operator()(const char *s, ...);
00253 
00254 
00255 protected:
00256 
00257    typedef std::vector<DtPrinter*> PrinterPtrVec;
00258 
00259 protected:
00260 
00261    DtOutputStreamBuffer       *myStreamBuf;
00262    DtMutex                     myStreamBufMutex;
00263    PrinterPtrVec               myPrinters;
00264    DtMutex                     myPrintersMutex;
00265    int                         myThreshold;
00266 
00268    int                        &myGlobalThresholdReference;
00269 
00270 private:
00272    DtOutputStream(const DtOutputStream &);
00273 
00275    DtOutputStream & operator=(const DtOutputStream &);
00276 
00277 };
00278 
00279 
00289 extern DT_DLL_VLUTIL DtStdoutPrinter DtStandardOutConsole;
00290 
00300 extern DT_DLL_VLUTIL DtStderrPrinter DtStandardErrorConsole;
00301 
00302 
00303 
00310 
00311 extern DT_DLL_VLUTIL DtOutputStream DtFatal;
00312 extern DT_DLL_VLUTIL DtOutputStream DtWarn;
00317 extern DT_DLL_VLUTIL DtOutputStream DtInfo;
00318 extern DT_DLL_VLUTIL DtOutputStream DtVerbose;
00319 extern DT_DLL_VLUTIL DtOutputStream DtDebug;
00321 
00322 
00331 
00332 extern DT_DLL_VLUTIL void DtFatalError(const char * str, ...);
00333 extern DT_DLL_VLUTIL void DtFatalPerror(const char * str, ...);
00334 extern DT_DLL_VLUTIL void DtWarnPerror(const char * str, ...);
00335 extern DT_DLL_VLUTIL void DtFatalNetPerror(const char * str, ...);
00336 extern DT_DLL_VLUTIL void DtWarnNetPerror(const char * str, ...);
00338 
00344 DT_DLL_VLUTIL void DtSetVrLinkPrinter(DtPrinter* newPrinter);
00345 
00346 #ifdef _WIN32
00347 
00348 
00349 
00350 
00351 
00352 
00353 
00354 
00355 DT_DLL_VLUTIL void setFileOutput(const char *filename, int con=0, int son=0);
00356 DT_DLL_VLUTIL void closeConsole();
00358 #endif
00359 
00360 
00365 DT_DLL_VLUTIL void DtAbort();
00366 
00368 typedef void (*DtAbortFunc)();
00369 
00371 DT_DLL_VLUTIL void DtSetAbortFunc(DtAbortFunc func);
00372 
00374 DT_DLL_VLUTIL DtAbortFunc DtGetAbortFunc();
00375 
00376 #if DT_NO_VSNPRINTF
00377 
00378 DT_DLL_VLUTIL int vsnprintf( char*, size_t, const char*, va_list );
00379 #endif
00380 
00381 //-------------------------------------------
00382 //Inline Function Definitions
00383 //-----------------------------------------
00384 inline void DtOutputStream::setThreshold( int level ) 
00385 { 
00386    myThreshold = level;
00387 }
00388 
00389 inline int  DtOutputStream::threshold() const
00390 { 
00391    return myThreshold; 
00392 }
00393 
00394 inline DtPrinter::DtPrinter() 
00395 {
00396 }
00397 
00398 inline DtPrinter::DtPrinter(const DtPrinter &) 
00399 {
00400 }
00401 
00402 inline DtPrinter::~DtPrinter() 
00403 {
00404 }
00405 
00406 inline DtStdoutPrinter::DtStdoutPrinter()
00407 {
00408 }
00409 
00410 inline DtStdoutPrinter::~DtStdoutPrinter() 
00411 {
00412 }
00413 
00414 inline DtStderrPrinter::DtStderrPrinter()
00415 {
00416 }
00417 
00418 inline DtStderrPrinter::~DtStderrPrinter() 
00419 {
00420 }
00421 
00422 #ifdef _WIN32
00423 inline bool DtOutputStream::okToPrint() const
00424 {
00425    return (threshold() <= myGlobalThresholdReference);
00426 }
00427 #endif
00428 
00429 #ifdef DtUSE_UTILITIES_NAMESPACE
00430 }     
00431 #endif
00432 

Document ID: Generated on Mon May 14 08:06:18 EDT 2012 from SVN revision 114750
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)