The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
playturn_network_adapter.hpp
Go to the documentation of this file.
1 
2 
3 #ifndef PLAYTURN_NETWORK_ADAPTER_HPP_INCLUDED
4 #define PLAYTURN_NETWORK_ADAPTER_HPP_INCLUDED
5 
6 #include "config.hpp"
7 #include <list>
8 #include "utils/functional.hpp"
9 /*
10  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.
11  Especially we want each replay command in his own [turn].
12 */
14 {
15 public:
16  typedef std::function<bool(config&)> source_type;
17 
18  playturn_network_adapter(source_type source);
20 
21  //returns true on success.
22  //dst has to be empty before the call.
23  //after the call dst contains one child when returned true otherwise it's empty.
24  bool read(config& dst);
25  //returns false if there is still data in the internal buffer.
26  bool is_at_end();
27  void set_source(source_type source);
28  //returns a function to be passed to set_source.
29  static source_type get_source_from_config(config& src);
30 private:
31  //reads data from the network stream.
32  void read_from_network();
33  //this always contains one empty config because we want a valid value for next_.
34  std::list<config> data_;
35  //the position of the next to be received element in data_->front().
37  //if we are processing a [turn] with multiple [command] we want to split them.
38  //In this case next_command_num_ is the next to be processed turn into a command otherwise it's 0;
39  unsigned int next_command_num_;
40  //a function to receive data from the network.
41  source_type network_reader_;
42 };
43 #endif
GLenum src
Definition: glew.h:2392
Definitions for the interface to Wesnoth Markup Language (WML).
void set_source(source_type source)
GLenum GLenum dst
Definition: glew.h:2392
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:83
GLsizei GLsizei GLchar * source
Definition: glew.h:1800
playturn_network_adapter(source_type source)