00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "InputFileStream.h"
00023 #include "gzfilebuf.h"
00024 #include <iostream>
00025 #include <boost/algorithm/string/predicate.hpp>
00026
00027 using namespace std;
00028 using namespace boost::algorithm;
00029
00030 namespace Moses
00031 {
00032 InputFileStream::InputFileStream(const std::string &filePath)
00033 : std::istream(NULL)
00034 , m_streambuf(NULL)
00035 {
00036 Open(filePath);
00037 }
00038
00039 InputFileStream::~InputFileStream()
00040 {
00041 Close();
00042 }
00043
00044 void InputFileStream::Open(const std::string &filePath)
00045 {
00046 if (ends_with(filePath, ".gz")) {
00047 m_streambuf = new gzfilebuf(filePath.c_str());
00048 } else {
00049 std::filebuf* fb = new std::filebuf();
00050 fb = fb->open(filePath.c_str(), std::ios::in);
00051 if (! fb) {
00052 cerr << "Can't read " << filePath.c_str() << endl;
00053 exit(1);
00054 }
00055 m_streambuf = fb;
00056 }
00057 this->init(m_streambuf);
00058 }
00059
00060 void InputFileStream::Close()
00061 {
00062 delete m_streambuf;
00063 m_streambuf = NULL;
00064 }
00065
00066
00067 }
00068