mi32/base64.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  *
00003  * mi32/base64.h
00004  *
00005  * A Base-64 encoder/decoder class
00006  *
00007  * $Id: base64.h_v 1.2 2006/04/12 20:19:19 scowan Exp $
00008  *
00009  * $Log: base64.h_v $
00010  * Revision 1.2  2006/04/12 20:19:19  scowan
00011  * Cleaned up header for diocs.
00012  *
00013  * Revision 1.1  2003/07/11 16:39:14  dwilliss
00014  * Initial revision
00015  *
00016  * 
00017  ****************************************************************************/
00018 
00019 #ifndef INC_BASE64_H
00020 #define INC_BASE64_H
00021 
00022 #ifndef INC_MI32_STDDEFNS_H
00023 #include <mi32/stddefns.h>
00024 #endif
00025 
00026 #ifndef INC_MI32_SIMPLEAR_H
00027 #include <mi32/simplear.h>
00028 #endif
00029 
00030 #ifndef GENERATING_DOXYGEN_OUTPUT
00031 class FILEPATH;
00032 class GENERICRW;
00033 #endif // GENERATING_DOXYGEN_OUTPUT
00034 
00035 #ifdef MISYSTEMDLL
00036    #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00037 #else
00038    #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00039 #endif
00040 
00041 
00042 class CLASSLIBEXPORT BASE64_ENCODER {
00043    public:
00044       BASE64_ENCODER ();
00045       virtual ~BASE64_ENCODER ();
00046 
00047       //! Encode a file.
00048       //! Just opens the file and calles the GENERICRW version of the method.
00049       ERRVALUE Encode (
00050          const FILEPATH& filepath
00051          );
00052 
00053       //! Reads the file in chunks and calls the buffer version of the method
00054       ERRVALUE Encode (
00055          GENERICRW& stream
00056          );
00057 
00058       //! Encode byte stream.  Can be called multiple times if the input to
00059       //! be encoded is being read in chunks.
00060       ERRVALUE Encode (
00061          const UINT8* buffer,
00062          int NumBytes
00063          );
00064 
00065    private:
00066       #ifndef GENERATING_DOXYGEN_OUTPUT
00067       SIMPLE_ARRAY<char> m_WorkBuffer;
00068       // Copy constructor and assignment operator are private and unimplemented
00069       // Doesn't make sense to copy one.
00070       BASE64_ENCODER(const BASE64_ENCODER&);
00071       BASE64_ENCODER& operator=(const BASE64_ENCODER&);
00072       #endif // GENERATING_DOXYGEN_OUTPUT
00073 
00074       // Derived class must implement this.
00075       // Will be called as many times as needed as chunks of data are encoded
00076       // Do NOT append a newline to the buffer.  It will already have newlines
00077       // and may contain more than one line.
00078       // Should return 0 or an error code < 0
00079       virtual ERRVALUE v_Write (
00080          const char* buffer
00081          ) = 0;
00082 
00083       // Derived class may override this method if it wants to show status or
00084       // implement cancel checking.  This method should return EUserCancel to
00085       // cancel the operation, 0 to continue.  Will not be called by the 
00086       // version of Encode which just takes a buffer because the total size
00087       // is not known.  
00088       virtual ERRVALUE v_ShowStatus (
00089          double PercentDone
00090          );
00091 
00092    };
00093 
00094 
00095 class CLASSLIBEXPORT BASE64_DECODER {
00096    public:
00097       BASE64_DECODER();
00098       virtual ~BASE64_DECODER();
00099 
00100       //! Decode a file
00101       ERRVALUE Decode (
00102          const FILEPATH& filepath
00103          );
00104 
00105       //! Decode character stream
00106       //!
00107       ERRVALUE Decode (
00108          const char* buffer
00109          );
00110 
00111       //! Decode data from a GENERICRW stream.
00112       //! If size is supplied by the caller, it will only read and decode that
00113       //! many bytes of input.  This is useful for decoding base-64 data which
00114       //! is embeded in a larger stream of data.
00115       ERRVALUE Decode (
00116          GENERICRW& stream,
00117          INT64 size = -1
00118          );
00119 
00120    private:
00121       #ifndef GENERATING_DOXYGEN_OUTPUT
00122       // Copy constructor and assignment operator are private and unimplemented
00123       // Doesn't make sense to copy one.
00124       BASE64_DECODER(const BASE64_DECODER&);
00125       BASE64_DECODER& operator=(const BASE64_DECODER&);
00126       #endif // GENERATING_DOXYGEN_OUTPUT
00127 
00128       // Derived class must implemnt this.
00129       // Will be called as many times as needed as chunks of data are decoded
00130       // Should return 0 or an error code < 0
00131       virtual ERRVALUE v_Write (
00132          const UINT8* buffer,
00133          int numbytes
00134          ) = 0;
00135 
00136       // Derived class may override this method if it wants to show status or
00137       // implement cancel checking.  This method should return EUserCancel to
00138       // cancel the operation, 0 to continue.
00139       virtual ERRVALUE v_ShowStatus (
00140          double PercentDone
00141          );
00142 
00143    };
00144 
00145 #undef CLASSLIBEXPORT
00146 
00147 #endif
00148 

Generated on Thu Apr 26 04:44:52 2007 for TNTsdk by  doxygen 1.5.2