The Battle for Wesnoth  1.17.21+dev
replay_recorder_base.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017 - 2023
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 <cassert>
17 #include <boost/ptr_container/ptr_vector.hpp>
18 
19 #include "config.hpp"
20 
21 class config_writer;
23 {
24 public:
27 
28  void swap(replay_recorder_base& other);
29  void swap(replay_recorder_base&& other) {swap(other);}
30  int get_pos() const;
31 
32  int size() const;
33 
34  config& get_command_at(int pos);
35 
36  config& add_child();
37 
39 
40  void remove_command(int index);
41 
43 
44  void set_to_end();
45 
46  void set_pos(int pos);
47 
48  void append_config(const config& data);
49  /** Clears the passed config. */
50  void append_config(config& data);
51 
52  void write(config_writer& out) const;
53 
54  void write(config& out) const;
55 
57 
58  /// checks whether the parameter is an earlier state in the
59  /// same "savegame gamestate branch"
60  bool is_ancestor(const config& other_replay) const;
61 protected:
63  boost::ptr_vector<config> commands_;
64  int pos_;
65 };
66 
67 /** 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:161
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)
std::size_t index(const std::string &str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
Definition: unicode.cpp:72
std::string_view data
Definition: picture.cpp:199
void swap(replay_recorder_base &lhs, replay_recorder_base &rhs)
Implement non-member swap function for std::swap (calls replay_recorder_base::swap).