Mercurial > audlegacy-plugins
diff src/adplug/core/binio_virtual.h @ 339:d19ac60697ec trunk
[svn] - implement virtual class to use VFS through binio
- update the places where binio is used directly to use vfs[io]stream instead of bin[io]stream, respectively
- make CFileProvider use vfsistream instead of binifstream.
| author | nenolod |
|---|---|
| date | Wed, 06 Dec 2006 07:37:05 -0800 |
| parents | |
| children | 7fc7b66c8a53 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/adplug/core/binio_virtual.h Wed Dec 06 07:37:05 2006 -0800 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2006 William Pitcock <nenolod -at- atheme.org> + * This code is in the public domain. + */ + +#ifndef __BINIO_VIRTUAL__ +#define __BINIO_VIRTUAL__ + +#include <binio.h> +#include <binstr.h> + +#include <string> + +#include <glib.h> +#include <audacious/vfs.h> + +class vfsistream : public binistream, virtual public binio { +private: + VFSFile *fd; + +public: + vfsistream() {}; + + vfsistream(const char *file) { + fd = vfs_fopen(file, "rb"); + }; + + vfsistream(std::string &file) { + fd = vfs_fopen(file.c_str(), "rb"); + }; + + ~vfsistream() { + if (fd != NULL) + vfs_fclose(fd); + }; + + void open(const char *file) { + fd = vfs_fopen(file, "rb"); + }; + + void open(std::string &file) { + fd = vfs_fopen(file.c_str(), "rb"); + }; + + // XXX: this sucks because binio won't let us do sanity checking + Byte getByte(void) { + return vfs_getc(fd); + }; + + void seek(long pos, Offset offs = Set) { + vfs_fseek(fd, pos, offs == Set ? SEEK_SET : SEEK_CUR); + } + + long pos(void) { + return vfs_ftell(fd); + } +}; + +// XXX: binio sucks and doesn't let us just combine the two. +class vfsostream : public binostream, virtual public binio { +private: + VFSFile *fd; + +public: + vfsostream() {}; + + vfsostream(const char *file) { + fd = vfs_fopen(file, "wb"); + }; + + vfsostream(std::string &file) { + fd = vfs_fopen(file.c_str(), "wb"); + }; + + ~vfsostream() { + if (fd != NULL) + vfs_fclose(fd); + }; + + void open(const char *file) { + fd = vfs_fopen(file, "wb"); + }; + + void open(std::string &file) { + fd = vfs_fopen(file.c_str(), "wb"); + }; + + // XXX: this sucks because binio won't let us do sanity checking + void putByte(Byte b) { + vfs_fwrite(&b, 1, 1, fd); + }; + + void seek(long pos, Offset offs = Set) { + vfs_fseek(fd, pos, offs == Set ? SEEK_SET : SEEK_CUR); + } + + long pos(void) { + return vfs_ftell(fd); + } +}; + +#endif
