From f5c0b0d3168d6c34010f86a4b6878b7181d10237 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 29 Jan 2013 23:26:51 +0100 Subject: ArchiveFile: convert to a class --- src/archive/Bzip2ArchivePlugin.cxx | 23 ++++++++++------------- src/archive/Iso9660ArchivePlugin.cxx | 22 +++++++++------------- src/archive/ZzipArchivePlugin.cxx | 21 +++++++++------------ 3 files changed, 28 insertions(+), 38 deletions(-) (limited to 'src/archive') diff --git a/src/archive/Bzip2ArchivePlugin.cxx b/src/archive/Bzip2ArchivePlugin.cxx index f93718128..daa04b975 100644 --- a/src/archive/Bzip2ArchivePlugin.cxx +++ b/src/archive/Bzip2ArchivePlugin.cxx @@ -23,8 +23,8 @@ #include "config.h" #include "Bzip2ArchivePlugin.hxx" -#include "ArchiveInternal.hxx" #include "ArchivePlugin.hxx" +#include "ArchiveFile.hxx" #include "ArchiveVisitor.hxx" #include "InputInternal.hxx" #include "InputStream.hxx" @@ -42,17 +42,14 @@ #define BZ2_bzDecompress bzDecompress #endif -struct Bzip2ArchiveFile { - struct archive_file base; - +class Bzip2ArchiveFile : public ArchiveFile { +public: RefCount ref; char *name; struct input_stream *istream; - Bzip2ArchiveFile() { - archive_file_init(&base, &bz2_archive_plugin); - } + Bzip2ArchiveFile():ArchiveFile(bz2_archive_plugin) {} void Unref() { if (!ref.Decrement()) @@ -123,7 +120,7 @@ Bzip2InputStream::Close() /* archive open && listing routine */ -static struct archive_file * +static ArchiveFile * bz2_open(const char *pathname, GError **error_r) { Bzip2ArchiveFile *context = new Bzip2ArchiveFile(); @@ -147,11 +144,11 @@ bz2_open(const char *pathname, GError **error_r) context->name[len - 4] = 0; //remove .bz2 suffix } - return &context->base; + return context; } static void -bz2_visit(archive_file *file, ArchiveVisitor &visitor) +bz2_visit(ArchiveFile *file, ArchiveVisitor &visitor) { Bzip2ArchiveFile *context = (Bzip2ArchiveFile *) file; @@ -159,7 +156,7 @@ bz2_visit(archive_file *file, ArchiveVisitor &visitor) } static void -bz2_close(struct archive_file *file) +bz2_close(ArchiveFile *file) { Bzip2ArchiveFile *context = (Bzip2ArchiveFile *) file; @@ -178,11 +175,11 @@ Bzip2InputStream::Bzip2InputStream(Bzip2ArchiveFile &_context, const char *uri, Bzip2InputStream::~Bzip2InputStream() { - bz2_close(&archive->base); + archive->Unref(); } static struct input_stream * -bz2_open_stream(struct archive_file *file, const char *path, +bz2_open_stream(ArchiveFile *file, const char *path, Mutex &mutex, Cond &cond, GError **error_r) { diff --git a/src/archive/Iso9660ArchivePlugin.cxx b/src/archive/Iso9660ArchivePlugin.cxx index 344cdac6a..21e2fa41c 100644 --- a/src/archive/Iso9660ArchivePlugin.cxx +++ b/src/archive/Iso9660ArchivePlugin.cxx @@ -23,8 +23,8 @@ #include "config.h" #include "Iso9660ArchivePlugin.hxx" -#include "ArchiveInternal.hxx" #include "ArchivePlugin.hxx" +#include "ArchiveFile.hxx" #include "ArchiveVisitor.hxx" #include "InputInternal.hxx" #include "InputStream.hxx" @@ -41,17 +41,14 @@ #define CEILING(x, y) ((x+(y-1))/y) -struct Iso9660ArchiveFile { - struct archive_file base; - +class Iso9660ArchiveFile : public ArchiveFile { +public: RefCount ref; iso9660_t *iso; Iso9660ArchiveFile(iso9660_t *_iso) - :iso(_iso) { - archive_file_init(&base, &iso9660_archive_plugin); - } + :ArchiveFile(iso9660_archive_plugin), iso(_iso) {} ~Iso9660ArchiveFile() { iso9660_close(iso); @@ -107,7 +104,7 @@ Iso9660ArchiveFile::Visit(const char *psz_path, ArchiveVisitor &visitor) _cdio_list_free (entlist, true); } -static struct archive_file * +static ArchiveFile * iso9660_archive_open(const char *pathname, GError **error_r) { /* open archive */ @@ -118,12 +115,11 @@ iso9660_archive_open(const char *pathname, GError **error_r) return NULL; } - Iso9660ArchiveFile *archive = new Iso9660ArchiveFile(iso); - return &archive->base; + return new Iso9660ArchiveFile(iso); } static void -iso9660_archive_visit(archive_file *file, ArchiveVisitor &visitor) +iso9660_archive_visit(ArchiveFile *file, ArchiveVisitor &visitor) { Iso9660ArchiveFile *context = (Iso9660ArchiveFile *)file; @@ -132,7 +128,7 @@ iso9660_archive_visit(archive_file *file, ArchiveVisitor &visitor) } static void -iso9660_archive_close(struct archive_file *file) +iso9660_archive_close(ArchiveFile *file) { Iso9660ArchiveFile *context = (Iso9660ArchiveFile *)file; @@ -170,7 +166,7 @@ struct Iso9660InputStream { }; static struct input_stream * -iso9660_archive_open_stream(struct archive_file *file, const char *pathname, +iso9660_archive_open_stream(ArchiveFile *file, const char *pathname, Mutex &mutex, Cond &cond, GError **error_r) { diff --git a/src/archive/ZzipArchivePlugin.cxx b/src/archive/ZzipArchivePlugin.cxx index 1b089a484..ba001bdd5 100644 --- a/src/archive/ZzipArchivePlugin.cxx +++ b/src/archive/ZzipArchivePlugin.cxx @@ -23,8 +23,8 @@ #include "config.h" #include "ZzipArchivePlugin.hxx" -#include "ArchiveInternal.hxx" #include "ArchivePlugin.hxx" +#include "ArchiveFile.hxx" #include "ArchiveVisitor.hxx" #include "InputInternal.hxx" #include "InputStream.hxx" @@ -35,16 +35,13 @@ #include #include -struct ZzipArchiveFile { - struct archive_file base; - +class ZzipArchiveFile : public ArchiveFile { +public: RefCount ref; ZZIP_DIR *dir; - ZzipArchiveFile() { - archive_file_init(&base, &zzip_archive_plugin); - } + ZzipArchiveFile():ArchiveFile(zzip_archive_plugin) {} void Unref() { if (!ref.Decrement()) @@ -69,7 +66,7 @@ zzip_quark(void) /* archive open && listing routine */ -static struct archive_file * +static ArchiveFile * zzip_archive_open(const char *pathname, GError **error_r) { ZzipArchiveFile *context = new ZzipArchiveFile(); @@ -82,7 +79,7 @@ zzip_archive_open(const char *pathname, GError **error_r) return NULL; } - return &context->base; + return context; } inline void @@ -98,7 +95,7 @@ ZzipArchiveFile::Visit(ArchiveVisitor &visitor) } static void -zzip_archive_visit(archive_file *file, ArchiveVisitor &visitor) +zzip_archive_visit(ArchiveFile *file, ArchiveVisitor &visitor) { ZzipArchiveFile *context = (ZzipArchiveFile *) file; @@ -106,7 +103,7 @@ zzip_archive_visit(archive_file *file, ArchiveVisitor &visitor) } static void -zzip_archive_close(struct archive_file *file) +zzip_archive_close(ArchiveFile *file) { ZzipArchiveFile *context = (ZzipArchiveFile *) file; @@ -145,7 +142,7 @@ struct ZzipInputStream { }; static struct input_stream * -zzip_archive_open_stream(struct archive_file *file, +zzip_archive_open_stream(ArchiveFile *file, const char *pathname, Mutex &mutex, Cond &cond, GError **error_r) -- cgit v1.2.3