00001 #include "FileStream.h"
00002
00003 #include <stdexcept>
00004 #include "GzFileBuf.h"
00005
00006 using namespace std;
00007
00008 namespace
00009 {
00010 bool IsGzipFile(const std::string &filename)
00011 {
00012 return filename.size() > 3 &&
00013 filename.substr(filename.size() - 3, 3) == ".gz";
00014 }
00015 }
00016
00017 inputfilestream::inputfilestream(const std::string &filePath)
00018 : std::istream(0), m_streambuf(0), m_is_good(false)
00019 {
00020
00021 std::filebuf* fb = new std::filebuf();
00022 m_is_good = (fb->open(filePath.c_str(), std::ios::in) != NULL);
00023
00024 if (IsGzipFile(filePath)) {
00025 fb->close();
00026 delete fb;
00027 m_streambuf = new GzFileBuf(filePath.c_str());
00028 } else {
00029 m_streambuf = fb;
00030 }
00031 this->init(m_streambuf);
00032 }
00033
00034 inputfilestream::~inputfilestream()
00035 {
00036 delete m_streambuf;
00037 m_streambuf = 0;
00038 }
00039
00040 void inputfilestream::close()
00041 {
00042 }