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 if (ends_with(filePath, ".gz")) {
00037 m_streambuf = new gzfilebuf(filePath.c_str());
00038 } else {
00039 std::filebuf* fb = new std::filebuf();
00040 fb = fb->open(filePath.c_str(), std::ios::in);
00041 if (! fb) {
00042 cerr << "Can't read " << filePath.c_str() << endl;
00043 exit(1);
00044 }
00045 m_streambuf = fb;
00046 }
00047 this->init(m_streambuf);
00048 }
00049
00050 InputFileStream::~InputFileStream()
00051 {
00052 delete m_streambuf;
00053 m_streambuf = NULL;
00054 }
00055
00056 void InputFileStream::Close()
00057 {
00058 }
00059
00060
00061 }
00062