00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef INCL_PLDATASRC
00012 #define INCL_PLDATASRC
00013
00014 #include "plexcept.h"
00015 #include "plpaintlibdefs.h"
00016
00017 #ifndef AFX_PLOBJECT_H__E40881E3_C809_11D3_97BC_0050046F615E__INCLUDED_
00018 #include "plobject.h"
00019 #endif
00020
00021 #ifdef _WINDOWS
00022 #include "stddef.h"
00023 #endif
00024
00025 class PLIProgressNotification;
00026
00027
00028
00029
00030
00031 class PLDataSource : public PLObject
00032 {
00033
00034 public:
00035
00036
00037
00038 PLDataSource
00039 ( PLIProgressNotification * pNotification = NULL
00040 );
00041
00042
00043 virtual ~PLDataSource
00044 ();
00045
00046
00047 virtual void Open
00048 ( const char * pszName,
00049 int FileSize
00050 );
00051
00052 #ifdef _WINDOWS
00053
00054 virtual void OpenW
00055 ( const wchar_t * pszwName,
00056 int FileSize
00057 );
00058 #endif
00059
00060
00061 virtual void Close
00062 ();
00063
00064
00065 char * GetName
00066 ();
00067
00068 #ifdef _WINDOWS
00069
00070 wchar_t * GetNameW
00071 ();
00072
00073
00074 bool NameIsWide
00075 ();
00076 #endif
00077
00078
00079 virtual PLBYTE * GetBufferPtr
00080 ( int MinBytesInBuffer
00081 ) = 0;
00082
00083
00084 virtual PLBYTE * ReadNBytes
00085 ( int n
00086 );
00087
00088
00089 int GetFileSize
00090 ();
00091
00092
00093
00094 virtual PLBYTE * ReadEverything
00095 () = 0;
00096
00097
00098 PLBYTE * Read1Byte
00099 ();
00100
00101
00102 PLBYTE * Read2Bytes
00103 ();
00104
00105
00106 PLBYTE * Read4Bytes
00107 ();
00108
00109
00110 void OProgressNotification
00111 ( double part
00112 );
00113
00114
00115 void AlignToWord
00116 ();
00117
00118
00119 void Skip
00120 ( int n
00121 );
00122
00123
00124 virtual void Seek
00125 ( int n
00126 ) = 0;
00127
00128
00129 void CheckEOF
00130 ();
00131
00132 protected:
00133
00134 private:
00135 char * m_pszName;
00136
00137 #ifdef _WINDOWS
00138 wchar_t * m_pszwName;
00139 bool m_bNameIsWide;
00140 #endif
00141 int m_FileSize;
00142 int m_BytesRead;
00143 bool m_bSrcLSBFirst;
00144
00145 PLIProgressNotification * m_pNotification;
00146 };
00147
00148
00149 #ifdef _WINDOWS
00150 inline bool PLDataSource::NameIsWide
00151 ()
00152 {
00153 return m_bNameIsWide;
00154 }
00155 #endif
00156
00157 inline int PLDataSource::GetFileSize
00158 ()
00159 {
00160 return m_FileSize;
00161 }
00162
00163 inline PLBYTE * PLDataSource::Read1Byte
00164 ()
00165 {
00166 return ReadNBytes (1);
00167 }
00168
00169
00170 inline PLBYTE * PLDataSource::Read2Bytes
00171 ()
00172 {
00173 return ReadNBytes (2);
00174 }
00175
00176
00177 inline PLBYTE * PLDataSource::Read4Bytes
00178 ()
00179 {
00180 return ReadNBytes (4);
00181 }
00182
00183 inline void PLDataSource::AlignToWord
00184 ()
00185 {
00186 if (m_BytesRead & 1)
00187 Read1Byte();
00188 }
00189
00190
00191 inline void PLDataSource::Skip
00192 ( int n
00193 )
00194 {
00195 ReadNBytes (n);
00196 }
00197
00198 inline void PLDataSource::CheckEOF
00199 ()
00200 {
00201
00202 if (m_FileSize < m_BytesRead)
00203 {
00204 throw PLTextException (PL_ERREND_OF_FILE,
00205 "End of file reached while decoding.\n");
00206 }
00207 }
00208
00209 #endif
00210
00211
00212
00213