The Battle for Wesnoth  1.15.7+dev
Public Member Functions | Protected Attributes | List of all members
editor::editor_action_chain Class Reference

Container action wrapping several actions into one. More...

#include <action.hpp>

Inheritance diagram for editor::editor_action_chain:
Inheritance graph

Public Member Functions

 editor_action_chain ()
 Create an empty action chain. More...
 
 editor_action_chain (const editor_action_chain &other)
 
editor_action_chainoperator= (const editor_action_chain &other)
 
std::unique_ptr< editor_actionclone () const override
 Inherited from editor_action, implemented by IMPLEMENT_ACTION. More...
 
 editor_action_chain (std::deque< std::unique_ptr< editor_action >> actions)
 Create an action chain from a deque of action pointers. More...
 
 ~editor_action_chain () override=default
 The destructor deletes all the owned action pointers. More...
 
int action_count () const override
 Go through the chain and add up all the action counts. More...
 
void append_action (std::unique_ptr< editor_action > a)
 Add an action at the end of the chain. More...
 
void prepend_action (std::unique_ptr< editor_action > a)
 Add an action at the beginning of the chain. More...
 
bool empty () const
 
std::unique_ptr< editor_actionpop_last_action ()
 Remove the last added action and return it, transferring ownership to the caller. More...
 
std::unique_ptr< editor_actionpop_first_action ()
 Remove the first added action and return it, transferring ownership to the caller. More...
 
std::unique_ptr< editor_actionperform (map_context &m) const override
 Perform all the actions in order and create a undo action chain. More...
 
void perform_without_undo (map_context &m) const override
 Perform all the actions in order. More...
 
const std::string & get_name () const override
 
- Public Member Functions inherited from editor::editor_action
 editor_action ()
 
virtual ~editor_action ()
 
virtual std::string get_description () const
 A textual description of the action. More...
 
int get_id () const
 Debugging aid. More...
 

Protected Attributes

std::deque< std::unique_ptr< editor_action > > actions_
 The action pointers owned by this action chain. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from editor::editor_action
static int get_instance_count ()
 Debugging aid. More...
 

Detailed Description

Container action wrapping several actions into one.

The actions are performed in the order they are added, i.e. in the usual iteration order through the container.

Definition at line 86 of file action.hpp.

Constructor & Destructor Documentation

◆ editor_action_chain() [1/3]

editor::editor_action_chain::editor_action_chain ( )
inline

Create an empty action chain.

Definition at line 92 of file action.hpp.

References editor::editor_action_whole_map::clone().

◆ editor_action_chain() [2/3]

editor::editor_action_chain::editor_action_chain ( const editor_action_chain other)

Definition at line 77 of file action.cpp.

References a, and actions_.

◆ editor_action_chain() [3/3]

editor::editor_action_chain::editor_action_chain ( std::deque< std::unique_ptr< editor_action >>  actions)
inlineexplicit

Create an action chain from a deque of action pointers.

Note: the action chain assumes ownership of the pointers.

Definition at line 108 of file action.hpp.

References a, editor::editor_action::action_count(), editor::editor_action_whole_map::get_name(), editor::editor_action::perform(), editor::editor_action_whole_map::perform_without_undo(), and mariadb::value::string.

◆ ~editor_action_chain()

editor::editor_action_chain::~editor_action_chain ( )
overridedefault

The destructor deletes all the owned action pointers.

Member Function Documentation

◆ action_count()

int editor::editor_action_chain::action_count ( ) const
overridevirtual

Go through the chain and add up all the action counts.

Reimplemented from editor::editor_action.

Definition at line 103 of file action.cpp.

References a, and actions_.

◆ append_action()

void editor::editor_action_chain::append_action ( std::unique_ptr< editor_action a)

Add an action at the end of the chain.

Definition at line 115 of file action.cpp.

References actions_.

◆ clone()

std::unique_ptr<editor_action> editor::editor_action_chain::clone ( ) const
overridevirtual

Inherited from editor_action, implemented by IMPLEMENT_ACTION.

Implements editor::editor_action.

◆ empty()

bool editor::editor_action_chain::empty ( ) const
Returns
true when there are no actions in the chain. Empty action chains should usually be discarded as to not keep "empty" actions around.

Definition at line 125 of file action.cpp.

References actions_.

Referenced by editor::map_context::partial_undo(), pop_first_action(), and pop_last_action().

◆ get_name()

const std::string& editor::editor_action_chain::get_name ( ) const
overridevirtual
Returns
a short name of this action type, defaults to unknown

Reimplemented from editor::editor_action.

◆ operator=()

editor_action_chain & editor::editor_action_chain::operator= ( const editor_action_chain other)

Definition at line 86 of file action.cpp.

References a, actions_, and IMPLEMENT_ACTION.

◆ perform()

std::unique_ptr< editor_action > editor::editor_action_chain::perform ( map_context m) const
overridevirtual

Perform all the actions in order and create a undo action chain.

Reimplemented from editor::editor_action.

Definition at line 152 of file action.cpp.

References a, actions_, and reverse().

◆ perform_without_undo()

void editor::editor_action_chain::perform_without_undo ( map_context m) const
overridevirtual

Perform all the actions in order.

Implements editor::editor_action.

Definition at line 164 of file action.cpp.

References a, and actions_.

Referenced by editor::editor_action_paste::perform(), editor::editor_action_paint_area::perform(), and editor::editor_action_shuffle_area::perform().

◆ pop_first_action()

std::unique_ptr< editor_action > editor::editor_action_chain::pop_first_action ( )

Remove the first added action and return it, transferring ownership to the caller.

Definition at line 141 of file action.cpp.

References actions_, and empty().

Referenced by editor::map_context::partial_undo().

◆ pop_last_action()

std::unique_ptr< editor_action > editor::editor_action_chain::pop_last_action ( )

Remove the last added action and return it, transferring ownership to the caller.

Definition at line 130 of file action.cpp.

References actions_, and empty().

◆ prepend_action()

void editor::editor_action_chain::prepend_action ( std::unique_ptr< editor_action a)

Add an action at the beginning of the chain.

Definition at line 120 of file action.cpp.

References actions_.

Referenced by editor::map_context::perform_partial_action().

Member Data Documentation

◆ actions_

std::deque<std::unique_ptr<editor_action> > editor::editor_action_chain::actions_
protected

The action pointers owned by this action chain.

Definition at line 168 of file action.hpp.

Referenced by action_count(), append_action(), editor_action_chain(), empty(), operator=(), perform(), perform_without_undo(), pop_first_action(), pop_last_action(), and prepend_action().


The documentation for this class was generated from the following files: