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

pldatasrc.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: pldatasrc_8h-source.html,v 1.4 2004/09/15 15:26:29 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 #ifdef _WINDOWS
00022 #include "stddef.h"
00023 #endif
00024 
00025 class PLIProgressNotification;
00026 
00027 //! This is a base class for a source of picture data.
00028 //! It defines methods to open, close, and read from data sources.
00029 //! Does byte-order-conversions in the ReadByte, ReadWord, and
00030 //! ReadLong routines.
00031 class PLDataSource : public PLObject
00032 {
00033 
00034 public:
00035 
00036   //! Constructs a new data source. pNotification points to an object that 
00037   //! reacts to progress notification messages.
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   //! Read but don't advance file pointer.
00079   virtual PLBYTE * GetBufferPtr
00080     ( int MinBytesInBuffer
00081     ) = 0;
00082 
00083   //! This needs to be overridden in derived classes.
00084   virtual PLBYTE * ReadNBytes
00085     ( int n
00086     );
00087 
00088   //!
00089   int GetFileSize
00090     ();
00091 
00092   //! This is a legacy routine that interferes with progress notifications.
00093   //! Don't call it!
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   //! handles progress notification from other libs
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   //! Test to see if we didn't go past the end of the file
00129   void CheckEOF
00130     ();
00131 
00132 protected:
00133 
00134 private:
00135   char * m_pszName;        // Name of the data source for diagnostic
00136                            // purposes.
00137 #ifdef _WINDOWS
00138   wchar_t * m_pszwName;       // Name in wide characters.
00139   bool      m_bNameIsWide;    // Is the name wide or not?
00140 #endif
00141   int    m_FileSize;
00142   int    m_BytesRead;
00143   bool   m_bSrcLSBFirst;   // Source byte order: true for intel order,
00144                            // false for Motorola et al. (MSB first).
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 |      $Log: pldatasrc_8h-source.html,v $
00213 |      Revision 1.4  2004/09/15 15:26:29  uzadow
00213 |      Linux compatibility changes, doc update.
00213 |
00214 |      Revision 1.7  2004/09/11 12:41:35  uzadow
00215 |      removed plstdpch.h
00216 |
00217 |      Revision 1.6  2004/08/20 14:39:37  uzadow
00218 |      Added rle format to sgi decoder. Doesn't work yet, though.
00219 |
00220 |      Revision 1.5  2004/06/06 12:56:38  uzadow
00221 |      Doxygenified documentation.
00222 |
00223 |      Revision 1.4  2003/08/03 12:03:20  uzadow
00224 |      Added unicode support; fixed some header includes.
00225 |
00226 |      Revision 1.3  2002/02/24 13:00:21  uzadow
00227 |      Documentation update; removed buggy PLFilterRotate.
00228 |
00229 |      Revision 1.2  2001/10/06 22:03:26  uzadow
00230 |      Added PL prefix to basic data types.
00231 |
00232 |      Revision 1.1  2001/09/16 19:03:22  uzadow
00233 |      Added global name prefix PL, changed most filenames.
00234 |
00235 |      Revision 1.5  2000/10/24 22:59:34  uzadow
00236 |      no message
00237 |
00238 |
00239 \--------------------------------------------------------------------
00240 */

Generated on Mon Sep 13 16:16:40 2004 for paintlib by doxygen 1.3.2