nlib
Base64OutputStream.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_BASE64OUTPUTSTREAM_H_
4 #define INCLUDE_NN_NLIB_BASE64OUTPUTSTREAM_H_
5 
7 
8 NLIB_NAMESPACE_BEGIN
9 
10 class OutputStream;
11 
12 namespace detail {
13 
14 class NLIB_VIS_PUBLIC Base64OutputTransform NLIB_FINAL : public OutputTransform {
15  public:
16  enum NewLineMode { NEWLINEMODE_NONE = 0, NEWLINEMODE_CRLF, NEWLINEMODE_LF };
17 
18  Base64OutputTransform() NLIB_NOEXCEPT;
19  virtual errno_t Transform(OutputStream* os, const void* p, size_t nBytes,
20  bool doFlush) NLIB_NOEXCEPT NLIB_OVERRIDE;
21  virtual void* GetWorkBuffer(size_t* n) NLIB_NOEXCEPT NLIB_OVERRIDE;
22  virtual errno_t OnSetStream(OutputStream* os) NLIB_NOEXCEPT NLIB_OVERRIDE;
23  virtual errno_t OnClose(OutputStream* os) NLIB_NOEXCEPT NLIB_OVERRIDE;
24 
25  void SetNewLineMode(NewLineMode mode) NLIB_NOEXCEPT { m_NewLine = mode; }
26 
27  private:
28  int m_C;
29  int m_CLen;
30  NewLineMode m_NewLine;
31  int m_Column;
32  unsigned char m_Buf[192];
33 };
34 
35 } // namespace detail
36 
37 #ifndef NLIB_DOXYGEN
38 typedef OutputConverterStreamTempl<detail::Base64OutputTransform> Base64OutputStream;
39 #else
41  : public OutputConverterStreamTempl<detail::Base64OutputTransform> {
42  public:
43  // NOTE: define NewLineMode (not typedef) again for doxygen.
44  enum NewLineMode { NEWLINEMODE_NONE = 0, NEWLINEMODE_CRLF, NEWLINEMODE_LF };
45 
46  public:
48  NLIB_STATIC_ASSERT(static_cast<int>(NEWLINEMODE_NONE) ==
49  static_cast<int>(TransformType::NEWLINEMODE_NONE));
50  NLIB_STATIC_ASSERT(static_cast<int>(NEWLINEMODE_CRLF) ==
51  static_cast<int>(TransformType::NEWLINEMODE_CRLF));
52  NLIB_STATIC_ASSERT(static_cast<int>(NEWLINEMODE_LF) ==
53  static_cast<int>(TransformType::NEWLINEMODE_LF));
54  m_Transform.SetNewLineMode(static_cast<TransformType::NewLineMode>(mode));
55  }
56 };
57 #endif
58 
59 NLIB_NAMESPACE_END
60 
61 #endif // INCLUDE_NN_NLIB_BASE64OUTPUTSTREAM_H_
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Platform.h:2151
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
#define NLIB_OVERRIDE
Defines override if it is available for use. If not, holds an empty string.
void SetNewLineMode(NewLineMode mode) noexcept
Sets the newline mode.
The class for holding the OutputTransform derived class.
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:51
#define NLIB_STATIC_ASSERT(exp)
Defines a static assertion. Uses static_assert if it is available for use.
Definition: Config.h:117
NewLineMode
The newline options for the output Base64 text. The default is NEWLINEMODE_NONE.
The class for writing data after encoding it in Base64.
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24