00001 #ifndef SDXFILEWRITER_H
00002 #define SDXFILEWRITER_H
00003
00004
00005 #include <fstream>
00006 #include <string>
00007
00008 namespace SDX {
00009 namespace Helpers {
00018 template <class T> class FileWriter : public T {
00019 public:
00023 FileWriter(std::string filePath) :
00024 m_filePath(filePath)
00025 {
00026 }
00027
00031 void setFilePath(std::string filePath){
00032 m_filePath = filePath;
00033 }
00034
00038 void openStream(){
00039 m_oStream = new std::ofstream(m_filePath.c_str());
00040
00041 bool success = !m_oStream->fail();
00042 if(!success){
00043 delete m_oStream;
00044 m_oStream = 0;
00045 } else
00046 T::setStream(m_oStream);
00047 }
00048
00052 void closeStream(){
00053 if(!m_oStream)
00054 return;
00055
00056 m_oStream->close();
00057 delete m_oStream;
00058 m_oStream = 0;
00059 }
00060 private:
00061 std::string m_filePath;
00062 std::ofstream* m_oStream;
00063 };
00064 }
00065 }
00066
00067 #endif