archive/File: eliminate Close(), make destructor virtual instead

This commit is contained in:
Max Kellermann 2017-12-22 16:30:17 +01:00
parent 5da455080b
commit 9aec2f019a
7 changed files with 4 additions and 23 deletions

View File

@ -22,19 +22,12 @@
class Mutex; class Mutex;
class Cond; class Cond;
struct ArchivePlugin;
class ArchiveVisitor; class ArchiveVisitor;
class InputStream; class InputStream;
class ArchiveFile { class ArchiveFile {
protected:
/**
* Use Close() instead of delete.
*/
~ArchiveFile() {}
public: public:
virtual void Close() = 0; virtual ~ArchiveFile() noexcept = default;
/** /**
* Visit all entries inside this archive. * Visit all entries inside this archive.

View File

@ -49,10 +49,6 @@ public:
name.erase(len - 4); name.erase(len - 4);
} }
virtual void Close() override {
delete this;
}
virtual void Visit(ArchiveVisitor &visitor) override { virtual void Visit(ArchiveVisitor &visitor) override {
visitor.VisitArchiveEntry(name.c_str()); visitor.VisitArchiveEntry(name.c_str());
} }

View File

@ -72,10 +72,6 @@ public:
void Visit(char *path, size_t length, size_t capacity, void Visit(char *path, size_t length, size_t capacity,
ArchiveVisitor &visitor); ArchiveVisitor &visitor);
virtual void Close() override {
delete this;
}
virtual void Visit(ArchiveVisitor &visitor) override; virtual void Visit(ArchiveVisitor &visitor) override;
InputStream *OpenStream(const char *path, InputStream *OpenStream(const char *path,

View File

@ -57,10 +57,6 @@ public:
ZzipArchiveFile(std::shared_ptr<ZzipDir> &&_dir) ZzipArchiveFile(std::shared_ptr<ZzipDir> &&_dir)
:dir(std::move(_dir)) {} :dir(std::move(_dir)) {}
virtual void Close() override {
delete this;
}
virtual void Visit(ArchiveVisitor &visitor) override; virtual void Visit(ArchiveVisitor &visitor) override;
InputStream *OpenStream(const char *path, InputStream *OpenStream(const char *path,

View File

@ -177,7 +177,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
UpdateArchiveVisitor visitor(*this, *file, directory); UpdateArchiveVisitor visitor(*this, *file, directory);
file->Visit(visitor); file->Visit(visitor);
file->Close(); delete file;
} }
bool bool

View File

@ -63,7 +63,7 @@ OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond)
auto file = archive_file_open(arplug, Path::FromFS(archive)); auto file = archive_file_open(arplug, Path::FromFS(archive));
AtScopeExit(file) { AtScopeExit(file) {
file->Close(); delete file;
}; };
return InputStreamPtr(file->OpenStream(filename, mutex, cond)); return InputStreamPtr(file->OpenStream(filename, mutex, cond));

View File

@ -93,7 +93,7 @@ try {
MyArchiveVisitor visitor; MyArchiveVisitor visitor;
file->Visit(visitor); file->Visit(visitor);
file->Close(); delete file;
return result; return result;
} catch (const std::exception &e) { } catch (const std::exception &e) {