#include <FileHandler.h>
Public Member Functions | |
FileHandler (const std::string &path, std::ios_base::openmode flags=std::ios::in, bool checkExists=true) | |
~FileHandler () | |
std::string | getPath () |
std::ios_base::openmode | getFlags () |
bool | isStdIn () |
bool | isStdOut () |
bool | reset () |
Static Public Member Functions | |
static bool | getCompressionCmds (const std::string &filepath, std::string &compressionCmd, std::string &decompressionCmd, std::string &compressionSuffix) |
Static Public Attributes | |
static const std::string | kStdInDescriptor = "___stdin___" |
static const std::string | kStdOutDescriptor = "___stdout___" |
static const std::string | kCatCommand = "cat" |
static const std::string | kGzipCommand = "gzip -f" |
static const std::string | kGunzipCommand = "gunzip -f" |
static const std::string | kBzip2Command = "bzip2 -f" |
static const std::string | kBunzip2Command = "bunzip2 -f" |
Protected Member Functions | |
bool | fileExists () |
bool | setStreamBuffer (bool checkExists) |
bool | isCompressedFile (std::string &cmd) |
fdstreambuf * | openCompressedFile (const char *cmd) |
Protected Attributes | |
std::string | path_ |
std::ios_base::openmode | flags_ |
std::streambuf * | buffer_ |
std::FILE * | fp_ |
Static Protected Attributes | |
static const FileExtension | kGzipped = ".gz" |
static const FileExtension | kBzipped2 = ".bz2" |
Definition at line 19 of file FileHandler.h.
Moses::FileHandler::FileHandler | ( | const std::string & | path, | |
std::ios_base::openmode | flags = std::ios::in , |
|||
bool | checkExists = true | |||
) |
Definition at line 27 of file FileHandler.cpp.
References path_, setStreamBuffer(), and UTIL_THROW_IF2.
Moses::FileHandler::~FileHandler | ( | ) |
Definition at line 40 of file FileHandler.cpp.
References buffer_, fp_, kStdInDescriptor, kStdOutDescriptor, path_, and pclose().
bool Moses::FileHandler::fileExists | ( | ) | [protected] |
Definition at line 135 of file FileHandler.cpp.
References path_.
Referenced by setStreamBuffer().
bool Moses::FileHandler::getCompressionCmds | ( | const std::string & | filepath, | |
std::string & | compressionCmd, | |||
std::string & | decompressionCmd, | |||
std::string & | compressionSuffix | |||
) | [static] |
Definition at line 146 of file FileHandler.cpp.
References kBunzip2Command, kBzip2Command, kBzipped2, kCatCommand, kGunzipCommand, kGzipCommand, and kGzipped.
std::ios_base::openmode Moses::FileHandler::getFlags | ( | ) | [inline] |
std::string Moses::FileHandler::getPath | ( | ) | [inline] |
bool Moses::FileHandler::isCompressedFile | ( | std::string & | cmd | ) | [protected] |
Definition at line 113 of file FileHandler.cpp.
References flags_, kBunzip2Command, kBzip2Command, kBzipped2, kGunzipCommand, kGzipCommand, kGzipped, and path_.
Referenced by reset(), and setStreamBuffer().
bool Moses::FileHandler::isStdIn | ( | ) | [inline] |
bool Moses::FileHandler::isStdOut | ( | ) | [inline] |
fdstreambuf * Moses::FileHandler::openCompressedFile | ( | const char * | cmd | ) | [protected] |
Definition at line 53 of file FileHandler.cpp.
References flags_, fp_, NULL, and popen().
Referenced by reset(), and setStreamBuffer().
bool Moses::FileHandler::reset | ( | ) |
Definition at line 169 of file FileHandler.cpp.
References buffer_, fp_, init(), isCompressedFile(), openCompressedFile(), and pclose().
bool Moses::FileHandler::setStreamBuffer | ( | bool | checkExists | ) | [protected] |
Definition at line 72 of file FileHandler.cpp.
References buffer_, fileExists(), flags_, init(), isCompressedFile(), kStdInDescriptor, kStdOutDescriptor, openCompressedFile(), path_, and UTIL_THROW_IF2.
Referenced by FileHandler().
std::streambuf* Moses::FileHandler::buffer_ [protected] |
Definition at line 66 of file FileHandler.h.
Referenced by reset(), setStreamBuffer(), and ~FileHandler().
std::ios_base::openmode Moses::FileHandler::flags_ [protected] |
Definition at line 65 of file FileHandler.h.
Referenced by getFlags(), isCompressedFile(), openCompressedFile(), and setStreamBuffer().
std::FILE* Moses::FileHandler::fp_ [protected] |
Definition at line 67 of file FileHandler.h.
Referenced by openCompressedFile(), reset(), and ~FileHandler().
const std::string Moses::FileHandler::kBunzip2Command = "bunzip2 -f" [static] |
Definition at line 30 of file FileHandler.h.
Referenced by getCompressionCmds(), and isCompressedFile().
const std::string Moses::FileHandler::kBzip2Command = "bzip2 -f" [static] |
Definition at line 29 of file FileHandler.h.
Referenced by getCompressionCmds(), and isCompressedFile().
const FileExtension Moses::FileHandler::kBzipped2 = ".bz2" [static, protected] |
Definition at line 59 of file FileHandler.h.
Referenced by getCompressionCmds(), and isCompressedFile().
const std::string Moses::FileHandler::kCatCommand = "cat" [static] |
const std::string Moses::FileHandler::kGunzipCommand = "gunzip -f" [static] |
Definition at line 28 of file FileHandler.h.
Referenced by getCompressionCmds(), and isCompressedFile().
const std::string Moses::FileHandler::kGzipCommand = "gzip -f" [static] |
Definition at line 27 of file FileHandler.h.
Referenced by getCompressionCmds(), and isCompressedFile().
const FileExtension Moses::FileHandler::kGzipped = ".gz" [static, protected] |
Definition at line 58 of file FileHandler.h.
Referenced by getCompressionCmds(), and isCompressedFile().
const std::string Moses::FileHandler::kStdInDescriptor = "___stdin___" [static] |
Definition at line 23 of file FileHandler.h.
Referenced by isStdIn(), setStreamBuffer(), and ~FileHandler().
const std::string Moses::FileHandler::kStdOutDescriptor = "___stdout___" [static] |
Definition at line 24 of file FileHandler.h.
Referenced by isStdOut(), setStreamBuffer(), and ~FileHandler().
std::string Moses::FileHandler::path_ [protected] |
Definition at line 64 of file FileHandler.h.
Referenced by fileExists(), FileHandler(), getPath(), isCompressedFile(), isStdIn(), isStdOut(), setStreamBuffer(), and ~FileHandler().