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 class PLIProgressNotification;
00018
00023 class PLDataSource : public PLObject
00024 {
00025
00026 public:
00027
00029 PLDataSource
00030 ( PLIProgressNotification * pNotification = NULL
00031 );
00032
00034 virtual ~PLDataSource
00035 ();
00036
00038 virtual void Open
00039 ( const char * pszName,
00040 int FileSize
00041 );
00042
00044 virtual void Close
00045 ();
00046
00048 char * GetName
00049 ();
00050
00052 virtual PLBYTE * GetBufferPtr
00053 ( int MinBytesInBuffer
00054 ) = 0;
00055
00057 virtual PLBYTE * ReadNBytes
00058 ( int n
00059 );
00060
00062 int GetFileSize
00063 ();
00064
00067 virtual PLBYTE * ReadEverything
00068 () = 0;
00069
00071 PLBYTE * Read1Byte
00072 ();
00073
00075 PLBYTE * Read2Bytes
00076 ();
00077
00079 PLBYTE * Read4Bytes
00080 ();
00081
00082
00084 void OProgressNotification
00085 ( double part
00086 );
00087
00089 void AlignToWord
00090 ();
00091
00093 void Skip
00094 ( int n
00095 );
00096
00098 void CheckEOF
00099 ();
00100
00101 protected:
00102
00103 private:
00104 char * m_pszName;
00105
00106 int m_FileSize;
00107 int m_BytesRead;
00108 bool m_bSrcLSBFirst;
00109
00110 PLIProgressNotification * m_pNotification;
00111 };
00112
00113
00114 inline int PLDataSource::GetFileSize
00115 ()
00116 {
00117 return m_FileSize;
00118 }
00119
00120 inline PLBYTE * PLDataSource::Read1Byte
00121 ()
00122 {
00123 return ReadNBytes (1);
00124 }
00125
00126
00127 inline PLBYTE * PLDataSource::Read2Bytes
00128 ()
00129 {
00130 return ReadNBytes (2);
00131 }
00132
00133
00134 inline PLBYTE * PLDataSource::Read4Bytes
00135 ()
00136 {
00137 return ReadNBytes (4);
00138 }
00139
00140 inline void PLDataSource::AlignToWord
00141 ()
00142 {
00143 if (m_BytesRead & 1)
00144 Read1Byte();
00145 }
00146
00147
00148 inline void PLDataSource::Skip
00149 ( int n
00150 )
00151 {
00152 ReadNBytes (n);
00153 }
00154
00155 inline void PLDataSource::CheckEOF
00156 ()
00157 {
00158
00159 if (m_FileSize < m_BytesRead)
00160 {
00161 throw PLTextException (PL_ERREND_OF_FILE,
00162 "End of file reached while decoding.\n");
00163 }
00164 }
00165
00166 #endif
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191