mail[Wesnoth-commits] r43161 - in /trunk/src: config.cpp config.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by alinktomine on June 03, 2010 - 20:15:
Author: alink
Date: Thu Jun  3 20:15:48 2010
New Revision: 43161

URL: http://svn.gna.org/viewcvs/wesnoth?rev=43161&view=rev
Log:
Add possibility to log a WML error in the new functions handling backward 
compatible keys.

Modified:
    trunk/src/config.cpp
    trunk/src/config.hpp

Modified: trunk/src/config.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config.cpp?rev=43161&r1=43160&r2=43161&view=diff
==============================================================================
--- trunk/src/config.cpp (original)
+++ trunk/src/config.cpp Thu Jun  3 20:15:48 2010
@@ -201,10 +201,17 @@
        return values.find(key) != values.end();
 }
 
-bool config::has_old_attribute(const std::string &key, const std::string 
&old_key) const
-{
-       check_valid();
-       return values.find(key) != values.end() || values.find(old_key) != 
values.end();
+bool config::has_old_attribute(const std::string &key, const std::string 
&old_key, const std::string& msg) const
+{
+       check_valid();
+       if (values.find(key) != values.end()) {
+               return true;
+       } else if (values.find(old_key) != values.end()) {
+               if (!msg.empty())
+                       lg::wml_error << msg;
+               return true;
+       }
+       return false;
 }
 
 
@@ -484,14 +491,21 @@
        return empty_attribute;
 }
 
-const config::attribute_value &config::get_old_attribute(const std::string 
&key, const std::string &old_key) const
+const config::attribute_value &config::get_old_attribute(const std::string 
&key, const std::string &old_key, const std::string &msg) const
 {
        check_valid();
 
        attribute_map::const_iterator i = values.find(key);
-       if (i != values.end()) return i->second;
+       if (i != values.end())
+               return i->second;
+
        i = values.find(old_key);
-       if (i != values.end()) return i->second;
+       if (i != values.end()) {
+               if (!msg.empty())
+                       lg::wml_error << msg;
+               return i->second;
+       }
+
        static const attribute_value empty_attribute;
        return empty_attribute;
 }

Modified: trunk/src/config.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config.hpp?rev=43161&r1=43160&r2=43161&view=diff
==============================================================================
--- trunk/src/config.hpp (original)
+++ trunk/src/config.hpp Thu Jun  3 20:15:48 2010
@@ -257,8 +257,9 @@
        /**
         * Function to handle backward compatibility
         * Get the value of key and if missing try old_key
+        * and log msg as a WML error (if not empty)
        */
-       const attribute_value &get_old_attribute(const std::string &key, 
const std::string &old_key) const;
+       const attribute_value &get_old_attribute(const std::string &key, 
const std::string &old_key, const std::string& msg = "") const;
        /**
         * Returns a reference to the first child with the given @a key.
         * Creates the child if it does not yet exist.
@@ -269,8 +270,9 @@
        /**
         * Function to handle backward compatibility
         * Check if has key or old_key
+        * and log msg as a WML error (if not empty)
        */
-       bool has_old_attribute(const std::string &key, const std::string 
&old_key) const;
+       bool has_old_attribute(const std::string &key, const std::string 
&old_key, const std::string& msg = "") const;
 
        void remove_attribute(const std::string &key);
        void merge_attributes(const config &);




Related Messages


Powered by MHonArc, Updated Thu Jun 03 20:20:30 2010