Main Page | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members

pldatasrc.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: pldatasrc.h,v 1.4 2003/08/03 12:03:20 uzadow Exp $
00005 |
00006 |      Copyright (c) 1996-2002 Ulrich von Zadow
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 class PLIProgressNotification;
00022 
00023 //! This is a base class for a source of picture data.
00024 //! It defines methods to open, close, and read from data sources.
00025 //! Does byte-order-conversions in the ReadByte, ReadWord, and
00026 //! ReadLong routines.
00027 class PLDataSource : public PLObject
00028 {
00029 
00030 public:
00031 
00032   //! Constructs a new data source. pNotification points to an object that 
00033   //! reacts to progress notification messages.
00034   PLDataSource
00035     ( PLIProgressNotification * pNotification = NULL
00036     );
00037 
00038   //!
00039   virtual ~PLDataSource
00040     ();
00041 
00042   //! 
00043   virtual void Open
00044     ( const char * pszName,
00045       int    FileSize
00046     );
00047 
00048 #ifdef _WINDOWS
00049   //!
00050   virtual void OpenW
00051     ( const wchar_t * pszwName,
00052       int    FileSize
00053     );
00054 #endif
00055 
00056   //!
00057   virtual void Close
00058     ();
00059 
00060   //!
00061   char * GetName
00062     ();
00063 
00064 #ifdef _WINDOWS
00065   //!
00066   wchar_t * GetNameW
00067     ();
00068 
00069   //!
00070   bool NameIsWide
00071     ();
00072 #endif
00073 
00074   //! Read but don't advance file pointer.
00075   virtual PLBYTE * GetBufferPtr
00076     ( int MinBytesInBuffer
00077     ) = 0;
00078 
00079   //! This needs to be overridden in derived classes.
00080   virtual PLBYTE * ReadNBytes
00081     ( int n
00082     );
00083 
00084   //!
00085   int GetFileSize
00086     ();
00087 
00088   //! This is a legacy routine that interferes with progress notifications.
00089   //! Don't call it!
00090   virtual PLBYTE * ReadEverything
00091     () = 0;
00092 
00093   //!
00094   PLBYTE * Read1Byte
00095     ();
00096 
00097   //!
00098   PLBYTE * Read2Bytes
00099     ();
00100 
00101   //!
00102   PLBYTE * Read4Bytes
00103     ();
00104 
00105   //! handles progress notification from other libs
00106   void OProgressNotification
00107     ( double part
00108     );
00109 
00110   //!
00111   void AlignToWord
00112     ();
00113 
00114   //!
00115   void Skip
00116     ( int n
00117     );
00118 
00119   //! Test to see if we didn't go past the end of the file
00120   void CheckEOF
00121     ();
00122 
00123 protected:
00124 
00125 private:
00126   char * m_pszName;        // Name of the data source for diagnostic
00127                            // purposes.
00128 #ifdef _WINDOWS
00129   wchar_t * m_pszwName;       // Name in wide characters.
00130   bool      m_bNameIsWide;    // Is the name wide or not?
00131 #endif
00132   int    m_FileSize;
00133   int    m_BytesRead;
00134   bool   m_bSrcLSBFirst;   // Source byte order: true for intel order,
00135                            // false for Motorola et al. (MSB first).
00136   PLIProgressNotification * m_pNotification;
00137 };
00138 
00139 
00140 #ifdef _WINDOWS
00141 inline bool PLDataSource::NameIsWide
00142       ()
00143 {
00144   return m_bNameIsWide;
00145 }
00146 #endif
00147 
00148 inline int PLDataSource::GetFileSize
00149     ()
00150 {
00151   return m_FileSize;
00152 }
00153 
00154 inline PLBYTE * PLDataSource::Read1Byte
00155     ()
00156 {
00157   return ReadNBytes (1);
00158 }
00159 
00160 
00161 inline PLBYTE * PLDataSource::Read2Bytes
00162     ()
00163 {
00164   return ReadNBytes (2);
00165 }
00166 
00167 
00168 inline PLBYTE * PLDataSource::Read4Bytes
00169     ()
00170 {
00171   return ReadNBytes (4);
00172 }
00173 
00174 inline void PLDataSource::AlignToWord
00175     ()
00176 {
00177   if (m_BytesRead & 1)
00178     Read1Byte();
00179 }
00180 
00181 
00182 inline void PLDataSource::Skip
00183     ( int n
00184     )
00185 {
00186   ReadNBytes (n);
00187 }
00188 
00189 inline void PLDataSource::CheckEOF
00190     ()
00191 {
00192 
00193   if (m_FileSize < m_BytesRead)
00194   {
00195     throw PLTextException (PL_ERREND_OF_FILE,
00196           "End of file reached while decoding.\n");
00197   }
00198 }
00199 
00200 #endif
00201 /*
00202 /--------------------------------------------------------------------
00203 |
00204 |      $Log: pldatasrc.h,v $
00205 |      Revision 1.4  2003/08/03 12:03:20  uzadow
00206 |      Added unicode support; fixed some header includes.
00207 |
00208 |      Revision 1.3  2002/02/24 13:00:21  uzadow
00209 |      Documentation update; removed buggy PLFilterRotate.
00210 |
00211 |      Revision 1.2  2001/10/06 22:03:26  uzadow
00212 |      Added PL prefix to basic data types.
00213 |
00214 |      Revision 1.1  2001/09/16 19:03:22  uzadow
00215 |      Added global name prefix PL, changed most filenames.
00216 |
00217 |      Revision 1.5  2000/10/24 22:59:34  uzadow
00218 |      no message
00219 |
00220 |
00221 \--------------------------------------------------------------------
00222 */

Generated on Sun Jun 6 13:42:22 2004 for paintlib by doxygen 1.3.2