gui/dialogs/lobby/lobby_data.hpp

Go to the documentation of this file.
00001 /* $Id: lobby_data.hpp 54051 2012-04-30 21:52:38Z brilliand $ */
00002 /*
00003    Copyright (C) 2009 - 2012 by Tomasz Sniatowski <kailoran@gmail.com>
00004    Part of the Battle for Wesnoth Project http://www.wesnoth.org/
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2 of the License, or
00009    (at your option) any later version.
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY.
00012 
00013    See the COPYING file for more details.
00014 */
00015 
00016 #ifndef INC_LOBBY_DATA
00017 #define INC_LOBBY_DATA
00018 
00019 #include "sdl_utils.hpp"
00020 
00021 #include <set>
00022 #include <deque>
00023 #include <functional>
00024 
00025 class config;
00026 
00027 /** This class represenst a single stored chat message */
00028 struct chat_message
00029 {
00030     /** Create a chat message */
00031     chat_message(const time_t& timestamp, const std::string& user, const std::string& message);
00032 
00033     time_t timestamp;
00034     std::string user;
00035     std::string message;
00036 };
00037 
00038 /** this class memorizes a chat session. */
00039 class chat_log
00040 {
00041 public:
00042     chat_log();
00043 
00044     void add_message(const time_t& timestamp, const std::string& user, const std::string& message);
00045 
00046     void add_message(const std::string& user, const std::string& message);
00047 
00048     const std::deque<chat_message>& history() const { return history_; }
00049 
00050     void clear();
00051 private:
00052     std::deque<chat_message> history_;
00053 };
00054 
00055 /**
00056  * This class represents the information a client has about a room
00057  */
00058 class room_info
00059 {
00060 public:
00061     explicit room_info(const std::string& name);
00062 
00063     const std::string& name() const { return name_; }
00064     const std::set<std::string>& members() const { return members_; }
00065     bool is_member(const std::string& user) const;
00066     void add_member(const std::string& user);
00067     void remove_member(const std::string& user);
00068     void process_room_members(const config &data);
00069 
00070     const chat_log& log() const { return log_; }
00071     chat_log& log() { return log_; }
00072 
00073 private:
00074     std::string name_;
00075     std::set<std::string> members_;
00076     chat_log log_;
00077 };
00078 
00079 
00080 /**
00081  * This class represents the information a client has about another player
00082  */
00083 struct user_info
00084 {
00085     explicit user_info(const config& c);
00086 
00087     void update_state(int selected_game_id, const room_info* current_room = NULL);
00088     void update_relation();
00089 
00090     enum user_relation { FRIEND, ME, NEUTRAL, IGNORED };
00091     enum user_state    { LOBBY, SEL_ROOM, GAME, SEL_GAME };
00092 
00093     bool operator> (const user_info& b) const;
00094 
00095     std::string name;
00096     int game_id;
00097     user_relation relation;
00098     user_state state;
00099     bool registered;
00100     bool observing;
00101 };
00102 
00103 /**
00104  * This class represents the info a client has about a game on the server
00105  */
00106 struct game_info
00107 {
00108     game_info(const config& c, const config& game_config);
00109 
00110     bool can_join() const;
00111     bool can_observe() const;
00112 
00113     surface mini_map;
00114     int id;
00115     std::string map_data;
00116     std::string name;
00117     std::string scenario;
00118     bool remote_scenario;
00119     std::string map_info;
00120     std::string map_size_info;
00121     std::string era;
00122     std::string era_short;
00123 
00124     std::string gold;
00125     std::string support;
00126     std::string xp;
00127     std::string vision;
00128     std::string status; //vacant slots or turn info
00129     std::string time_limit;
00130     size_t vacant_slots;
00131 
00132     unsigned int current_turn;
00133     bool reloaded;
00134     bool started;
00135     bool fog;
00136     bool shroud;
00137     bool observers;
00138     bool shuffle_sides;
00139     bool use_map_settings;
00140     bool verified;
00141     bool password_required;
00142     bool have_era;
00143 
00144     bool has_friends;
00145     bool has_ignored;
00146 
00147     enum game_display_status { CLEAN, NEW, UPDATED, DELETED };
00148     game_display_status display_status;
00149 
00150     const char* display_status_string() const;
00151 
00152 };
00153 
00154 class game_filter_base : public std::unary_function<game_info, bool>
00155 {
00156 public:
00157     virtual ~game_filter_base() {}
00158     virtual bool match(const game_info& game) const = 0;
00159     bool operator()(const game_info& game) const { return match(game); }
00160 };
00161 
00162 template<class T>
00163 class game_filter_not : public game_filter_base
00164 {
00165 public:
00166     explicit game_filter_not(const T& t) : t(t) {}
00167     bool match(const game_info& game) const { return !t.match(game); }
00168     T t;
00169 };
00170 
00171 class game_filter_stack : public game_filter_base
00172 {
00173 public:
00174     game_filter_stack();
00175     virtual ~game_filter_stack();
00176 
00177     /**
00178      * Takes ownership
00179      */
00180     void append(game_filter_base* f);
00181 
00182     void clear();
00183 
00184     bool empty() const { return filters_.empty(); }
00185 
00186 protected:
00187     std::vector<game_filter_base*> filters_;
00188 };
00189 
00190 class game_filter_and_stack : public game_filter_stack
00191 {
00192 public:
00193     bool match(const game_info& game) const;
00194 };
00195 
00196 template <class T, T game_info::*member, class OP = std::equal_to<T> >
00197 class game_filter_value : public game_filter_base
00198 {
00199 public:
00200     explicit game_filter_value(const T& value)
00201     : member_(member), value_(value)
00202     {
00203     }
00204 
00205     bool match(const game_info& game) const { return OP()(game.*member_,value_); }
00206 
00207 private:
00208     T game_info::*member_;
00209     T value_;
00210 };
00211 
00212 class game_filter_general_string_part : public game_filter_base
00213 {
00214 public:
00215     explicit game_filter_general_string_part(const std::string& value)
00216     : value_(value)
00217     {
00218     }
00219 
00220     bool match(const game_info& game) const;
00221 private:
00222     std::string value_;
00223 };
00224 
00225 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:02:58 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs