The Battle for Wesnoth  1.15.12+dev
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017-2018 by the Battle for Wesnoth Project
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
11  See the COPYING file for more details.
12 */
14 #pragma once
16 #include "config.hpp"
17 #include <list>
18 #include <functional>
19 /*
20  The purpose if this class is to preprocess incoming network data, and provide a steam that always returns just one command/action at a time.
21  Especially we want each replay command in his own [turn].
22 */
24 {
25 public:
26  typedef std::function<bool(config&)> source_type;
28  playturn_network_adapter(source_type source);
31  //returns true on success.
32  //dst has to be empty before the call.
33  //after the call dst contains one child when returned true otherwise it's empty.
34  bool read(config& dst);
35  //returns false if there is still data in the internal buffer.
36  bool is_at_end() const;
37  void set_source(source_type source);
38  //returns a function to be passed to set_source.
39  static source_type get_source_from_config(config& src);
40  void push_front(config&& cfg);
41 private:
42  //reads data from the network stream.
43  void read_from_network();
44  //a function to receive data from the network.
45  source_type network_reader_;
47  // note: all of the following could be replaced by a simple std::list<config> if we would
48  // split incoming tags right after we rechived them from network_reader_ the reason
49  // why we currently don'T do that is for performance.
51  //this always contains one empty config because we want a valid value for next_.
52  std::list<config> data_;
53  //packages that the client could not process at that point.
54  std::list<config> data_front_;
55  //the position of the next to be received element in data_->front().
57  //if we are processing a [turn] with multiple [command] we want to split them.
58  //In this case next_command_num_ is the next to be processed turn into a command otherwise it's 0;
59  unsigned int next_command_num_;
60 };
Definitions for the interface to Wesnoth Markup Language (WML).
void set_source(source_type source)
config::all_children_iterator next_
std::function< bool(config &)> source_type
static source_type get_source_from_config(config &src)
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:59
playturn_network_adapter(source_type source)