00001 /**************************************************************************** 00002 ** libebml : parse EBML files, see http://embl.sourceforge.net/ 00003 ** 00004 ** <file/class description> 00005 ** 00006 ** Copyright (C) 2002-2004 Ingo Ralf Blum. All rights reserved. 00007 ** 00008 ** This library is free software; you can redistribute it and/or 00009 ** modify it under the terms of the GNU Lesser General Public 00010 ** License as published by the Free Software Foundation; either 00011 ** version 2.1 of the License, or (at your option) any later version. 00012 ** 00013 ** This library is distributed in the hope that it will be useful, 00014 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 ** Lesser General Public License for more details. 00017 ** 00018 ** You should have received a copy of the GNU Lesser General Public 00019 ** License along with this library; if not, write to the Free Software 00020 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 ** 00022 ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. 00023 ** 00024 ** Contact license@matroska.org if any conditions of this licensing are 00025 ** not clear to you. 00026 ** 00027 **********************************************************************/ 00028 00033 #ifndef LIBEBML_STDIOCALLBACK_H 00034 #define LIBEBML_STDIOCALLBACK_H 00035 00036 #include "IOCallback.h" 00037 00038 #include <stdexcept> 00039 #include <cerrno> 00040 00041 // ----- Added 10/15/2003 by jcsston from Zen ----- 00042 #if defined (__BORLANDC__) //Maybe other compilers? 00043 #include <errno.h> 00044 #include <stdio.h> 00045 #endif //__BORLANDC__ 00046 // ------------------------------------------------ 00047 00048 START_LIBEBML_NAMESPACE 00049 00050 class EBML_DLL_API CRTError:public std::runtime_error 00051 { 00052 // Variablen... 00053 private: 00054 int Error; 00055 00056 // Methoden... 00057 public: 00058 CRTError(int Error,const std::string&Description); 00059 CRTError(const std::string&Description,int Error=errno); 00060 00061 int getError()const throw(){return Error;} 00062 }; 00063 00064 // This class is currently private to the library, so there's no MATROSKA_EXPORT. 00065 class EBML_DLL_API StdIOCallback:public IOCallback 00066 { 00067 private: 00068 FILE*File; 00069 uint64 mCurrentPosition; 00070 00071 public: 00072 // StdIOCallback(const char*Path,const char*Mode); 00073 StdIOCallback(const char*Path, const open_mode Mode); 00074 virtual ~StdIOCallback()throw(); 00075 00076 virtual uint32 read(void*Buffer,size_t Size); 00077 00078 // Seek to the specified position. The mode can have either SEEK_SET, SEEK_CUR 00079 // or SEEK_END. The callback should return true(1) if the seek operation succeeded 00080 // or false (0), when the seek fails. 00081 virtual void setFilePointer(int64 Offset,seek_mode Mode=seek_beginning); 00082 00083 // This callback just works like its read pendant. It returns the number of bytes written. 00084 virtual size_t write(const void*Buffer,size_t Size); 00085 00086 // Although the position is always positive, the return value of this callback is signed to 00087 // easily allow negative values for returning errors. When an error occurs, the implementor 00088 // should return -1 and the file pointer otherwise. 00089 // 00090 // If an error occurs, an exception should be thrown. 00091 virtual uint64 getFilePointer(); 00092 00093 // The close callback flushes the file buffers to disk and closes the file. When using the stdio 00094 // library, this is equivalent to calling fclose. When the close is not successful, an exception 00095 // should be thrown. 00096 virtual void close(); 00097 }; 00098 00099 END_LIBEBML_NAMESPACE 00100 00101 #endif