diff options
author | nicolabertoldi <nicolabertoldi@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-20 18:15:30 +0400 |
---|---|---|
committer | nicolabertoldi <nicolabertoldi@1f5c12ca-751b-0410-a591-d2e778427230> | 2008-05-20 18:15:30 +0400 |
commit | 8a594fc254c520b62700b56fb14534be36394e06 (patch) | |
tree | ba2a8fa7eddbdf08a5b9cefff5b247094fc909cb /mert/Util.cpp | |
parent | f30000b87575f969e1ef9ac87ef1eaccecb1ec4e (diff) |
reading from textual gzipped file is now possible
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@1786 1f5c12ca-751b-0410-a591-d2e778427230
Diffstat (limited to 'mert/Util.cpp')
-rw-r--r-- | mert/Util.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/mert/Util.cpp b/mert/Util.cpp index 67c1053d5..4531a8645 100644 --- a/mert/Util.cpp +++ b/mert/Util.cpp @@ -6,6 +6,7 @@ * */ +#include <stdexcept> #include "Util.h" int verbose=0; @@ -37,3 +38,57 @@ int getNextPound(std::string &theString, std::string &substring, const std::stri } return (pos); }; + +inputfilestream::inputfilestream(const std::string &filePath) +: std::istream(0), +m_streambuf(0) +{ + //check if file is readable + std::filebuf* fb = new std::filebuf(); + _good=(fb->open(filePath.c_str(), std::ios::in)!=NULL); + + if (filePath.size() > 3 && + filePath.substr(filePath.size() - 3, 3) == ".gz") + { + fb->close(); delete fb; + m_streambuf = new gzfilebuf(filePath.c_str()); + } else { + m_streambuf = fb; + } + this->init(m_streambuf); +} + +inputfilestream::~inputfilestream() +{ + delete m_streambuf; m_streambuf = 0; +} + +void inputfilestream::close() +{ +} + +outputfilestream::outputfilestream(const std::string &filePath) +: std::ostream(0), +m_streambuf(0) +{ + //check if file is readable + std::filebuf* fb = new std::filebuf(); + _good=(fb->open(filePath.c_str(), std::ios::out)!=NULL); + + if (filePath.size() > 3 && filePath.substr(filePath.size() - 3, 3) == ".gz") + { + throw runtime_error("Output to a zipped file not supported!"); + } else { + m_streambuf = fb; + } + this->init(m_streambuf); +} + +outputfilestream::~outputfilestream() +{ + delete m_streambuf; m_streambuf = 0; +} + +void outputfilestream::close() +{ +} |