/src/vlc/contrib/x86_64-unknown-linux-gnu/include/ebml/IOCallback.h
Line | Count | Source |
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
21 | | ** |
22 | | ** See http://www.gnu.org/licenses/lgpl-2.1.html 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: IOCallback.h 639 2004-07-09 20:59:14Z mosu $ |
32 | | */ |
33 | | #ifndef MATROSKA_IOCALLBACK_H |
34 | | #define MATROSKA_IOCALLBACK_H |
35 | | |
36 | | #include "EbmlTypes.h" |
37 | | |
38 | | #include <cassert> |
39 | | #include <exception> |
40 | | #include <cstdio> |
41 | | // #include <iostream> |
42 | | |
43 | | |
44 | | namespace libebml { |
45 | | |
46 | | enum seek_mode |
47 | | { |
48 | | seek_beginning=SEEK_SET |
49 | | ,seek_end=SEEK_END |
50 | | ,seek_current=SEEK_CUR |
51 | | }; |
52 | | |
53 | | class EBML_DLL_API IOCallback |
54 | | { |
55 | | public: |
56 | 11.8k | virtual ~IOCallback() = default; |
57 | | |
58 | | // The read callback works like most other read functions. You specify the |
59 | | // file, the buffer and the size and the function returns the bytes read. |
60 | | // If an error occurs or the file pointer points to the end of the file 0 is returned. |
61 | | // Users are encouraged to throw a descriptive exception, when an error occurs. |
62 | | virtual uint32 read(void*Buffer,size_t Size)=0; |
63 | | |
64 | | // Seek to the specified position. The mode can have either SEEK_SET, SEEK_CUR |
65 | | // or SEEK_END. The callback should return true(1) if the seek operation succeeded |
66 | | // or false (0), when the seek fails. |
67 | | virtual void setFilePointer(int64 Offset,seek_mode Mode=seek_beginning)=0; |
68 | | |
69 | | // This callback just works like its read pendant. It returns the number of bytes written. |
70 | | virtual size_t write(const void*Buffer,size_t Size)=0; |
71 | | |
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. |
75 | | // |
76 | | // If an error occurs, an exception should be thrown. |
77 | | virtual uint64 getFilePointer()=0; |
78 | | |
79 | | // The close callback flushes the file buffers to disk and closes the file. When using the stdio |
80 | | // library, this is equivalent to calling fclose. When the close is not successful, an exception |
81 | | // should be thrown. |
82 | | virtual void close()=0; |
83 | | |
84 | | |
85 | | // The readFully is made virtual to allow derived classes to use another |
86 | | // implementation for this method, which e.g. does not read any data |
87 | | // unlike this does |
88 | | void readFully(void*Buffer,size_t Size); |
89 | | |
90 | | template<class STRUCT> void readStruct(STRUCT&Struct){readFully(&Struct,sizeof(Struct));} |
91 | | |
92 | | void writeFully(const void*Buffer,size_t Size); |
93 | | |
94 | | template<class STRUCT> void writeStruct(const STRUCT&Struct){writeFully(&Struct,sizeof(Struct));} |
95 | | }; |
96 | | |
97 | | /* cygwin incompatible |
98 | | template<class TRAITS> std::basic_ostream<char,TRAITS>&operator<<(std::basic_ostream<char,TRAITS>&Stream,seek_mode Mode) |
99 | | { |
100 | | switch(Mode) |
101 | | { |
102 | | #define x(y) case seek_##y: Stream<<"seek_" #y; break |
103 | | x(beginning); |
104 | | x(current); |
105 | | x(end); |
106 | | #undef x |
107 | | default: |
108 | | assert(false); |
109 | | } |
110 | | |
111 | | return Stream; |
112 | | } |
113 | | */ |
114 | | |
115 | | } // namespace libebml |
116 | | |
117 | | #endif // MATROSKA_IOCALLBACK_H |