NullStream.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // NullStream.h
  3. //
  4. // Library: Foundation
  5. // Package: Streams
  6. // Module: NullStream
  7. //
  8. // Definition of the NullStreamBuf, NullInputStream and NullOutputStream classes.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef Foundation_NullStream_INCLUDED
  16. #define Foundation_NullStream_INCLUDED
  17. #include "Poco/Foundation.h"
  18. #include "Poco/UnbufferedStreamBuf.h"
  19. #include <istream>
  20. #include <ostream>
  21. namespace Poco {
  22. class Foundation_API NullStreamBuf: public UnbufferedStreamBuf
  23. /// This stream buffer discards all characters written to it.
  24. /// Any read operation immediately yields EOF.
  25. {
  26. public:
  27. NullStreamBuf();
  28. /// Creates a NullStreamBuf.
  29. ~NullStreamBuf();
  30. /// Destroys the NullStreamBuf.
  31. protected:
  32. int readFromDevice();
  33. int writeToDevice(char c);
  34. };
  35. class Foundation_API NullIOS: public virtual std::ios
  36. /// The base class for NullInputStream and NullOutputStream.
  37. ///
  38. /// This class is needed to ensure the correct initialization
  39. /// order of the stream buffer and base classes.
  40. {
  41. public:
  42. NullIOS();
  43. ~NullIOS();
  44. protected:
  45. NullStreamBuf _buf;
  46. };
  47. class Foundation_API NullInputStream: public NullIOS, public std::istream
  48. /// Any read operation from this stream immediately
  49. /// yields EOF.
  50. {
  51. public:
  52. NullInputStream();
  53. /// Creates the NullInputStream.
  54. ~NullInputStream();
  55. /// Destroys the NullInputStream.
  56. };
  57. class Foundation_API NullOutputStream: public NullIOS, public std::ostream
  58. /// This stream discards all characters written to it.
  59. {
  60. public:
  61. NullOutputStream();
  62. /// Creates the NullOutputStream.
  63. ~NullOutputStream();
  64. /// Destroys the NullOutputStream.
  65. };
  66. } // namespace Poco
  67. #endif // Foundation_NullStream_INCLUDED