00001 #ifndef ASCII_FILE_H
00002 #define ASCII_FILE_H
00003
00004 #include <vector>
00005 #include <list>
00006
00007 using std::string;
00008
00009 namespace storage
00010 {
00011
00012 class Regex;
00013
00014
00015 class AsciiFile
00016 {
00017 public:
00018 AsciiFile( bool CreateBackup_bv=false,
00019 const char* BackupExt_Cv=".orig" );
00020 AsciiFile( const string& Name_Cv, bool CreateBackup_bv=false,
00021 const char* BackupExt_Cv=".orig" );
00022 AsciiFile( const char* Name_Cv, bool CreateBackup_bv=false,
00023 const char* BackupExt_Cv=".orig" );
00024 ~AsciiFile();
00025 bool insertFile( AsciiFile& File_Cv, unsigned int BeforeLine_iv=0 );
00026 bool appendFile( AsciiFile& File_Cv );
00027 bool insertFile( const string& Name_Cv, unsigned int BeforeLine_iv=0 );
00028 bool appendFile( const string& Name_Cv );
00029 bool loadFile( const string& Name_Cv );
00030 bool updateFile();
00031 bool saveToFile( const string& Name_Cv );
00032 void append( const string& Line_Cv );
00033 void append( const std::list<string>& Lines_Cv );
00034 void insert( unsigned int Before_iv, const string& Line_Cv );
00035 void remove( unsigned int Start_iv, unsigned int Cnt_iv );
00036 void replace( unsigned int Start_iv, unsigned int Cnt_iv,
00037 const string& Line_Cv );
00038 void replace( unsigned int Start_iv, unsigned int Cnt_iv,
00039 const std::list<string>& Line_Cv );
00040 const string& operator []( unsigned int Index_iv ) const;
00041 string& operator []( unsigned int Index_iv );
00042 int find( unsigned int Start_iv, const string& Pat_Cv ) const;
00043 int find( unsigned int Start_iv, Regex& Pat_Cv ) const;
00044 unsigned numLines() const;
00045 const string& fileName() const;
00046 unsigned differentLine( const AsciiFile& File_Cv ) const;
00047 bool removeIfEmpty();
00048
00049 protected:
00050 bool appendFile( const string& Name_Cv, std::vector<string>& Lines_Cr );
00051 bool appendFile( AsciiFile& File_Cv, std::vector<string>& Lines_Cr );
00052 void removeLastIf(string& Text_Cr, char Char_cv) const;
00053
00054 bool BackupCreated_b;
00055 string BackupExtension_C;
00056 std::vector<string> Lines_C;
00057 string Name_C;
00058 };
00059
00060 }
00061
00062 #endif