00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef INCL_PLDATASNK
00013 #define INCL_PLDATASNK
00014
00015 #include "plexcept.h"
00016 #include "plpaintlibdefs.h"
00017
00018 #ifndef AFX_PLOBJECT_H__E40881E3_C809_11D3_97BC_0050046F615E__INCLUDED_
00019 #include "plobject.h"
00020 #endif
00021
00022 #include <stdio.h>
00023
00024
00025
00026 class PLDataSink : public PLObject
00027 {
00028
00029
00030
00031 friend class PLTIFFEncoder;
00032 friend class PLTIFFEncoderEx;
00033
00034 public:
00035
00036 void Open
00037 ( const char* pszName,
00038 PLBYTE* pData,
00039 size_t MaxDataSize
00040 );
00041 #ifdef _WINDOWS
00042
00043 void OpenW
00044 ( const wchar_t* pszwName,
00045 PLBYTE* pData,
00046 size_t MaxDataSize
00047 );
00048 #endif
00049
00050
00051 virtual void Close
00052 ();
00053
00054
00055 char* GetName
00056 ();
00057 #ifdef _WINDOWS
00058 wchar_t * GetNameW
00059 ();
00060
00061 bool NameIsWide
00062 ();
00063 #endif
00064
00065
00066
00067 PLBYTE* GetBufferPtr
00068 ();
00069
00070
00071 size_t GetDataSize
00072 ();
00073
00074
00075 size_t GetMaxDataSize
00076 ();
00077
00078
00079 size_t WriteNBytes
00080 ( size_t n,
00081 PLBYTE* pData
00082 );
00083
00084 void WriteByte
00085 ( PLBYTE Data
00086 );
00087
00088
00089 void Skip
00090 ( size_t n );
00091
00092
00093 void CheckEOF
00094 ();
00095
00096 protected:
00097 PLBYTE* m_pStartData;
00098 int m_nCurPos;
00099
00100
00101 PLDataSink
00102 ();
00103
00104
00105 virtual ~PLDataSink
00106 ();
00107
00108 private:
00109 char* m_pszName;
00110 #ifdef _WINDOWS
00111 wchar_t * m_pszwName;
00112 bool m_bNameIsWide;
00113 #endif
00114 size_t m_nMaxFileSize;
00115 };
00116
00117
00118 #ifdef _WINDOWS
00119 inline bool PLDataSink::NameIsWide
00120 ()
00121 {
00122 return m_bNameIsWide;
00123 }
00124 #endif
00125
00126 inline PLBYTE * PLDataSink::GetBufferPtr
00127 ()
00128 {
00129 return m_pStartData + m_nCurPos;
00130 }
00131
00132 inline size_t PLDataSink::GetMaxDataSize
00133 ()
00134 {
00135 return m_nMaxFileSize;
00136 }
00137
00138 inline size_t PLDataSink::GetDataSize
00139 ()
00140 {
00141
00142 return m_nCurPos;
00143 }
00144
00145 inline void PLDataSink::CheckEOF
00146 ()
00147 {
00148
00149 if (m_nCurPos > (int)m_nMaxFileSize)
00150 {
00151 throw PLTextException (PL_ERREND_OF_FILE,
00152 "Buffer overflow while encoding.\n");
00153 }
00154 }
00155
00156 inline void PLDataSink::Skip
00157 ( size_t n )
00158 {
00159
00160 m_nCurPos += (int)n;
00161 CheckEOF ();
00162 }
00163
00164 #endif // INCL_PLDATASNK
00165
00166
00167
00168