2012-12-02 22:14:24 +01:00
|
|
|
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2012-12-02 22:14:24 +01:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2012-12-02 22:14:24 +01:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file text_file_reader.h
|
|
|
|
/// @see text_file_reader.cpp
|
|
|
|
/// @ingroup utility
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2007-04-13 04:05:38 +02:00
|
|
|
#pragma once
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2008-03-05 19:52:09 +01:00
|
|
|
#include <fstream>
|
2010-06-03 22:32:25 +02:00
|
|
|
#include <memory>
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-09-11 04:36:34 +02:00
|
|
|
#include <wx/dynarray.h>
|
|
|
|
#include <wx/string.h>
|
|
|
|
|
2010-07-07 04:41:46 +02:00
|
|
|
#include <libaegisub/line_iterator.h>
|
2010-06-03 22:32:25 +02:00
|
|
|
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
/// @class TextFileReader
|
2010-01-24 19:56:51 +01:00
|
|
|
/// @brief A line-based text file reader
|
2006-01-16 22:02:54 +01:00
|
|
|
class TextFileReader {
|
2012-11-16 00:46:56 +01:00
|
|
|
std::unique_ptr<std::ifstream> file;
|
2006-01-16 22:02:54 +01:00
|
|
|
bool trim;
|
2010-07-07 04:41:46 +02:00
|
|
|
agi::line_iterator<wxString> iter;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-07-18 02:58:13 +02:00
|
|
|
TextFileReader(const TextFileReader&);
|
|
|
|
TextFileReader& operator=(const TextFileReader&);
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
public:
|
2010-01-24 19:56:51 +01:00
|
|
|
/// @brief Constructor
|
|
|
|
/// @param filename File to open
|
|
|
|
/// @param enc Encoding to use, or empty to autodetect
|
|
|
|
/// @param trim Whether to trim whitespace from lines read
|
2011-09-28 21:43:11 +02:00
|
|
|
TextFileReader(wxString const& filename,wxString encoding="", bool trim=true);
|
2010-01-24 19:56:51 +01:00
|
|
|
/// @brief Destructor
|
2006-01-16 22:02:54 +01:00
|
|
|
~TextFileReader();
|
|
|
|
|
2010-01-24 19:56:51 +01:00
|
|
|
/// @brief Read a line from the file
|
|
|
|
/// @return The line, possibly trimmed
|
2006-01-16 22:02:54 +01:00
|
|
|
wxString ReadLineFromFile();
|
2010-01-24 19:56:51 +01:00
|
|
|
/// @brief Check if there are any more lines to read
|
2010-07-07 04:41:46 +02:00
|
|
|
bool HasMoreLines() const { return iter != agi::line_iterator<wxString>(); }
|
2010-01-24 19:56:51 +01:00
|
|
|
};
|