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

pldatasink.h

00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: pldatasink.h,v 1.5 2003/08/03 12:03:20 uzadow Exp $
00005 |
00006 |      Copyright (c) 1996-2002 Ulrich von Zadow
00007 |
00008 \--------------------------------------------------------------------
00009 */
00010 // not quite ready for prime-time; bdelmee; 2/99
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 //! This is a base class for a destination of picture data.
00025 //! It defines methods to open, write to, close data sinks.
00026 class PLDataSink : public PLObject
00027 {
00028   // I'd like to get rid of this, but now it is needed so the encoders
00029   // can maintain the actually useful length of the buffer.
00030   // TODO: Get rid of this!!
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   //! Test to see if we didn't go past the "end of the file"
00093   void CheckEOF
00094     ();
00095 
00096 protected:
00097   PLBYTE* m_pStartData;
00098   int   m_nCurPos;   // this SHOULD be an unsigned int (size_t), but TIFFLib wants an int
00099 
00100   //!
00101   PLDataSink
00102     ();
00103 
00104   //!
00105   virtual ~PLDataSink
00106    ();
00107 
00108 private:
00109   char*  m_pszName;    // Name of the data source for diagnostic purposes
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   // return currently used buffer size
00142   return m_nCurPos;
00143 }
00144 
00145 inline void PLDataSink::CheckEOF
00146     ()
00147 {
00148   //if (GetFileSize() > GetMaxFileSize())
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         // maybe we should fill the gap with nulls
00160   m_nCurPos += (int)n;
00161   CheckEOF ();
00162 }
00163 
00164 #endif  // INCL_PLDATASNK
00165 /*
00166 /--------------------------------------------------------------------
00167 |
00168 |      $Log: pldatasink.h,v $
00169 |      Revision 1.5  2003/08/03 12:03:20  uzadow
00170 |      Added unicode support; fixed some header includes.
00171 |
00172 |      Revision 1.4  2002/02/24 13:00:20  uzadow
00173 |      Documentation update; removed buggy PLFilterRotate.
00174 |
00175 |      Revision 1.3  2001/10/06 22:03:26  uzadow
00176 |      Added PL prefix to basic data types.
00177 |
00178 |      Revision 1.2  2001/10/06 20:44:45  uzadow
00179 |      Linux compatibility
00180 |
00181 |      Revision 1.1  2001/09/16 19:03:22  uzadow
00182 |      Added global name prefix PL, changed most filenames.
00183 |
00184 |      Revision 1.5  2000/01/16 20:43:13  anonymous
00185 |      Removed MFC dependencies
00186 |
00187 |      Revision 1.4  2000/01/08 15:56:12  Ulrich von Zadow
00188 |      Made sure change logging works in every file.
00189 |
00190 |
00191 \--------------------------------------------------------------------
00192 */

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