null.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "zerocopy.h"
  3. #include "output.h"
  4. /**
  5. * @addtogroup Streams
  6. * @{
  7. */
  8. /**
  9. * Null input stream. Does nothing, contains no data.
  10. */
  11. class TNullInput: public IZeroCopyInput {
  12. public:
  13. TNullInput() noexcept;
  14. ~TNullInput() override;
  15. private:
  16. size_t DoRead(void* buf, size_t len) override;
  17. size_t DoSkip(size_t len) override;
  18. size_t DoNext(const void** ptr, size_t len) override;
  19. };
  20. /**
  21. * Null output stream. Just ignores whatever is written into it.
  22. */
  23. class TNullOutput: public IOutputStream {
  24. public:
  25. TNullOutput() noexcept;
  26. ~TNullOutput() override;
  27. TNullOutput(TNullOutput&&) noexcept = default;
  28. TNullOutput& operator=(TNullOutput&&) noexcept = default;
  29. private:
  30. void DoWrite(const void* buf, size_t len) override;
  31. };
  32. /**
  33. * Null input-output stream.
  34. *
  35. * @see TNullInput
  36. * @see TNullOutput
  37. */
  38. class TNullIO: public TNullInput, public TNullOutput {
  39. public:
  40. TNullIO() noexcept;
  41. ~TNullIO() override;
  42. };
  43. namespace NPrivate {
  44. TNullIO& StdNullStream() noexcept;
  45. }
  46. /**
  47. * Standard null stream.
  48. */
  49. #define Cnull (::NPrivate::StdNullStream())
  50. /** @} */