fs/io/TextFile: use std::unique_ptr<>

This commit is contained in:
Max Kellermann 2019-04-26 14:42:54 +02:00
parent 376f4a2b16
commit 6d86902a02
2 changed files with 12 additions and 17 deletions

View File

@ -26,28 +26,21 @@
#include <assert.h>
TextFile::TextFile(Path path_fs)
:file_reader(new FileReader(path_fs)),
:file_reader(std::make_unique<FileReader>(path_fs)),
#ifdef ENABLE_ZLIB
gunzip_reader(new AutoGunzipReader(*file_reader)),
gunzip_reader(std::make_unique<AutoGunzipReader>(*file_reader)),
#endif
buffered_reader(new BufferedReader(*
buffered_reader(std::make_unique<BufferedReader>(*
#ifdef ENABLE_ZLIB
gunzip_reader
gunzip_reader
#else
file_reader
file_reader
#endif
))
))
{
}
TextFile::~TextFile()
{
delete buffered_reader;
#ifdef ENABLE_ZLIB
delete gunzip_reader;
#endif
delete file_reader;
}
TextFile::~TextFile() = default;
char *
TextFile::ReadLine()

View File

@ -23,19 +23,21 @@
#include "util/Compiler.h"
#include "config.h"
#include <memory>
class Path;
class FileReader;
class AutoGunzipReader;
class BufferedReader;
class TextFile {
FileReader *const file_reader;
const std::unique_ptr<FileReader> file_reader;
#ifdef ENABLE_ZLIB
AutoGunzipReader *const gunzip_reader;
const std::unique_ptr<AutoGunzipReader> gunzip_reader;
#endif
BufferedReader *const buffered_reader;
const std::unique_ptr<BufferedReader> buffered_reader;
public:
explicit TextFile(Path path_fs);