TeeStream.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // TeeStream.cpp
  3. //
  4. // $Id: //poco/1.4/Foundation/src/TeeStream.cpp#1 $
  5. //
  6. // Library: Foundation
  7. // Package: Streams
  8. // Module: TeeStream
  9. //
  10. // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #include "Poco/TeeStream.h"
  16. namespace Poco {
  17. TeeStreamBuf::TeeStreamBuf():
  18. _pIstr(0)
  19. {
  20. }
  21. TeeStreamBuf::TeeStreamBuf(std::istream& istr):
  22. _pIstr(&istr)
  23. {
  24. }
  25. TeeStreamBuf::TeeStreamBuf(std::ostream& ostr):
  26. _pIstr(0)
  27. {
  28. _streams.push_back(&ostr);
  29. }
  30. TeeStreamBuf::~TeeStreamBuf()
  31. {
  32. }
  33. void TeeStreamBuf::addStream(std::ostream& ostr)
  34. {
  35. _streams.push_back(&ostr);
  36. }
  37. int TeeStreamBuf::readFromDevice()
  38. {
  39. if (_pIstr)
  40. {
  41. int c = _pIstr->get();
  42. if (c != -1) writeToDevice((char) c);
  43. return c;
  44. }
  45. return -1;
  46. }
  47. int TeeStreamBuf::writeToDevice(char c)
  48. {
  49. for (StreamVec::iterator it = _streams.begin(); it != _streams.end(); ++it)
  50. {
  51. (*it)->put(c);
  52. }
  53. return charToInt(c);
  54. }
  55. TeeIOS::TeeIOS()
  56. {
  57. poco_ios_init(&_buf);
  58. }
  59. TeeIOS::TeeIOS(std::istream& istr): _buf(istr)
  60. {
  61. poco_ios_init(&_buf);
  62. }
  63. TeeIOS::TeeIOS(std::ostream& ostr): _buf(ostr)
  64. {
  65. poco_ios_init(&_buf);
  66. }
  67. TeeIOS::~TeeIOS()
  68. {
  69. }
  70. void TeeIOS::addStream(std::ostream& ostr)
  71. {
  72. _buf.addStream(ostr);
  73. }
  74. TeeStreamBuf* TeeIOS::rdbuf()
  75. {
  76. return &_buf;
  77. }
  78. TeeInputStream::TeeInputStream(std::istream& istr): TeeIOS(istr), std::istream(&_buf)
  79. {
  80. }
  81. TeeInputStream::~TeeInputStream()
  82. {
  83. }
  84. TeeOutputStream::TeeOutputStream(): std::ostream(&_buf)
  85. {
  86. }
  87. TeeOutputStream::TeeOutputStream(std::ostream& ostr): TeeIOS(ostr), std::ostream(&_buf)
  88. {
  89. }
  90. TeeOutputStream::~TeeOutputStream()
  91. {
  92. }
  93. } // namespace Poco