multiplexStream.I 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // Filename: multiplexStream.I
  2. // Created by: drose (27Nov00)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. ////////////////////////////////////////////////////////////////////
  15. // Function: MultiplexStream::Constructor
  16. // Access: Public
  17. // Description:
  18. ////////////////////////////////////////////////////////////////////
  19. INLINE MultiplexStream::
  20. MultiplexStream() : ostream(&_msb) {
  21. setf(ios::unitbuf);
  22. }
  23. ////////////////////////////////////////////////////////////////////
  24. // Function: MultiplexStream::add_ostream
  25. // Access: Public
  26. // Description: Adds the indicated generic ostream to the multiplex
  27. // output. The ostream will receive whatever data is
  28. // sent to the pipe.
  29. ////////////////////////////////////////////////////////////////////
  30. INLINE void MultiplexStream::
  31. add_ostream(ostream *out, bool delete_later) {
  32. _msb.add_output(MultiplexStreamBuf::BT_none,
  33. MultiplexStreamBuf::OT_ostream,
  34. out, NULL, delete_later);
  35. }
  36. ////////////////////////////////////////////////////////////////////
  37. // Function: MultiplexStream::add_stdio_file
  38. // Access: Public
  39. // Description: Adds the given file, previously opened using the C
  40. // stdio library, to the multiplex output.
  41. ////////////////////////////////////////////////////////////////////
  42. INLINE bool MultiplexStream::
  43. add_stdio_file(FILE *fout, bool close_when_done) {
  44. _msb.add_output(MultiplexStreamBuf::BT_line,
  45. MultiplexStreamBuf::OT_ostream,
  46. NULL, fout, close_when_done);
  47. return true;
  48. }
  49. ////////////////////////////////////////////////////////////////////
  50. // Function: MultiplexStream::add_standard_output
  51. // Access: Public
  52. // Description: Adds the standard output channel.
  53. ////////////////////////////////////////////////////////////////////
  54. INLINE void MultiplexStream::
  55. add_standard_output() {
  56. _msb.add_output(MultiplexStreamBuf::BT_none,
  57. MultiplexStreamBuf::OT_ostream,
  58. &cout, NULL, false);
  59. }
  60. ////////////////////////////////////////////////////////////////////
  61. // Function: MultiplexStream::add_file
  62. // Access: Public
  63. // Description: Adds the given file to the multiplex output. The
  64. // file is opened in append mode with line buffering.
  65. // Returns false if the file cannot be opened.
  66. ////////////////////////////////////////////////////////////////////
  67. INLINE bool MultiplexStream::
  68. add_file(Filename file) {
  69. file.set_text();
  70. pofstream *out = new pofstream;
  71. if (!file.open_append(*out)) {
  72. delete out;
  73. return false;
  74. }
  75. out->setf(ios::unitbuf);
  76. _msb.add_output(MultiplexStreamBuf::BT_line,
  77. MultiplexStreamBuf::OT_ostream,
  78. out, NULL, true);
  79. return true;
  80. }
  81. ////////////////////////////////////////////////////////////////////
  82. // Function: MultiplexStream::add_system_debug
  83. // Access: Public
  84. // Description: Adds the system debug output the the multiplex
  85. // output. This may map to a syslog or some such
  86. // os-specific output system. It may do nothing on a
  87. // particular system.
  88. //
  89. // Presently, this maps only to OutputDebugString() on
  90. // Windows.
  91. ////////////////////////////////////////////////////////////////////
  92. INLINE void MultiplexStream::
  93. add_system_debug() {
  94. _msb.add_output(MultiplexStreamBuf::BT_line,
  95. MultiplexStreamBuf::OT_system_debug);
  96. }
  97. ////////////////////////////////////////////////////////////////////
  98. // Function: MultiplexStream::flush
  99. // Access: Public
  100. // Description: Forces out all output that hasn't yet been written.
  101. ////////////////////////////////////////////////////////////////////
  102. INLINE void MultiplexStream::
  103. flush() {
  104. _msb.flush();
  105. }