LightWrap++
AC++wrapperfortheLightWave3DSDK
debug.h
Go to the documentation of this file.
1 #ifndef LWPP_DEBUG_H
2 #define LWPP_DEBUG_H
3 
4 // always include plattform specific include
5 #include <lwpp/platform.h>
6 #include <cassert>
7 #include <fstream>
8 
9 namespace lwpp
10 {
11 #ifdef _DEBUG
12  #ifdef _DEBUGTOFILE
13  class dostream : public std::ofstream
14  {
15  public:
16  dostream() : std::ofstream("lwpp.log", std::ios::out | std::ios::app)
17  {
18  ;
19  }
20  };
21  #else
22  #ifdef LWPP_PLATFORM_OSX_UB
23  /*
24  #ifdef NOTHING
25  //#ifdef __MWERKS__
26 // #warning Debugging OSX
27 
28  class dostream : public std::ofstream
29  {
30  public:
31  dostream() : std::ofstream("lwpp.log", std::ios::out | std::ios::app)
32  {
33  ;
34  }
35  };
36  #else
37 */
38  //#warning Debugging OSX
39 
40  class dostream : public std::stringstream
41  {
42  public:
43  dostream()
44  {
45  ;
46  }
47 
48  virtual ~dostream()
49  {
50  sync();
51  }
52 
53  virtual int sync()
54  {
55  std::cerr << str(); // << std::endl;
56  str(""); // Clear the string buffer
57  return 0;
58  }
59  };
60  //#endif
61 
62  #elif defined(LWPP_PLATFORM_WIN)
63 
64  template <class CharT, class TraitsT = std::char_traits<CharT> >
65  class basic_debugbuf : public std::basic_stringbuf<CharT, TraitsT>
66  {
67  public:
68  virtual ~basic_debugbuf()
69  {
70  sync();
71  }
72 
73  protected:
74  int sync()
75  {
76  ::OutputDebugStringA(str().c_str());
77  str(std::basic_string<CharT>()); // Clear the string buffer
78  return 0;
79  }
80  };
81 
82  template<class CharT, class TraitsT = std::char_traits<CharT> >
83  class basic_dostream :
84  public std::basic_ostream<CharT, TraitsT>
85  {
86  public:
87  basic_dostream()
88  : std::basic_ostream<CharT, TraitsT>(new basic_debugbuf<CharT, TraitsT>())
89  {
90  setf(std::ios::unitbuf);
91  }
92  ~basic_dostream()
93  {
94  delete rdbuf();
95  }
96  };
97 
98  typedef basic_dostream<char> dostream;
99 
100  #endif // _MSWIN
101  #endif // _DEBUGTOFILE
102 #endif // _DEBUG
103 }
104 
105 #endif // LWPP_DEBUG_H