mail[Wesnoth-commits] r36840 - in /trunk/src: lobby_data.cpp lobby_data.hpp


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

Header


Content

Posted by kailoran on July 12, 2009 - 15:55:
Author: ilor
Date: Sun Jul 12 15:54:52 2009
New Revision: 36840

URL: http://svn.gna.org/viewcvs/wesnoth?rev=36840&view=rev
Log:
new lobby game filters backend

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

Modified: trunk/src/lobby_data.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/lobby_data.cpp?rev=36840&r1=36839&r2=36840&view=diff
==============================================================================
--- trunk/src/lobby_data.cpp (original)
+++ trunk/src/lobby_data.cpp Sun Jul 12 15:54:52 2009
@@ -348,6 +348,19 @@
        }
 }
 
+void game_filter_stack::append(game_filter_base *f)
+{
+       filters_.push_back(f);
+}
+
+void game_filter_stack::clear()
+{
+       foreach (game_filter_base* f, filters_) {
+               delete f;
+       }
+       filters_.clear();
+}
+
 bool game_filter_and_stack::match(const game_info &game) const
 {
        foreach (game_filter_base* f, filters_) {
@@ -373,7 +386,8 @@
 
 lobby_info::lobby_info(const config& game_config)
 : game_config_(game_config), gamelist_(), gamelist_initialized_(false)
-, rooms_(), games_(), users_()
+, rooms_(), games_(), games_filtered_(), users_()
+, game_filter_(), game_filter_invert_(false)
 {
 }
 
@@ -449,3 +463,35 @@
                rooms_.erase(rooms_.begin() + (r - &rooms_[0]));
        }
 }
+
+const std::vector<game_info>& lobby_info::games_filtered()
+{
+       return games_filtered_;
+}
+
+void lobby_info::add_game_filter(game_filter_base *f)
+{
+       game_filter_.append(f);
+}
+
+void lobby_info::clear_game_filter()
+{
+       game_filter_.clear();
+}
+
+void lobby_info::set_game_filter_invert(bool value)
+{
+       game_filter_invert_ = value;
+}
+
+void lobby_info::apply_game_filter()
+{
+       games_filtered_.clear();
+       if (game_filter_invert_) {
+               std::remove_copy_if(games_.begin(), games_.end(),
+                       std::back_inserter(games_filtered_), game_filter_);
+       } else {
+               std::remove_copy_if(games_.begin(), games_.end(),
+                       std::back_inserter(games_filtered_), 
std::not1(game_filter_));
+       }
+}

Modified: trunk/src/lobby_data.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/lobby_data.hpp?rev=36840&r1=36839&r2=36840&view=diff
==============================================================================
--- trunk/src/lobby_data.hpp (original)
+++ trunk/src/lobby_data.hpp Sun Jul 12 15:54:52 2009
@@ -21,6 +21,7 @@
 #include <set>
 #include <map>
 #include <deque>
+#include <functional>
 
 /** This class represenst a single stored chat message */
 struct chat_message
@@ -140,12 +141,12 @@
        bool have_era;
 };
 
-class game_filter_base
+class game_filter_base : public std::unary_function<game_info, bool>
 {
 public:
        virtual ~game_filter_base() {}
        virtual bool match(const game_info& game) const = 0;
-       bool operator()(const game_info& game) { return match(game); }
+       bool operator()(const game_info& game) const { return match(game); }
 };
 
 class game_filter_stack : public game_filter_base
@@ -157,7 +158,11 @@
        /**
         * Takes ownership
         */
-       bool append(game_filter_base* f);
+       void append(game_filter_base* f);
+
+       void clear();
+
+       bool empty() const { return filters_.empty(); }
 
 protected:
        std::vector<game_filter_base*> filters_;
@@ -217,6 +222,11 @@
        bool process_gamelist_diff(const config &data);
 
        const config& gamelist() const { return gamelist_; }
+
+       void clear_game_filter();
+       void add_game_filter(game_filter_base* f);
+       void set_game_filter_invert(bool value);
+       void apply_game_filter();
 
        void open_room(const std::string& name);
        void close_room(const std::string& name);
@@ -230,6 +240,7 @@
 
        const std::vector<room_info>& rooms() const { return rooms_; }
        const std::vector<game_info>& games() const { return games_; }
+       const std::vector<game_info>& games_filtered();
        const std::vector<user_info>& users() const { return users_; }
 private:
        void parse_gamelist();
@@ -239,8 +250,11 @@
        bool gamelist_initialized_;
        std::vector<room_info> rooms_;
        std::vector<game_info> games_;
+       std::vector<game_info> games_filtered_;
        std::vector<user_info> users_;
        std::map<std::string, chat_log> whispers_;
+       game_filter_and_stack game_filter_;
+       bool game_filter_invert_;
 };
 
 #endif




Related Messages


Powered by MHonArc, Updated Sun Jul 12 16:00:57 2009