NullStream.h 1.8 KB

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