Base64Decoder.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // Base64Decoder.h
  3. //
  4. // $Id: //poco/1.4/Foundation/include/Poco/Base64Decoder.h#2 $
  5. //
  6. // Library: Foundation
  7. // Package: Streams
  8. // Module: Base64
  9. //
  10. // Definition of class Base64Decoder.
  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_Base64Decoder_INCLUDED
  18. #define Foundation_Base64Decoder_INCLUDED
  19. #include "Poco/Foundation.h"
  20. #include "Poco/UnbufferedStreamBuf.h"
  21. #include <istream>
  22. namespace Poco {
  23. class Foundation_API Base64DecoderBuf: public UnbufferedStreamBuf
  24. /// This streambuf base64-decodes all data read
  25. /// from the istream connected to it.
  26. ///
  27. /// Note: For performance reasons, the characters
  28. /// are read directly from the given istream's
  29. /// underlying streambuf, so the state
  30. /// of the istream will not reflect that of
  31. /// its streambuf.
  32. {
  33. public:
  34. Base64DecoderBuf(std::istream& istr);
  35. ~Base64DecoderBuf();
  36. private:
  37. int readFromDevice();
  38. int readOne();
  39. unsigned char _group[3];
  40. int _groupLength;
  41. int _groupIndex;
  42. std::streambuf& _buf;
  43. static unsigned char IN_ENCODING[256];
  44. static bool IN_ENCODING_INIT;
  45. private:
  46. Base64DecoderBuf(const Base64DecoderBuf&);
  47. Base64DecoderBuf& operator = (const Base64DecoderBuf&);
  48. };
  49. class Foundation_API Base64DecoderIOS: public virtual std::ios
  50. /// The base class for Base64Decoder.
  51. ///
  52. /// This class is needed to ensure the correct initialization
  53. /// order of the stream buffer and base classes.
  54. {
  55. public:
  56. Base64DecoderIOS(std::istream& istr);
  57. ~Base64DecoderIOS();
  58. Base64DecoderBuf* rdbuf();
  59. protected:
  60. Base64DecoderBuf _buf;
  61. private:
  62. Base64DecoderIOS(const Base64DecoderIOS&);
  63. Base64DecoderIOS& operator = (const Base64DecoderIOS&);
  64. };
  65. class Foundation_API Base64Decoder: public Base64DecoderIOS, public std::istream
  66. /// This istream base64-decodes all data
  67. /// read from the istream connected to it.
  68. ///
  69. /// Note: For performance reasons, the characters
  70. /// are read directly from the given istream's
  71. /// underlying streambuf, so the state
  72. /// of the istream will not reflect that of
  73. /// its streambuf.
  74. {
  75. public:
  76. Base64Decoder(std::istream& istr);
  77. ~Base64Decoder();
  78. private:
  79. Base64Decoder(const Base64Decoder&);
  80. Base64Decoder& operator = (const Base64Decoder&);
  81. };
  82. } // namespace Poco
  83. #endif // Foundation_Base64Decoder_INCLUDED