1/**************************************************************************** 2** libebml : parse EBML files, see http://embl.sourceforge.net/ 3** 4** <file/class description> 5** 6** Copyright (C) 2002-2004 Ingo Ralf Blum. All rights reserved. 7** 8** This library is free software; you can redistribute it and/or 9** modify it under the terms of the GNU Lesser General Public 10** License as published by the Free Software Foundation; either 11** version 2.1 of the License, or (at your option) any later version. 12** 13** This library is distributed in the hope that it will be useful, 14** but WITHOUT ANY WARRANTY; without even the implied warranty of 15** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16** Lesser General Public License for more details. 17** 18** You should have received a copy of the GNU Lesser General Public 19** License along with this library; if not, write to the Free Software 20** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21** 22** See http://www.matroska.org/license/lgpl/ for LGPL licensing information. 23** 24** Contact license@matroska.org if any conditions of this licensing are 25** not clear to you. 26** 27**********************************************************************/ 28 29/*! 30 \file 31 \version \$Id: StdIOCallback.h 1090 2005-03-16 12:47:59Z robux4 $ 32*/ 33#ifndef LIBEBML_STDIOCALLBACK_H 34#define LIBEBML_STDIOCALLBACK_H 35 36#include "IOCallback.h" 37 38#include <stdexcept> 39#include <cerrno> 40 41// ----- Added 10/15/2003 by jcsston from Zen ----- 42#if defined (__BORLANDC__) //Maybe other compilers? 43 #include <errno.h> 44 #include <stdio.h> 45#endif //__BORLANDC__ 46// ------------------------------------------------ 47 48START_LIBEBML_NAMESPACE 49 50class EBML_DLL_API CRTError:public std::runtime_error 51{ 52// Variablen... 53private: 54 int Error; 55 56// Methoden... 57public: 58 CRTError(int Error,const std::string&Description); 59 CRTError(const std::string&Description,int Error=errno); 60 61 int getError()const throw(){return Error;} 62}; 63 64// This class is currently private to the library, so there's no MATROSKA_EXPORT. 65class EBML_DLL_API StdIOCallback:public IOCallback 66{ 67 private: 68 FILE*File; 69 uint64 mCurrentPosition; 70 71 public: 72// StdIOCallback(const char*Path,const char*Mode); 73 StdIOCallback(const char*Path, const open_mode Mode); 74 virtual ~StdIOCallback()throw(); 75 76 virtual uint32 read(void*Buffer,size_t Size); 77 78 // Seek to the specified position. The mode can have either SEEK_SET, SEEK_CUR 79 // or SEEK_END. The callback should return true(1) if the seek operation succeeded 80 // or false (0), when the seek fails. 81 virtual void setFilePointer(int64 Offset,seek_mode Mode=seek_beginning); 82 83 // This callback just works like its read pendant. It returns the number of bytes written. 84 virtual size_t write(const void*Buffer,size_t Size); 85 86 // Although the position is always positive, the return value of this callback is signed to 87 // easily allow negative values for returning errors. When an error occurs, the implementor 88 // should return -1 and the file pointer otherwise. 89 // 90 // If an error occurs, an exception should be thrown. 91 virtual uint64 getFilePointer(); 92 93 // The close callback flushes the file buffers to disk and closes the file. When using the stdio 94 // library, this is equivalent to calling fclose. When the close is not successful, an exception 95 // should be thrown. 96 virtual void close(); 97}; 98 99END_LIBEBML_NAMESPACE 100 101#endif 102