The Battle for Wesnoth  1.17.0-dev
syncmp_handler.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
3  by David White <dave@whitevine.net>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #include "syncmp_handler.hpp"
17 
18 #include <cassert>
19 #include <algorithm>
20 
22 {
24 }
25 
27 {
29 }
30 
31 std::vector<syncmp_handler*>& syncmp_registry::handlers()
32 {
33  //using pointer in order to prevent destruction at program end. Although in this simple case it shouldn't matter.
34  static handler_list* handlers_ = new handler_list();
35  return *handlers_;
36 }
37 
39 {
40  handler_list::iterator elem = std::find(handlers().begin(), handlers().end(), handler);
41  assert(elem != handlers().end());
42  handlers().erase(elem);
43 }
44 
46 {
47  handler_list::iterator elem = std::find(handlers().begin(), handlers().end(), handler);
48  assert(elem == handlers().end());
49  handlers().push_back(handler);
50 }
51 
53 {
54  for(syncmp_handler* phandler : handlers())
55  {
56  phandler->pull_remote_choice();
57  }
58 }
59 
61 {
62  for(syncmp_handler* phandler : handlers())
63  {
64  phandler->send_user_choice();
65  }
66 }
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:36
static void add_handler(syncmp_handler *handler)
virtual ~syncmp_handler()
static void send_user_choice()
std::vector< syncmp_handler * > handler_list
std::string::const_iterator iterator
Definition: tokenizer.hpp:25