The Battle for Wesnoth  1.19.7+dev
replay_recorder_base.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2024
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 
15 #pragma once
16 #include <boost/ptr_container/ptr_vector.hpp>
17 
18 #include "config.hpp"
19 
20 class config_writer;
22 {
23 public:
26 
27  void swap(replay_recorder_base& other);
28  void swap(replay_recorder_base&& other) {swap(other);}
29  int get_pos() const;
30 
31  int size() const;
32 
33  config& get_command_at(int pos);
34 
35  config& add_child();
36 
38 
39  void remove_command(int index);
40 
42 
43  void set_to_end();
44 
45  void set_pos(int pos);
46 
47  void append_config(const config& data);
48  /** Clears the passed config. */
49  void append_config(config& data);
50 
51  void write(config_writer& out) const;
52 
53  void write(config& out) const;
54 
56 
57  /// checks whether the parameter is an earlier state in the
58  /// same "savegame gamestate branch"
59  bool is_ancestor(const config& other_replay) const;
60 protected:
62  boost::ptr_vector<config> commands_;
63  int pos_;
64 };
65 
66 /** Implement non-member swap function for std::swap (calls @ref replay_recorder_base::swap). */
Class for writing a config out to a file in pieces.
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:172
void write(config_writer &out) const
void swap(replay_recorder_base &&other)
void append_config(const config &data)
void swap(replay_recorder_base &other)
bool is_ancestor(const config &other_replay) const
checks whether the parameter is an earlier state in the same "savegame gamestate branch"
config & get_command_at(int pos)
config & insert_command(int index)
boost::ptr_vector< config > commands_
void remove_command(int index)
Definitions for the interface to Wesnoth Markup Language (WML).
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:70
std::string_view data
Definition: picture.cpp:178
void swap(replay_recorder_base &lhs, replay_recorder_base &rhs)
Implement non-member swap function for std::swap (calls replay_recorder_base::swap).