The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
manager_impl.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #ifndef GAME_EVENTS_MANAGER_IMPL_HPP
16 #define GAME_EVENTS_MANAGER_IMPL_HPP
17 
18 #include "game_events/handlers.hpp"
19 
20 #include <boost/noncopyable.hpp>
21 #include <boost/scoped_ptr.hpp>
22 #include <boost/shared_ptr.hpp>
23 #include <boost/unordered_map.hpp>
24 #include <boost/weak_ptr.hpp>
25 
26 namespace game_events {
27 
28  //t_event_handlers is essentially the implementation details of the manager
30  typedef boost::unordered_map<std::string, handler_list> map_t;
31  typedef boost::unordered_map<std::string, boost::weak_ptr<event_handler> > id_map_t;
32 
33  public:
35  typedef handler_vec::const_iterator const_iterator;
36 
37  private:
38  handler_vec active_; /// Active event handlers. Will not have elements removed unless the t_event_handlers is clear()ed.
39  map_t by_name_; /// Active event handlers with fixed event names, organized by event name.
40  handler_list dynamic_; /// Active event handlers with variables in their event names.
41  id_map_t id_map_; /// Allows quick locating of handlers by id.
42 
43 
44  void log_handlers();
45  /// Utility to standardize the event names used in by_name_.
47 
48  public:
49  typedef handler_vec::size_type size_type;
50 
52  : active_()
53  , by_name_()
54  , dynamic_()
55  , id_map_()
56  {}
57 
58  /// Read-only access to the handlers with varying event names.
59  const handler_list & get() const { return dynamic_; }
60  /// Read-only access to the handlers with fixed event names, by event name.
61  const handler_list & get(const std::string & name) const;
62 
63  /// Adds an event handler.
64  void add_event_handler(const config & cfg, manager & man, bool is_menu_item=false);
65  /// Removes an event handler, identified by its ID.
66  void remove_event_handler(std::string const & id);
67 
68  iterator begin() { return active_.begin(); }
69  const_iterator begin() const { return active_.begin(); }
70 
71  iterator end() { return active_.end(); }
72  const_iterator end() const { return active_.end(); }
73 
74  /// The number of active event handlers.
75  size_type size() const { return active_.size(); }
76  /// Access to active event handlers by index.
77  handler_ptr & operator[](size_type index) { return active_[index]; }
78  };//t_event_handlers
79 
80 } //end namespace game_events
81 
82 #endif
handler_vec::const_iterator const_iterator
handler_vec::iterator iterator
static std::string standardize_name(const std::string &name)
Utility to standardize the event names used in by_name_.
handler_ptr & operator[](size_type index)
Access to active event handlers by index.
boost::unordered_map< std::string, boost::weak_ptr< event_handler > > id_map_t
id_map_t id_map_
Active event handlers with variables in their event names.
void add_event_handler(const config &cfg, manager &man, bool is_menu_item=false)
Adds an event handler.
handler_vec::size_type size_type
handler_list dynamic_
Active event handlers with fixed event names, organized by event name.
boost::unordered_map< std::string, handler_list > map_t
size_type size() const
The number of active event handlers.
map_t by_name_
Active event handlers. Will not have elements removed unless the t_event_handlers is clear()ed...
This is a wrapper for a list of weak pointers to handlers.
Definition: handlers.hpp:88
std::vector< handler_ptr > handler_vec
Storage of event handlers.
Definition: handlers.hpp:49
void remove_event_handler(std::string const &id)
Removes an event handler, identified by its ID.
const_iterator begin() const
const_iterator end() const
Domain specific events.
Definition: action_wml.cpp:93
void log_handlers()
Allows quick locating of handlers by id.
GLuint index
Definition: glew.h:1782
The game event manager loads the scenario configuration object, and ensures that events are handled a...
Definition: manager.hpp:47
GLuint const GLchar * name
Definition: glew.h:1782
Define the handlers for the game's events mechanism.
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
GLsizei const GLcharARB ** string
Definition: glew.h:4503