The Battle for Wesnoth  1.15.1+dev
syncmp_handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://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 program end. Although in this simple case it shouldn't matter.
32  static handler_list* handlers_ = new handler_list();
33  return *handlers_;
34 }
35 
37 {
38  handler_list::iterator elem = std::find(handlers().begin(), handlers().end(), handler);
39  assert(elem != handlers().end());
40  handlers().erase(elem);
41 }
42 
44 {
45  handler_list::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 void remove_handler(syncmp_handler *handler)
static void pull_remote_choice()
static handler_list & handlers()
std::list< sdl_handler * > handler_list
Definition: events.hpp:35
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::vector< syncmp_handler * > handler_list
std::string::const_iterator iterator
Definition: tokenizer.hpp:24