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/
|
|
|
|
|
2014-03-21 17:28:17 +01:00
|
|
|
#include <iosfwd>
|
2013-02-17 04:47:31 +01:00
|
|
|
#include <memory>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <string>
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <libaegisub/fs_fwd.h>
|
2010-07-07 04:41:46 +02:00
|
|
|
#include <libaegisub/line_iterator.h>
|
2010-06-03 22:32:25 +02:00
|
|
|
|
2014-03-21 17:28:17 +01:00
|
|
|
namespace agi { class read_file_mapping; }
|
|
|
|
|
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 {
|
2014-03-21 17:28:17 +01:00
|
|
|
std::unique_ptr<agi::read_file_mapping> file;
|
|
|
|
std::unique_ptr<std::istream> stream;
|
2006-01-16 22:02:54 +01:00
|
|
|
bool trim;
|
2013-01-04 16:01:50 +01:00
|
|
|
agi::line_iterator<std::string> iter;
|
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
|
2013-04-13 17:15:36 +02:00
|
|
|
TextFileReader(agi::fs::path const& filename, std::string 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
|
2013-01-04 16:01:50 +01:00
|
|
|
std::string ReadLineFromFile();
|
2010-01-24 19:56:51 +01:00
|
|
|
/// @brief Check if there are any more lines to read
|
2013-01-04 16:01:50 +01:00
|
|
|
bool HasMoreLines() const { return iter != agi::line_iterator<std::string>(); }
|
2010-01-24 19:56:51 +01:00
|
|
|
};
|