TextFile.hxx 1.81 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright (C) 2003-2015 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * http://www.musicpd.org
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

20 21
#ifndef MPD_TEXT_FILE_HXX
#define MPD_TEXT_FILE_HXX
22

23
#include "check.h"
24
#include "Compiler.h"
25

26
#include <stddef.h>
27 28

class Path;
29 30
class Error;
class FileReader;
31
class AutoGunzipReader;
32
class BufferedReader;
33

34
class TextFile {
35
	FileReader *const file_reader;
36

37
#ifdef ENABLE_ZLIB
38 39 40
	AutoGunzipReader *const gunzip_reader;
#endif

41
	BufferedReader *const buffered_reader;
42 43

public:
44
	TextFile(Path path_fs, Error &error);
45 46 47

	TextFile(const TextFile &other) = delete;

48
	~TextFile();
49 50

	bool HasFailed() const {
51
		return gcc_unlikely(buffered_reader == nullptr);
52 53 54 55 56 57 58
	}

	/**
	 * Reads a line from the input file, and strips trailing
	 * space.  There is a reasonable maximum line length, only to
	 * prevent denial of service.
	 *
59 60 61
	 * Use Check() after nullptr has been returned to check
	 * whether an error occurred or end-of-file has been reached.
	 *
62
	 * @return a pointer to the line, or nullptr on end-of-file or error
63 64
	 */
	char *ReadLine();
65 66 67 68 69

	/**
	 * Check whether a ReadLine() call has thrown an error.
	 */
	bool Check(Error &error) const;
70
};
71 72

#endif