1 #ifndef _FILE_ENGINE_H_031104_ 2 #define _FILE_ENGINE_H_031104_ 3 4 #include "DataEngine.h" 5 6 enum fileengine_type 7 { 8 ISAM, 9 TIANWANG, 10 LINK4SE 11 }; 12 13 class CUrl; 14 class CPage; 15 16 struct file_arg 17 { 18 CUrl *pUrl; 19 CPage *pPage; 20 }; 21 22 class CFileEngine : public CDataEngine//仍然只能用作基类 23 { 24 public: 25 ofstream m_ofsFile; 26 27 public: 28 CFileEngine(); 29 CFileEngine(string str); 30 virtual ~CFileEngine(); 31 32 int GetEngineType() { return FILE_ENGINE; } 33 virtual int GetFileType() = 0; 34 35 bool Open(string str); 36 37 inline void Close() { m_ofsFile.close(); } 38 39 }; 40 41 #endif /* _FILE_ENGINE_H_031104_ */
1 #include "FileEngine.h" 2 3 CFileEngine::CFileEngine() 4 { 5 } 6 7 CFileEngine::CFileEngine(string str) : CDataEngine (str) 8 { 9 m_ofsFile.open(m_str.c_str(), ios::out|ios::app|ios::binary); 10 11 if( !m_ofsFile ){ 12 cerr << "cannot open " << m_str << "for output" << endl; 13 } 14 } 15 16 CFileEngine::~CFileEngine() 17 { 18 m_ofsFile.close(); 19 } 20 21 bool CFileEngine::Open(string str) 22 { 23 m_str = str; 24 25 m_ofsFile.open(m_str.c_str(), ios::out|ios::app|ios::binary); 26 27 if( !m_ofsFile ) 28 { 29 cerr << "cannot open " << m_str << "for output" << endl; 30 return false; 31 } 32 else 33 { 34 return true; 35 } 36 }