Changeset 13697

Show
Ignore:
Timestamp:
02/05/08 12:12:31 (5 months ago)
Author:
retsios
Message:

Avoid writing an ILWIS file to disk when it is a src_dataset. Design of responsible class (IniFile?) is simplified, to prevent this from happening unintentionally.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/ilwis/ilwisdataset.cpp

    r13693 r13697  
    7070// Construction/Destruction 
    7171////////////////////////////////////////////////////////////////////// 
    72 IniFile::IniFile() 
    73 
    74  
     72IniFile::IniFile(const string& filenam) 
     73
     74    filename = filenam; 
     75    Load(); 
     76    bChanged = false; // Start tracking changes 
    7577} 
    7678 
    7779IniFile::~IniFile() 
    7880{ 
    79  
    80 
    81  
    82 void IniFile::Open(const string& filenam) 
    83 
    84     filename = filenam; 
    85  
    86     Load(); 
    87 
    88  
    89 void IniFile::Close() 
    90 
    91     Flush(); 
     81    if (bChanged) 
     82    { 
     83        Store(); 
     84        bChanged = false; 
     85    } 
    9286 
    9387    for (Sections::iterator iter = sections.begin(); iter != sections.end(); ++iter) 
     
    116110        (*entries)[key] = value; 
    117111    } 
    118 
     112    bChanged = true; 
     113
     114 
    119115string IniFile::GetKeyValue(const string& section, const string& key) 
    120116{ 
     
    139135        SectionEntries *entries = (*iterSect).second; 
    140136        (*entries).erase(key); 
     137        bChanged = true; 
    141138    } 
    142139} 
     
    151148        (*entries).clear(); 
    152149        sections.erase(iterSect); 
     150        bChanged = true; 
    153151    } 
    154152} 
     
    214212} 
    215213 
    216 void IniFile::Flush() 
     214void IniFile::Store() 
    217215{ 
    218216    FILE *filIni = VSIFOpenL(filename.c_str(), "w+"); 
     
    263261        return string(); 
    264262 
    265     IniFile MyIniFile; 
    266     MyIniFile = IniFile(); 
    267     MyIniFile.Open(filename); 
    268  
    269     string ret = MyIniFile.GetKeyValue(section, entry); 
    270  
    271     MyIniFile.Close(); 
    272  
    273     return ret; 
     263    IniFile MyIniFile (filename); 
     264 
     265    return MyIniFile.GetKeyValue(section, entry);; 
    274266} 
    275267 
     
    280272        return false; 
    281273 
    282     IniFile MyIniFile; 
    283     MyIniFile = IniFile(); 
    284     MyIniFile.Open(fn); 
     274    IniFile MyIniFile (fn); 
    285275 
    286276    MyIniFile.SetKeyValue(sSection, sEntry, sValue); 
    287     MyIniFile.Close(); 
    288277    return true; 
    289278} 
  • trunk/gdal/frmts/ilwis/ilwisdataset.h

    r13694 r13697  
    192192{ 
    193193public: 
    194        bool operator() (const string&, const string&) const; 
     194    bool operator() (const string&, const string&) const; 
    195195}; 
    196196 
     
    201201{ 
    202202public: 
    203         IniFile(); 
    204         virtual ~IniFile(); 
    205  
    206         void Open(const string& filename); 
    207         void Close(); 
    208  
    209         void SetKeyValue(const string& section, const string& key, const string& value); 
    210         string GetKeyValue(const string& section, const string& key); 
    211  
    212         void RemoveKeyValue(const string& section, const string& key); 
    213         void RemoveSection(const string& section); 
     203    IniFile(const string& filename); 
     204    virtual ~IniFile(); 
     205 
     206    void SetKeyValue(const string& section, const string& key, const string& value); 
     207    string GetKeyValue(const string& section, const string& key); 
     208 
     209    void RemoveKeyValue(const string& section, const string& key); 
     210    void RemoveSection(const string& section); 
    214211 
    215212private: 
    216         string filename; 
    217         Sections sections; 
    218  
    219         void Load(); 
    220         void Flush(); 
    221 }; 
    222  
    223  
     213    string filename; 
     214    Sections sections; 
     215    bool bChanged; 
     216 
     217    void Load(); 
     218    void Store(); 
     219}; 
     220 
     221