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


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

Header


Content

Posted by patrick_X99 on August 31, 2008 - 21:56:
Author: sapient
Date: Sun Aug 31 21:56:15 2008
New Revision: 29142

URL: http://svn.gna.org/viewcvs/wesnoth?rev=29142&view=rev
Log:
now able to safely insert to an index at array.length using [set_variables] 
mode=insert (before it would create empty child data before inserting). 

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

Modified: trunk/src/config.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config.cpp?rev=29142&r1=29141&r2=29142&view=diff
==============================================================================
--- trunk/src/config.cpp (original)
+++ trunk/src/config.cpp Sun Aug 31 21:56:15 2008
@@ -111,6 +111,15 @@
                static const std::vector<config*> dummy;
                return const_child_itors(dummy.begin(),dummy.end());
        }
+}
+
+size_t config::child_count(const std::string& key) const
+{
+       child_map::const_iterator i = children.find(key);
+       if(i != children.end()) {
+               return i->second.size();
+       }
+       return 0;
 }
 
 const config::child_list& config::get_children(const std::string& key) const

Modified: trunk/src/config.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config.hpp?rev=29142&r1=29141&r2=29142&view=diff
==============================================================================
--- trunk/src/config.hpp (original)
+++ trunk/src/config.hpp Sun Aug 31 21:56:15 2008
@@ -75,6 +75,7 @@
 
        child_itors child_range(const std::string& key);
        const_child_itors child_range(const std::string& key) const;
+       size_t child_count(const std::string& key) const;
 
        const child_list& get_children(const std::string& key) const;
        const child_map& all_children() const;
@@ -89,9 +90,9 @@
 
        const t_string& get_attribute(const std::string& key) const;
        bool has_attribute(const std::string& key) const {return 
values.find(key) != values.end();}
-       
-       /** 
-        * This should only be used if there is no mapping of the key 
already, 
+
+       /**
+        * This should only be used if there is no mapping of the key already,
         * e.g. when creating a new config object. It does not replace an 
existing value.
         * @returns true when it added the key-value pair, false if it 
already existed
         *          (and you probably wanted to use config[key] = value)

Modified: trunk/src/game_events.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game_events.cpp?rev=29142&r1=29141&r2=29142&view=diff
==============================================================================
--- trunk/src/game_events.cpp (original)
+++ trunk/src/game_events.cpp Sun Aug 31 21:56:15 2008
@@ -1313,8 +1313,20 @@
                std::string mode = cfg["mode"]; // replace, append, merge, or 
insert
                if(mode == "extend") {
                        mode = "append";
-               } else if(mode != "append" && mode != "merge" && mode != 
"insert") {
-                       mode = "replace";
+               } else if(mode != "append" && mode != "merge") {
+                       if(mode == "insert") {
+                               size_t child_count = 
dest.vars->child_count(dest.key);
+                               if(dest.index >= child_count) {
+                                       while(dest.index >= ++child_count) {
+                                               //inserting past the end 
requires empty data
+                                               
dest.vars->append(config(dest.key));
+                                       }
+                                       //inserting at the end is handled by 
an append
+                                       mode = "append";
+                               }
+                       } else {
+                               mode = "replace";
+                       }
                }
 
                const vconfig::child_list values = cfg.get_children("value");




Related Messages


Powered by MHonArc, Updated Sun Aug 31 23:22:41 2008