1 /****************************************************************************
2 ** libebml : parse EBML files, see http://embl.sourceforge.net/
4 ** <file/class description>
6 ** Copyright (C) 2003-2004 Jory Stone. All rights reserved.
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.
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.
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
22 ** See http://www.matroska.org/license/lgpl/ for LGPL licensing information.
24 ** Contact license@matroska.org if any conditions of this licensing are
27 **********************************************************************/
31 \version \$Id: MemIOCallback.h 1298 2008-02-21 22:14:18Z mosu $
32 \author Jory Stone <jcsston @ toughguy.net>
34 #ifndef LIBEBML_MEMIOCALLBACK_H
35 #define LIBEBML_MEMIOCALLBACK_H
37 #include "IOCallback.h"
39 #if (!defined(__BEOS__) && !defined(__HAIKU__))
43 #define stringstream strstream
46 START_LIBEBML_NAMESPACE
48 class EBML_DLL_API MemIOCallback
: public IOCallback
51 MemIOCallback(uint64 DefaultSize
= 128);
55 Use this to copy some data to the Buffer from this classes data
57 uint32
read(void *Buffer
, size_t Size
);
60 Seek to the specified position. The mode can have either SEEK_SET, SEEK_CUR
61 or SEEK_END. The callback should return true(1) if the seek operation succeeded
62 or false (0), when the seek fails.
64 void setFilePointer(int64 Offset
, seek_mode Mode
=seek_beginning
);
67 This callback just works like its read pendant. It returns the number of bytes written.
69 size_t write(const void *Buffer
, size_t Size
);
72 Although the position is always positive, the return value of this callback is signed to
73 easily allow negative values for returning errors. When an error occurs, the implementor
74 should return -1 and the file pointer otherwise.
76 If an error occurs, an exception should be thrown.
78 virtual uint64
getFilePointer() {return dataBufferPos
;};
81 The close callback flushes the file buffers to disk and closes the file. When using the stdio
82 library, this is equivalent to calling fclose. When the close is not successful, an exception
87 binary
*GetDataBuffer() const {return dataBuffer
;};
88 uint64
GetDataBufferSize() {return dataBufferTotalSize
;};
89 void SetDataBufferSize(uint64 newDataBufferSize
) {dataBufferTotalSize
= newDataBufferSize
;};
91 Use this to write some data from another IOCallback
93 uint32
write(IOCallback
& IOToRead
, size_t Size
);
95 bool IsOk() { return mOk
; };
96 const std::string
&GetLastErrorStr() { return mLastErrorStr
; };
99 std::string mLastErrorStr
;
103 Postion where we start 'writing' to the dataBuffer
105 uint64 dataBufferPos
;
107 Size of the data in the dataBuffer
109 uint64 dataBufferTotalSize
;
111 Size of the memory malloc()/realloc()
113 uint64 dataBufferMemorySize
;
116 END_LIBEBML_NAMESPACE
118 #endif // LIBEBML_MEMIOCALLBACK_H