Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pldatasink.cpp

Go to the documentation of this file.
00001 /*
00002 /--------------------------------------------------------------------
00003 |
00004 |      $Id: pldatasink.cpp,v 1.1 2004/05/21 21:02:52 maxx Exp $
00005 |      Data Destination Base Class
00006 |
00007 |      This is a base class for a destination of picture data.
00008 |      It defines methods to open, write to, and close data sources.
00009 |
00010 |      Copyright (c) 1996-2002 Ulrich von Zadow
00011 |
00012 \--------------------------------------------------------------------
00013 */
00014 
00015 #include "plstdpch.h"
00016 
00017 #include "pldatasink.h"
00018 
00019 
00020 PLDataSink::PLDataSink() 
00021 : PLObject(),
00022   m_pStartData(NULL),
00023   m_nCurPos(0),
00024   m_pszName(NULL),
00025   m_nMaxFileSize(0)
00026 {  
00027 }
00028 
00029 
00030 PLDataSink::~PLDataSink
00031     ()
00032 {
00033   if (m_pStartData)
00034     Close();
00035 }
00036 
00037 
00038 // the actual data buffer is allocated in the derived classes
00039 void PLDataSink::Open
00040     ( const char * pszName,
00041       PLBYTE*  pData,
00042       size_t MaxFileSize
00043     )
00044 {
00045   // Data source may not be open already!
00046   PLASSERT (! m_pStartData);
00047   PLASSERT (MaxFileSize > 0);
00048 
00049   m_nMaxFileSize = MaxFileSize;
00050   // unchecked memory allocation, here!
00051   m_pszName = new char [strlen (pszName)+1];
00052   strcpy (m_pszName, pszName);
00053   m_pStartData = pData;
00054   m_nCurPos = 0;
00055 }
00056 
00057 
00058 void PLDataSink::Close
00059     ()
00060 {
00061   if (m_pszName)
00062   { delete [] m_pszName; m_pszName = NULL; }
00063   m_pStartData = NULL;
00064   m_nCurPos = 0;
00065 }
00066 
00067 
00068 char * PLDataSink::GetName
00069     ()
00070 {
00071   return m_pszName;
00072 }
00073 
00074 size_t PLDataSink::WriteNBytes
00075     ( size_t   n,
00076     PLBYTE* pData
00077     )
00078 {
00079   if (m_nCurPos+n > m_nMaxFileSize)
00080     throw PLTextException (PL_ERREND_OF_FILE,
00081           "Buffer overflow while encoding.\n");
00082 
00083   memcpy(m_pStartData + m_nCurPos, pData, n);
00084   m_nCurPos += n;
00085   return n;
00086 }
00087 
00088 void PLDataSink::WriteByte
00089     ( PLBYTE Data
00090     )
00091 {
00092   *(m_pStartData + m_nCurPos) = Data;
00093   m_nCurPos ++;
00094 }
00095 
00096 /*
00097 /--------------------------------------------------------------------
00098 |
00099 |      $Log: pldatasink.cpp,v $
00100 |      Revision 1.1  2004/05/21 21:02:52  maxx
00101 |      Initial Version of vuVolume, moderatly changed to make it compile on my windows and linux machine.
00102 |
00103 |      Revision 1.1  2002/11/13 01:58:21  mspindle
00104 |      *** empty log message ***
00105 |
00106 |      Revision 1.4  2002/02/24 13:00:19  uzadow
00107 |      Documentation update; removed buggy PLFilterRotate.
00108 |
00109 |      Revision 1.3  2001/10/06 22:03:26  uzadow
00110 |      Added PL prefix to basic data types.
00111 |
00112 |      Revision 1.2  2001/10/06 20:44:45  uzadow
00113 |      Linux compatibility
00114 |
00115 |      Revision 1.1  2001/09/16 19:03:22  uzadow
00116 |      Added global name prefix PL, changed most filenames.
00117 |
00118 |      Revision 1.8  2001/02/04 14:31:52  uzadow
00119 |      Member initialization list cleanup (Erik Hoffmann).
00120 |
00121 |      Revision 1.7  2001/01/21 14:28:21  uzadow
00122 |      Changed array cleanup from delete to delete[].
00123 |
00124 |      Revision 1.6  2000/12/20 19:17:46  uzadow
00125 |      FileSink::Close() now calls the base class Close() so
00126 |      the file sink can be reopened.
00127 |
00128 |      Revision 1.5  2000/01/16 20:43:13  anonymous
00129 |      Removed MFC dependencies
00130 |
00131 |      Revision 1.4  1999/10/19 21:23:23  Ulrich von Zadow
00132 |      Martin Skinner: Added WriteNBytes()
00133 |
00134 |      Revision 1.3  1999/10/03 18:50:51  Ulrich von Zadow
00135 |      Added automatic logging of changes.
00136 |
00137 |
00138 --------------------------------------------------------------------
00139 */

Generated on Wed Dec 15 21:20:30 2004 for vuVolume by  doxygen 1.3.9.1