From: Marc D. <ma...@us...> - 2004-12-28 22:36:53
|
Update of /cvsroot/pclasses/pclasses2/src/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21640/src/Util Added Files: Prefs.cpp Variant.cpp Log Message: added Prefs and Variant class to Util module --- NEW FILE: Variant.cpp --- #include "Variant.h" #include <sstream> #include <iostream> using namespace std; namespace P { namespace Ext { } } --- NEW FILE: Prefs.cpp --- #include "Prefs.h" #include <sstream> #include <iostream> using namespace std; namespace P { namespace Ext { Prefs::Section::Section(const std::string& name) { } Prefs::Section::~Section() { clear(); } void Prefs::Section::clear() { for(list<Section*>::iterator it = _sections.begin(); it != _sections.end(); ++it) { delete *it; } _sections.clear(); for(list<Entry*>::iterator it = _entries.begin(); it != _entries.end(); ++it) { delete *it; } _entries.clear(); } Prefs::Entry* Prefs::Section::entry(const std::string& name) { for(list<Entry*>::iterator it = _entries.begin(); it != _entries.end(); ++it) { if( (*it)->name() == name ) { return *it; } } return 0; } void Prefs::Section::addEntry(Prefs::Entry* entry) { _entries.push_back(entry); } void Prefs::Section::removeEntries(const std::string& name) { list<Entry*>::iterator it = _entries.begin(); while( it != _entries.end() ) { if( (*it)->name() == name ) { delete *it; it = _entries.erase(it); } else { ++it; } } } Prefs::Section* Prefs::Section::section(const std::string& name) { for(list<Section*>::iterator it = _sections.begin(); it != _sections.end(); ++it) { if( (*it)->name() == name ) { return *it; } } return 0; } void Prefs::Section::addSection(Section* section) { _sections.push_back(section); } void Prefs::Section::removeSections(const std::string& name) { list<Section*>::iterator it = _sections.begin(); while( it != _sections.end() ) { if( (*it)->name() == name ) { delete *it; it = _sections.erase(it); } else { ++it; } } } Prefs::Prefs(PrefsStore* store, const std::string& name) : _root(name), _store(store) { load(); } Prefs::~Prefs() { if(_store) delete _store; clear(); } void Prefs::clear() { _root.clear(); } void Prefs::load() throw(P::IOError) { if(!_store) return; clear(); _store->load(_root); } void Prefs::save() throw(P::IOError) { if(!_store) return; _store->update(_root); } Prefs::Section& Prefs::root() { return _root; } const Prefs::Section& Prefs::root() const { return _root; } PrefsStore* Prefs::store() { return _store; } const PrefsStore* Prefs::store() const { return _store; } void Prefs::setStore(PrefsStore* store) { _store = store; } } } |