Mercurial > audlegacy-plugins
annotate src/adplug/core/binio_virtual.h @ 1404:ab7d89bb8fcb
Switched to new threading model
author | Christian Birchinger <joker@netswarm.net> |
---|---|
date | Sat, 04 Aug 2007 21:37:11 +0200 |
parents | cae46214b8bf |
children | fa9f85cebade |
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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
30 this->fd = 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
34 this->fd = 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
38 this->fd = 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
42 this->fd = 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
47 int c = vfs_getc(this->fd); |
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: |
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
58 vfs_fseek(this->fd, pos, SEEK_CUR); |
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: |
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
61 vfs_fseek(this->fd, pos, SEEK_END); |
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: |
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
65 vfs_fseek(this->fd, pos, SEEK_SET); |
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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
72 return 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
90 this->fd = 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
94 this->fd = 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
98 this->fd = 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
102 this->fd = 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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
107 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: |
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
114 vfs_fseek(this->fd, pos, SEEK_CUR); |
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: |
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
117 vfs_fseek(this->fd, pos, SEEK_END); |
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: |
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
121 vfs_fseek(this->fd, pos, SEEK_SET); |
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) { |
352
7fc7b66c8a53
[svn] - you know, it'd help if binio were better documented.
nenolod
parents:
339
diff
changeset
|
128 return 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 |