00001 /* 00002 | 00003 | $Id: plfilesink.cpp,v 1.1 2004/05/21 21:02:52 maxx Exp $ 00004 | File "Data Sink" Class 00005 | 00006 | This class a file as a destination for picture data. 00007 | 00008 | Copyright (c) 1996-1998 Ulrich von Zadow 00009 | 00010 \-------------------------------------------------------------------- 00011 */ 00012 00013 #include "plstdpch.h" 00014 00015 // not quite ready for prime-time; bdelmee; 2/99 00016 // this is a very simple-minded implementation suitable for 00017 // the needs of the TIFF encoder at this point 00018 00019 #include "plfilesink.h" 00020 #include "plexcept.h" 00021 00022 00023 PLFileSink::PLFileSink () 00024 : PLDataSink (), 00025 m_pFile (NULL), 00026 m_pDataBuf (NULL) 00027 { 00028 } 00029 00030 PLFileSink::~PLFileSink () 00031 { 00032 if (m_pFile) 00033 Close(); 00034 } 00035 00036 // Generic code assuming memory mapped files are not available. 00037 int PLFileSink::Open (const char * pszFName, int MaxFileSize) 00038 { 00039 00040 // we could actually open the file in "Close()", 00041 // but if e.g we cannot create it, it's pointless to proceed 00042 if ((m_pFile = fopen (pszFName, "wb")) && 00043 (m_pDataBuf = new PLBYTE [MaxFileSize])) 00044 { 00045 PLDataSink::Open(pszFName, m_pDataBuf, MaxFileSize); 00046 return 0; 00047 } 00048 else 00049 return -1; 00050 } 00051 00052 // now flush the data to disk 00053 void PLFileSink::Close () 00054 { 00055 int towrite = GetDataSize(); 00056 int written = fwrite( m_pStartData, 1, towrite, m_pFile ); 00057 PLASSERT( written == towrite ); 00058 fclose( m_pFile ); 00059 m_pFile = 0; 00060 00061 if (m_pDataBuf) 00062 { 00063 delete[] m_pDataBuf; 00064 m_pDataBuf = NULL; 00065 } 00066 00067 PLDataSink::Close(); 00068 } 00069 00070 /* 00071 /-------------------------------------------------------------------- 00072 | 00073 | $Log: plfilesink.cpp,v $ 00074 | Revision 1.1 2004/05/21 21:02:52 maxx 00075 | Initial Version of vuVolume, moderatly changed to make it compile on my windows and linux machine. 00076 | 00077 | Revision 1.1 2002/11/13 01:58:21 mspindle 00078 | *** empty log message *** 00079 | 00080 | Revision 1.2 2001/10/06 22:37:08 uzadow 00081 | Linux compatibility. 00082 | 00083 | Revision 1.1 2001/09/16 19:03:22 uzadow 00084 | Added global name prefix PL, changed most filenames. 00085 | 00086 | Revision 1.8 2001/02/04 14:31:52 uzadow 00087 | Member initialization list cleanup (Erik Hoffmann). 00088 | 00089 | Revision 1.7 2000/12/20 19:17:46 uzadow 00090 | FileSink::Close() now calls the base class Close() so 00091 | the file sink can be reopened. 00092 | 00093 | Revision 1.6 2000/12/09 12:16:26 uzadow 00094 | Fixed several memory leaks. 00095 | 00096 | Revision 1.5 2000/01/16 20:43:13 anonymous 00097 | Removed MFC dependencies 00098 | 00099 | Revision 1.4 2000/01/10 23:52:59 Ulrich von Zadow 00100 | Changed formatting & removed tabs. 00101 | 00102 | Revision 1.3 1999/10/03 18:50:51 Ulrich von Zadow 00103 | Added automatic logging of changes. 00104 | 00105 | 00106 -------------------------------------------------------------------- 00107 */