Mercurial > audlegacy-plugins
annotate src/adplug/core/binio_virtual.h @ 1978:fa9f85cebade
s/vfs_/aud_vfs_/g
| author | William Pitcock <nenolod@atheme.org> |
|---|---|
| date | Sun, 07 Oct 2007 00:25:33 -0500 |
| parents | cae46214b8bf |
| children | b0ff8640f338 |
| rev | line source |
|---|---|
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
1 /* |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
2 * Copyright (c) 2006 William Pitcock <nenolod -at- atheme.org> |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
3 * This code is in the public domain. |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
4 */ |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
5 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
6 #ifndef __BINIO_VIRTUAL__ |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
7 #define __BINIO_VIRTUAL__ |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
8 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
9 #include <binio.h> |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
10 #include <binstr.h> |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
11 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
12 #include <string> |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
13 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
14 #include <glib.h> |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
15 #include <audacious/vfs.h> |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
16 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
17 class vfsistream : public binistream, virtual public binio { |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
18 private: |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
19 VFSFile *fd; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
20 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
21 public: |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
22 vfsistream() {}; |
| 703 | 23 ~vfsistream() {}; |
| 24 | |
| 25 vfsistream(VFSFile *fd) { | |
| 26 this->fd = fd; | |
| 27 }; | |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
28 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
29 vfsistream(const char *file) { |
| 1978 | 30 this->fd = aud_vfs_fopen(file, "rb"); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
31 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
32 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
33 vfsistream(std::string &file) { |
| 1978 | 34 this->fd = aud_vfs_fopen(file.c_str(), "rb"); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
35 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
36 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
37 void open(const char *file) { |
| 1978 | 38 this->fd = aud_vfs_fopen(file, "rb"); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
39 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
40 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
41 void open(std::string &file) { |
| 1978 | 42 this->fd = aud_vfs_fopen(file.c_str(), "rb"); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
43 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
44 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
45 // XXX: this sucks because binio won't let us do sanity checking |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
46 Byte getByte(void) { |
| 1978 | 47 int c = aud_vfs_getc(this->fd); |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
48 |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
49 if (c == EOF) err |= Eof; |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
50 |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
51 return (Byte) c; |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
52 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
53 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
54 void seek(long pos, Offset offs = Set) { |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
55 switch (offs) |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
56 { |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
57 case Add: |
| 1978 | 58 aud_vfs_fseek(this->fd, pos, SEEK_CUR); |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
59 break; |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
60 case End: |
| 1978 | 61 aud_vfs_fseek(this->fd, pos, SEEK_END); |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
62 break; |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
63 case Set: |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
64 default: |
| 1978 | 65 aud_vfs_fseek(this->fd, pos, SEEK_SET); |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
66 break; |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
67 } |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
68 |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
69 } |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
70 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
71 long pos(void) { |
| 1978 | 72 return aud_vfs_ftell(this->fd); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
73 } |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
74 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
75 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
76 // XXX: binio sucks and doesn't let us just combine the two. |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
77 class vfsostream : public binostream, virtual public binio { |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
78 private: |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
79 VFSFile *fd; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
80 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
81 public: |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
82 vfsostream() {}; |
| 703 | 83 ~vfsostream() {}; |
| 84 | |
| 85 vfsostream(VFSFile *fd) { | |
| 86 this->fd = fd; | |
| 87 }; | |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
88 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
89 vfsostream(const char *file) { |
| 1978 | 90 this->fd = aud_vfs_fopen(file, "wb"); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
91 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
92 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
93 vfsostream(std::string &file) { |
| 1978 | 94 this->fd = aud_vfs_fopen(file.c_str(), "wb"); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
95 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
96 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
97 void open(const char *file) { |
| 1978 | 98 this->fd = aud_vfs_fopen(file, "wb"); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
99 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
100 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
101 void open(std::string &file) { |
| 1978 | 102 this->fd = aud_vfs_fopen(file.c_str(), "wb"); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
103 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
104 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
105 // XXX: this sucks because binio won't let us do sanity checking |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
106 void putByte(Byte b) { |
| 1978 | 107 aud_vfs_fwrite(&b, 1, 1, this->fd); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
108 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
109 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
110 void seek(long pos, Offset offs = Set) { |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
111 switch (offs) |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
112 { |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
113 case Add: |
| 1978 | 114 aud_vfs_fseek(this->fd, pos, SEEK_CUR); |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
115 break; |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
116 case End: |
| 1978 | 117 aud_vfs_fseek(this->fd, pos, SEEK_END); |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
118 break; |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
119 case Set: |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
120 default: |
| 1978 | 121 aud_vfs_fseek(this->fd, pos, SEEK_SET); |
|
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
122 break; |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
123 } |
|
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
124 |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
125 } |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
126 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
127 long pos(void) { |
| 1978 | 128 return aud_vfs_ftell(this->fd); |
|
339
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
129 } |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
130 }; |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
131 |
|
d19ac60697ec
[svn] - implement virtual class to use VFS through binio
nenolod
parents:
diff
changeset
|
132 #endif |
