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> #include <assert.h>
TextFile::TextFile(Path path_fs) TextFile::TextFile(Path path_fs)
:file_reader(new FileReader(path_fs)), :file_reader(std::make_unique<FileReader>(path_fs)),
#ifdef ENABLE_ZLIB #ifdef ENABLE_ZLIB
gunzip_reader(new AutoGunzipReader(*file_reader)), gunzip_reader(std::make_unique<AutoGunzipReader>(*file_reader)),
#endif #endif
buffered_reader(new BufferedReader(* buffered_reader(std::make_unique<BufferedReader>(*
#ifdef ENABLE_ZLIB #ifdef ENABLE_ZLIB
gunzip_reader gunzip_reader
#else #else
file_reader file_reader
#endif #endif
)) ))
{ {
} }
TextFile::~TextFile() TextFile::~TextFile() = default;
{
delete buffered_reader;
#ifdef ENABLE_ZLIB
delete gunzip_reader;
#endif
delete file_reader;
}
char * char *
TextFile::ReadLine() TextFile::ReadLine()

View File

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