mail[Wesnoth-commits] r33936 - 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 guillaume . melquiond on March 20, 2009 - 20:48:
Author: silene
Date: Fri Mar 20 20:48:17 2009
New Revision: 33936

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33936&view=rev
Log:
Improved config::all_children_iterator by getting rid of std::auto_ptr.

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=33936&r1=33935&r2=33936&view=diff
==============================================================================
--- trunk/src/config.cpp (original)
+++ trunk/src/config.cpp Fri Mar 20 20:48:17 2009
@@ -452,32 +452,11 @@
        return children.empty() && values.empty();
 }
 
-config::all_children_iterator::all_children_iterator(config::all_children_iterator::Itor
 i) : i_(i)
-{}
-
-config::all_children_iterator& config::all_children_iterator::operator++()
-{
-       ++i_;
-       return *this;
-}
-
-config::all_children_iterator config::all_children_iterator::operator++(int)
-{
-       config::all_children_iterator i = *this;
-       ++i_;
-       return i;
-}
-
-std::pair<const std::string*,const config*> 
config::all_children_iterator::operator*() const
+config::any_child config::all_children_iterator::operator*() const
 {
        return std::pair<const std::string*,const 
config*>(&(i_->pos->first),i_->pos->second[i_->index]);
 }
 
-config::all_children_iterator::pointer 
config::all_children_iterator::operator->() const
-{
-       return pointer(new std::pair<const std::string*,const 
config*>(&(i_->pos->first),i_->pos->second[i_->index]));
-}
-
 const std::string& config::all_children_iterator::get_key() const
 {
        return i_->pos->first;
@@ -491,16 +470,6 @@
 size_t config::all_children_iterator::get_index() const
 {
        return i_->index;
-}
-
-bool config::all_children_iterator::operator==(all_children_iterator i) const
-{
-       return i_ == i.i_;
-}
-
-bool config::all_children_iterator::operator!=(all_children_iterator i) const
-{
-       return i_ != i.i_;
 }
 
 config::all_children_iterator config::ordered_begin() const

Modified: trunk/src/config.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/config.hpp?rev=33936&r1=33935&r2=33936&view=diff
==============================================================================
--- trunk/src/config.hpp (original)
+++ trunk/src/config.hpp Fri Mar 20 20:48:17 2009
@@ -33,7 +33,6 @@
 #include <boost/shared_ptr.hpp>
 
 #include <map>
-#include <memory>
 #include <ostream>
 #include <string>
 #include <vector>
@@ -83,7 +82,7 @@
                typedef config *pointer;
                typedef config &reference;
                typedef child_list::iterator Itor;
-               explicit child_iterator(Itor i = Itor()): i_(i) {}
+               explicit child_iterator(const Itor &i = Itor()): i_(i) {}
 
                child_iterator &operator++() { ++i_; return *this; }
                child_iterator operator++(int) { return child_iterator(i_++); 
}
@@ -107,7 +106,7 @@
                typedef const config *pointer;
                typedef const config &reference;
                typedef child_list::const_iterator Itor;
-               explicit const_child_iterator(Itor i = Itor()): i_(i) {}
+               explicit const_child_iterator(const Itor &i = Itor()): i_(i) 
{}
                const_child_iterator(const child_iterator &i): i_(i.i_) {}
 
                const_child_iterator &operator++() { ++i_; return *this; }
@@ -136,7 +135,7 @@
                typedef const attribute *pointer;
                typedef const attribute &reference;
                typedef string_map::const_iterator Itor;
-               explicit const_attribute_iterator(Itor i = Itor()): i_(i) {}
+               explicit const_attribute_iterator(const Itor &i = Itor()): 
i_(i) {}
                const_attribute_iterator(const const_attribute_iterator &i): 
i_(i.i_) {}
 
                const_attribute_iterator &operator++() { ++i_; return *this; }
@@ -206,27 +205,37 @@
                bool operator!=(const child_pos& o) const { return 
!operator==(o); }
        };
 
-       struct all_children_iterator {
-               typedef std::pair<const std::string*,const config*> 
value_type;
+       typedef std::pair<const std::string *, const config *> any_child;
+
+       struct all_children_iterator
+       {
+               typedef any_child value_type;
                typedef std::forward_iterator_tag iterator_category;
                typedef int difference_type;
-               typedef std::auto_ptr<value_type> pointer;
-               typedef value_type& reference;
+               typedef any_child *pointer;
+               typedef any_child &reference;
                typedef std::vector<child_pos>::const_iterator Itor;
-               explicit all_children_iterator(Itor i=Itor());
-
-               all_children_iterator& operator++();
-               all_children_iterator  operator++(int);
+               explicit all_children_iterator(const Itor &i = Itor()): i_(i) 
{}
+
+               all_children_iterator &operator++() { ++i_; return *this; }
+               all_children_iterator operator++(int) { return 
all_children_iterator(i_++); }
+
+               struct arrow_helper
+               {
+                       any_child data;
+                       arrow_helper(const all_children_iterator &i): 
data(*i) {}
+                       any_child *operator->() { return &data; }
+               };
 
                value_type operator*() const;
-               pointer operator->() const;
+               arrow_helper operator->() const { return *this; }
 
                const std::string& get_key() const;
                size_t get_index() const;
                const config& get_child() const;
 
-               bool operator==(all_children_iterator i) const;
-               bool operator!=(all_children_iterator i) const;
+               bool operator==(const all_children_iterator &i) const { 
return i_ == i.i_; }
+               bool operator!=(const all_children_iterator &i) const { 
return i_ != i.i_; }
 
        private:
                Itor i_;




Related Messages


Powered by MHonArc, Updated Fri Mar 20 21:00:37 2009