#include <file_piece.hh>
Public Member Functions | |
FilePiece (const char *file, std::ostream *show_progress=NULL, std::size_t min_buffer=1048576) | |
FilePiece (int fd, const char *name=NULL, std::ostream *show_progress=NULL, std::size_t min_buffer=1048576) | |
FilePiece (std::istream &stream, const char *name=NULL, std::size_t min_buffer=1048576) | |
~FilePiece () | |
char | get () |
StringPiece | ReadDelimited (const bool *delim=kSpaces) |
bool | ReadWordSameLine (StringPiece &to, const bool *delim=kSpaces) |
Read word until the line or file ends. | |
StringPiece | ReadLine (char delim= '\n', bool strip_cr=true) |
bool | ReadLineOrEOF (StringPiece &to, char delim= '\n', bool strip_cr=true) |
float | ReadFloat () |
double | ReadDouble () |
long int | ReadLong () |
unsigned long int | ReadULong () |
void | SkipSpaces (const bool *delim=kSpaces) |
uint64_t | Offset () const |
const std::string & | FileName () const |
Definition at line 28 of file file_piece.hh.
util::FilePiece::FilePiece | ( | const char * | file, | |
std::ostream * | show_progress = NULL , |
|||
std::size_t | min_buffer = 1048576 | |||
) | [explicit] |
Definition at line 35 of file file_piece.cc.
util::FilePiece::FilePiece | ( | int | fd, | |
const char * | name = NULL , |
|||
std::ostream * | show_progress = NULL , |
|||
std::size_t | min_buffer = 1048576 | |||
) | [explicit] |
Definition at line 48 of file file_piece.cc.
util::FilePiece::FilePiece | ( | std::istream & | stream, | |
const char * | name = NULL , |
|||
std::size_t | min_buffer = 1048576 | |||
) | [explicit] |
Definition at line 54 of file file_piece.cc.
References util::scoped_memory::begin(), util::HugeMalloc(), and util::ReadCompressed::Reset().
util::FilePiece::~FilePiece | ( | ) |
Definition at line 66 of file file_piece.cc.
const std::string& util::FilePiece::FileName | ( | ) | const [inline] |
Definition at line 126 of file file_piece.hh.
Referenced by lm::ReadARPACounts().
char util::FilePiece::get | ( | ) | [inline] |
Definition at line 44 of file file_piece.hh.
Referenced by lm::ngram::Query(), lm::Read1Gram(), and lm::ReadBackoff().
uint64_t util::FilePiece::Offset | ( | ) | const [inline] |
Definition at line 122 of file file_piece.hh.
References util::scoped_memory::begin().
Referenced by lm::Read1Gram(), and lm::ReadNGram().
StringPiece util::FilePiece::ReadDelimited | ( | const bool * | delim = kSpaces |
) | [inline] |
Definition at line 53 of file file_piece.hh.
References SkipSpaces().
Referenced by lm::Read1Gram(), and lm::ReadNGram().
double util::FilePiece::ReadDouble | ( | ) |
Definition at line 104 of file file_piece.cc.
float util::FilePiece::ReadFloat | ( | ) |
Definition at line 101 of file file_piece.cc.
Referenced by lm::Read1Gram(), lm::ReadBackoff(), and lm::ReadNGram().
StringPiece util::FilePiece::ReadLine | ( | char | delim = '\n' , |
|
bool | strip_cr = true | |||
) |
Read a line of text from the file.
Unlike ReadDelimited, this includes leading spaces and consumes the delimiter. It is similar to getline in that way.
If strip_cr is true, any trailing carriate return (as would be found on a file written on Windows) will be left out of the returned line.
Throws EndOfFileException if the end of the file is encountered. If the file does not end in a newline, this could mean that the last line is never read.
Definition at line 68 of file file_piece.cc.
References skip.
Referenced by main(), MosesTuning::NextLine(), lm::ReadARPACounts(), lm::ReadCount(), lm::ReadEnd(), MosesTuning::ReadGraph(), ReadLineOrEOF(), lm::ReadNGramHeader(), lm::ReadNGrams(), and lm::builder::CorpusCount::Run().
bool util::FilePiece::ReadLineOrEOF | ( | StringPiece & | to, | |
char | delim = '\n' , |
|||
bool | strip_cr = true | |||
) |
Read a line of text from the file, or return false on EOF.
This is like ReadLine, except it returns false where ReadLine throws EndOfFileException. Like ReadLine it may not read the last line in the file if the file does not end in a newline.
If strip_cr is true, any trailing carriate return (as would be found on a file written on Windows) will be left out of the returned line.
Definition at line 94 of file file_piece.cc.
References ReadLine().
long int util::FilePiece::ReadLong | ( | ) |
Definition at line 107 of file file_piece.cc.
unsigned long int util::FilePiece::ReadULong | ( | ) |
Definition at line 110 of file file_piece.cc.
bool util::FilePiece::ReadWordSameLine | ( | StringPiece & | to, | |
const bool * | delim = kSpaces | |||
) | [inline] |
Read word until the line or file ends.
Definition at line 59 of file file_piece.hh.
Referenced by lm::ngram::Query().
void util::FilePiece::SkipSpaces | ( | const bool * | delim = kSpaces |
) | [inline] |
Definition at line 109 of file file_piece.hh.
Referenced by ReadDelimited().