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