archive/File: eliminate Close(), make destructor virtual instead
This commit is contained in:
parent
5da455080b
commit
9aec2f019a
@ -22,19 +22,12 @@
|
||||
|
||||
class Mutex;
|
||||
class Cond;
|
||||
struct ArchivePlugin;
|
||||
class ArchiveVisitor;
|
||||
class InputStream;
|
||||
|
||||
class ArchiveFile {
|
||||
protected:
|
||||
/**
|
||||
* Use Close() instead of delete.
|
||||
*/
|
||||
~ArchiveFile() {}
|
||||
|
||||
public:
|
||||
virtual void Close() = 0;
|
||||
virtual ~ArchiveFile() noexcept = default;
|
||||
|
||||
/**
|
||||
* Visit all entries inside this archive.
|
||||
|
@ -49,10 +49,6 @@ public:
|
||||
name.erase(len - 4);
|
||||
}
|
||||
|
||||
virtual void Close() override {
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void Visit(ArchiveVisitor &visitor) override {
|
||||
visitor.VisitArchiveEntry(name.c_str());
|
||||
}
|
||||
|
@ -72,10 +72,6 @@ public:
|
||||
void Visit(char *path, size_t length, size_t capacity,
|
||||
ArchiveVisitor &visitor);
|
||||
|
||||
virtual void Close() override {
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void Visit(ArchiveVisitor &visitor) override;
|
||||
|
||||
InputStream *OpenStream(const char *path,
|
||||
|
@ -57,10 +57,6 @@ public:
|
||||
ZzipArchiveFile(std::shared_ptr<ZzipDir> &&_dir)
|
||||
:dir(std::move(_dir)) {}
|
||||
|
||||
virtual void Close() override {
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void Visit(ArchiveVisitor &visitor) override;
|
||||
|
||||
InputStream *OpenStream(const char *path,
|
||||
|
@ -177,7 +177,7 @@ UpdateWalk::UpdateArchiveFile(Directory &parent, const char *name,
|
||||
|
||||
UpdateArchiveVisitor visitor(*this, *file, directory);
|
||||
file->Visit(visitor);
|
||||
file->Close();
|
||||
delete file;
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -63,7 +63,7 @@ OpenArchiveInputStream(Path path, Mutex &mutex, Cond &cond)
|
||||
auto file = archive_file_open(arplug, Path::FromFS(archive));
|
||||
|
||||
AtScopeExit(file) {
|
||||
file->Close();
|
||||
delete file;
|
||||
};
|
||||
|
||||
return InputStreamPtr(file->OpenStream(filename, mutex, cond));
|
||||
|
@ -93,7 +93,7 @@ try {
|
||||
|
||||
MyArchiveVisitor visitor;
|
||||
file->Visit(visitor);
|
||||
file->Close();
|
||||
delete file;
|
||||
|
||||
return result;
|
||||
} catch (const std::exception &e) {
|
||||
|
Loading…
Reference in New Issue
Block a user