fs/io/TextFile: split into class FileLineReader and AutoGunzipFileLineReader
Detangle dependencies.
This commit is contained in:
@@ -26,7 +26,8 @@
|
||||
#include "util/StringSplit.hxx"
|
||||
#include "util/StringStrip.hxx"
|
||||
#include "util/StringCompare.hxx"
|
||||
#include "fs/io/TextFile.hxx"
|
||||
#include "io/FileLineReader.hxx"
|
||||
|
||||
#include <string.h>
|
||||
#include <utility>
|
||||
#endif
|
||||
@@ -230,7 +231,7 @@ try {
|
||||
if (config_dir.IsNull())
|
||||
return result;
|
||||
|
||||
TextFile input(config_dir / Path::FromFS("user-dirs.dirs"));
|
||||
FileLineReader input{config_dir / Path::FromFS("user-dirs.dirs")};
|
||||
char *line;
|
||||
while ((line = input.ReadLine()) != nullptr)
|
||||
if (ParseConfigLine(line, name, result))
|
||||
|
@@ -5,7 +5,7 @@ fs_glue = static_library(
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
fs_dep,
|
||||
fs_io_dep,
|
||||
io_dep,
|
||||
fmt_dep,
|
||||
log_dep,
|
||||
util_dep,
|
||||
|
@@ -1,35 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#include "TextFile.hxx"
|
||||
#include "io/FileReader.hxx"
|
||||
#include "io/BufferedReader.hxx"
|
||||
#include "lib/zlib/AutoGunzipReader.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
TextFile::TextFile(Path path_fs)
|
||||
:file_reader(std::make_unique<FileReader>(path_fs)),
|
||||
#ifdef ENABLE_ZLIB
|
||||
gunzip_reader(std::make_unique<AutoGunzipReader>(*file_reader)),
|
||||
#endif
|
||||
buffered_reader(std::make_unique<BufferedReader>(*
|
||||
#ifdef ENABLE_ZLIB
|
||||
gunzip_reader
|
||||
#else
|
||||
file_reader
|
||||
#endif
|
||||
))
|
||||
{
|
||||
}
|
||||
|
||||
TextFile::~TextFile() noexcept = default;
|
||||
|
||||
char *
|
||||
TextFile::ReadLine()
|
||||
{
|
||||
assert(buffered_reader != nullptr);
|
||||
|
||||
return buffered_reader->ReadLine();
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
// Copyright The Music Player Daemon Project
|
||||
|
||||
#ifndef MPD_TEXT_FILE_HXX
|
||||
#define MPD_TEXT_FILE_HXX
|
||||
|
||||
#include "io/LineReader.hxx"
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
class Path;
|
||||
class FileReader;
|
||||
class AutoGunzipReader;
|
||||
class BufferedReader;
|
||||
|
||||
class TextFile final : public LineReader {
|
||||
const std::unique_ptr<FileReader> file_reader;
|
||||
|
||||
#ifdef ENABLE_ZLIB
|
||||
const std::unique_ptr<AutoGunzipReader> gunzip_reader;
|
||||
#endif
|
||||
|
||||
const std::unique_ptr<BufferedReader> buffered_reader;
|
||||
|
||||
public:
|
||||
explicit TextFile(Path path_fs);
|
||||
|
||||
TextFile(const TextFile &other) = delete;
|
||||
|
||||
~TextFile() noexcept;
|
||||
|
||||
/* virtual methods from class LineReader */
|
||||
char *ReadLine() override;
|
||||
};
|
||||
|
||||
#endif
|
@@ -1,18 +0,0 @@
|
||||
fs_io = static_library(
|
||||
'fs_io',
|
||||
'TextFile.cxx',
|
||||
include_directories: inc,
|
||||
dependencies: [
|
||||
fs_dep,
|
||||
io_fs_dep,
|
||||
system_dep,
|
||||
zlib_dep,
|
||||
],
|
||||
)
|
||||
|
||||
fs_io_dep = declare_dependency(
|
||||
link_with: fs_io,
|
||||
dependencies: [
|
||||
io_dep,
|
||||
],
|
||||
)
|
Reference in New Issue
Block a user