The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
syncmp_handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 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 #include "syncmp_handler.hpp"
15 
16 #include <cassert>
17 #include <algorithm>
18 
20 {
22 }
23 
25 {
27 }
28 
29 std::vector<syncmp_handler*>& syncmp_registry::handlers()
30 {
31  //using pointer in order to prevent destruction at programm end. Although in this simple case it shouldn't matter.
32  static t_handlers* handlers_ = new t_handlers();
33  return *handlers_;
34 }
35 
37 {
38  t_handlers::iterator elem = std::find(handlers().begin(), handlers().end(), handler);
39  assert(elem != handlers().end());
40  handlers().erase(elem);
41 }
42 
44 {
45  t_handlers::iterator elem = std::find(handlers().begin(), handlers().end(), handler);
46  assert(elem == handlers().end());
47  handlers().push_back(handler);
48 }
49 
51 {
52  for(syncmp_handler* phandler : handlers())
53  {
54  phandler->pull_remote_choice();
55  }
56 }
57 
59 {
60  for(syncmp_handler* phandler : handlers())
61  {
62  phandler->send_user_choice();
63  }
64 }
static thandler * handler
Definition: handler.cpp:60
static void remove_handler(syncmp_handler *handler)
static void pull_remote_choice()
std::vector< syncmp_handler * > t_handlers
static t_handlers & handlers()
GLuint GLuint end
Definition: glew.h:1221
static void add_handler(syncmp_handler *handler)
virtual ~syncmp_handler()
static void send_user_choice()
bool find(E event, F functor)
Tests whether an event handler is available.
std::string::const_iterator iterator
Definition: tokenizer.hpp:21