Base32Encoder.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // Base32Encoder.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/Base32Encoder.h#2 $
  5. //
  6. // Library: Foundation
  7. // Package: Streams
  8. // Module: Base32
  9. //
  10. // Definition of class Base32Encoder.
  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_Base32Encoder_INCLUDED
  18. #define Foundation_Base32Encoder_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/UnbufferedStreamBuf.h"
  21. #include <ostream>
  22. namespace Poco {
  23. class Foundation_API Base32EncoderBuf: public UnbufferedStreamBuf
  24. /// This streambuf base32-encodes all data written
  25. /// to it and forwards it to a connected
  26. /// ostream.
  27. ///
  28. /// Note: The characters are directly written
  29. /// to the ostream's streambuf, thus bypassing
  30. /// the ostream. The ostream's state is therefore
  31. /// not updated to match the buffer's state.
  32. {
  33. public:
  34. Base32EncoderBuf(std::ostream& ostr, bool padding = true);
  35. ~Base32EncoderBuf();
  36. int close();
  37. /// Closes the stream buffer.
  38. private:
  39. int writeToDevice(char c);
  40. unsigned char _group[5];
  41. int _groupLength;
  42. std::streambuf& _buf;
  43. bool _doPadding;
  44. static const unsigned char OUT_ENCODING[32];
  45. friend class Base32DecoderBuf;
  46. Base32EncoderBuf(const Base32EncoderBuf&);
  47. Base32EncoderBuf& operator = (const Base32EncoderBuf&);
  48. };
  49. class Foundation_API Base32EncoderIOS: public virtual std::ios
  50. /// The base class for Base32Encoder.
  51. ///
  52. /// This class is needed to ensure the correct initialization
  53. /// order of the stream buffer and base classes.
  54. {
  55. public:
  56. Base32EncoderIOS(std::ostream& ostr, bool padding = true);
  57. ~Base32EncoderIOS();
  58. int close();
  59. Base32EncoderBuf* rdbuf();
  60. protected:
  61. Base32EncoderBuf _buf;
  62. private:
  63. Base32EncoderIOS(const Base32EncoderIOS&);
  64. Base32EncoderIOS& operator = (const Base32EncoderIOS&);
  65. };
  66. class Foundation_API Base32Encoder: public Base32EncoderIOS, public std::ostream
  67. /// This ostream base32-encodes all data
  68. /// written to it and forwards it to
  69. /// a connected ostream.
  70. /// Always call close() when done
  71. /// writing data, to ensure proper
  72. /// completion of the encoding operation.
  73. ///
  74. /// Note: The characters are directly written
  75. /// to the ostream's streambuf, thus bypassing
  76. /// the ostream. The ostream's state is therefore
  77. /// not updated to match the buffer's state.
  78. {
  79. public:
  80. Base32Encoder(std::ostream& ostr, bool padding = true);
  81. ~Base32Encoder();
  82. private:
  83. Base32Encoder(const Base32Encoder&);
  84. Base32Encoder& operator = (const Base32Encoder&);
  85. };
  86. } // namespace Poco
  87. #endif // Foundation_Base32Encoder_INCLUDED