From e0676f2432f84d188b2ac7a3816d15b125b4af12 Mon Sep 17 00:00:00 2001 From: stephena Date: Sat, 16 Jan 2016 00:13:52 +0000 Subject: [PATCH] The properties database is now smarter, and automatically discards entries if they are already present in the built-in data. This eliminates a 'bug' where entries were being saved to the external properties file that were also present in the app itself. The app still worked, but it bloated the external file for no reason. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@3248 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/emucore/OSystem.cxx | 3 +++ src/emucore/Props.cxx | 16 ++++++++++++++++ src/emucore/Props.hxx | 10 +++++++++- src/emucore/PropsSet.cxx | 30 ++++++++++++++---------------- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index d0e835816..3259f5fae 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -177,6 +177,9 @@ void OSystem::saveConfig() if(mySettings) mySettings->saveConfig(); + + if(myPropSet) + myPropSet->save(myPropertiesFile); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/Props.cxx b/src/emucore/Props.cxx index 710f62003..20631f5e2 100644 --- a/src/emucore/Props.cxx +++ b/src/emucore/Props.cxx @@ -195,6 +195,22 @@ void Properties::writeQuotedString(ostream& out, const string& s) out.put('"'); } +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Properties::operator == (const Properties& properties) const +{ + for(int i = 0; i < LastPropType; ++i) + if(myProperties[i] != properties.myProperties[i]) + return false; + + return true; +} + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +bool Properties::operator != (const Properties& properties) const +{ + return !(*this == properties); +} + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Properties& Properties::operator = (const Properties& properties) { diff --git a/src/emucore/Props.hxx b/src/emucore/Props.hxx index 9a6c9a874..c07981df4 100644 --- a/src/emucore/Props.hxx +++ b/src/emucore/Props.hxx @@ -122,7 +122,15 @@ class Properties */ void setDefaults(); - public: + /** + Overloaded equality operator(s) + + @param properties The properties object to compare to + @return True if the properties are equal, else false + */ + bool operator == (const Properties& properties) const; + bool operator != (const Properties& properties) const; + /** Overloaded assignment operator diff --git a/src/emucore/PropsSet.cxx b/src/emucore/PropsSet.cxx index 16cd88a34..826806a4e 100644 --- a/src/emucore/PropsSet.cxx +++ b/src/emucore/PropsSet.cxx @@ -39,21 +39,9 @@ void PropertiesSet::load(const string& filename) { ifstream in(filename); - // Loop reading properties - for(;;) - { - // Make sure the stream is still good or we're done - if(!in) - break; - - // Get the property list associated with this profile - Properties prop; - in >> prop; - - // If the stream is still good then insert the properties - if(in) - insert(prop); - } + Properties prop; + while(in >> prop) + insert(prop); } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -165,10 +153,20 @@ void PropertiesSet::insert(const Properties& properties, bool save) if(md5 == "") return; + // Make sure the exact entry isn't already in any list + Properties defaultProps; + if(getMD5(md5, defaultProps, false) && defaultProps == properties) + return; + else if(getMD5(md5, defaultProps, true) && defaultProps == properties) + { + myExternalProps.erase(md5); + return; + } + // The status of 'save' determines which list to save to PropsList& list = save ? myExternalProps : myTempProps; - auto ret = list.insert(make_pair(md5, properties)); + auto ret = list.emplace(md5, properties); if(ret.second == false) { // Remove old item and insert again