The Battle for Wesnoth  1.19.0-dev
Classes | Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
wb::side_actions_container Class Reference

Datastructure holding the actions of a side on multiple turns. More...

#include <side_actions.hpp>

Classes

struct  by_hex
 Tag for action_set's hashed_non_unique index. More...
 
struct  by_unit
 Tag for action_set's hashed_non_unique index. More...
 
struct  chronological
 Tag for action_set's random_access index. More...
 

Public Types

typedef boost::multi_index::multi_index_container< action_ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< chronological > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< by_unit >, boost::multi_index::const_mem_fun< action, std::size_t, &action::get_unit_id > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< by_hex >, boost::multi_index::const_mem_fun< action, map_location, &action::get_numbering_hex > > > > action_set
 Underlying container. More...
 
typedef action_set::index< chronological >::type::iterator iterator
 
typedef action_set::index< chronological >::type::const_iterator const_iterator
 
typedef action_set::index< chronological >::type::reverse_iterator reverse_iterator
 
typedef action_set::index< chronological >::type::const_reverse_iterator const_reverse_iterator
 
typedef std::pair< iterator, iteratorrange_t
 
typedef std::pair< reverse_iterator, reverse_iteratorrrange_t
 
typedef std::pair< const_iterator, const_iteratorcrange_t
 
typedef std::pair< const_reverse_iterator, const_reverse_iteratorcrrange_t
 
typedef std::deque< iteratoraction_limits
 

Public Member Functions

 side_actions_container ()
 
iterator insert (iterator position, action_ptr action)
 Inserts an action at the specified position. More...
 
iterator queue (std::size_t turn_num, action_ptr action)
 Queues an action to be executed last. More...
 
iterator push_front (std::size_t turn, action_ptr action)
 Pushes an action in front of a given turn. More...
 
iterator bump_earlier (iterator position)
 Moves an action earlier in the execution order. More...
 
iterator bump_later (iterator position)
 Moves an action later in the execution order. More...
 
iterator erase (iterator position)
 Deletes the action at the specified position. More...
 
iterator erase (iterator first, iterator last)
 Deletes the action at the specified position. More...
 
void clear ()
 Empties the action queue. More...
 
void turn_shift ()
 Shift turn. More...
 
bool replace (iterator it, action_ptr act)
 Replaces the action at a given position with another action. More...
 
template<typename T >
action_set::index< T >::type & get ()
 Returns a given index. More...
 
template<typename T >
action_set::index< T >::type const & get () const
 
template<typename T , typename U >
action_set::index< T >::type::iterator project (U it)
 Projects an iterator on a given index. More...
 
template<typename T , typename U >
action_set::index< T >::type::const_iterator project (U it) const
 
iterator begin ()
 Returns the iterator for the first (executed earlier) action within the actions queue. More...
 
reverse_iterator rbegin ()
 reverse version of the above More...
 
const_iterator begin () const
 const versions of the above More...
 
const_reverse_iterator rbegin () const
 const reverse versions of the above More...
 
iterator end ()
 Returns the iterator for the position after the last executed action within the actions queue. More...
 
reverse_iterator rend ()
 reverse version of the above More...
 
const_iterator end () const
 const versions of the above More...
 
const_reverse_iterator rend () const
 const reverse versions of the above More...
 
bool empty () const
 Indicates whether the action queue is empty. More...
 
std::size_t size () const
 Returns the number of actions in the action queue. More...
 
std::size_t num_turns () const
 Returns the number of turns that have plans. More...
 
std::size_t get_turn (const_iterator it) const
 Returns the turn of a given iterator planned execution. More...
 
std::size_t position_in_turn (const_iterator it) const
 Returns the position of a given iterator in its turn. More...
 
iterator turn_begin (std::size_t turn_num)
 Returns the iterator for the first (executed earlier) action of a given turn within the actions queue. More...
 
const_iterator turn_begin (std::size_t turn_num) const
 
reverse_iterator turn_rbegin (std::size_t turn_num)
 
const_reverse_iterator turn_rbegin (std::size_t turn_num) const
 
iterator turn_end (std::size_t turn_num)
 
const_iterator turn_end (std::size_t turn_num) const
 
reverse_iterator turn_rend (std::size_t turn_num)
 
const_reverse_iterator turn_rend (std::size_t turn_num) const
 
range_t iter_turn (std::size_t turn_num)
 Returns an iterator range corresponding to the requested turn. More...
 
rrange_t riter_turn (std::size_t turn_num)
 
crange_t iter_turn (std::size_t turn_num) const
 
crrange_t riter_turn (std::size_t turn_num) const
 
std::size_t turn_size (std::size_t turn_num) const
 Returns the number of actions planned for turn turn_num. More...
 
const action_setactions () const
 Get the underlying action container. More...
 
template<typename Modifier >
bool modify (iterator position, Modifier mod)
 

Private Member Functions

std::size_t get_turn_impl (std::size_t begin, std::size_t end, const_iterator it) const
 Binary search to find the occurring turn of the action pointed by an iterator. More...
 

Private Attributes

action_set actions_
 
action_limits turn_beginnings_
 Contains a list of iterator to the beginning of each turn. More...
 

Detailed Description

Datastructure holding the actions of a side on multiple turns.

Invariant
forall(t>0) if turn_size(t)==0 then turn_size(t+1)==0

Definition at line 41 of file side_actions.hpp.

Member Typedef Documentation

◆ action_limits

Definition at line 81 of file side_actions.hpp.

◆ action_set

typedef boost::multi_index::multi_index_container< action_ptr, boost::multi_index::indexed_by< boost::multi_index::random_access< boost::multi_index::tag< chronological > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< by_unit >, boost::multi_index::const_mem_fun< action, std::size_t, &action::get_unit_id > >, boost::multi_index::hashed_non_unique< boost::multi_index::tag< by_hex >, boost::multi_index::const_mem_fun< action, map_location, &action::get_numbering_hex > > > > wb::side_actions_container::action_set

Underlying container.

Definition at line 69 of file side_actions.hpp.

◆ const_iterator

typedef action_set::index<chronological>::type::const_iterator wb::side_actions_container::const_iterator

Definition at line 72 of file side_actions.hpp.

◆ const_reverse_iterator

typedef action_set::index<chronological>::type::const_reverse_iterator wb::side_actions_container::const_reverse_iterator

Definition at line 74 of file side_actions.hpp.

◆ crange_t

Definition at line 78 of file side_actions.hpp.

◆ crrange_t

Definition at line 79 of file side_actions.hpp.

◆ iterator

typedef action_set::index<chronological>::type::iterator wb::side_actions_container::iterator

Definition at line 71 of file side_actions.hpp.

◆ range_t

Definition at line 76 of file side_actions.hpp.

◆ reverse_iterator

typedef action_set::index<chronological>::type::reverse_iterator wb::side_actions_container::reverse_iterator

Definition at line 73 of file side_actions.hpp.

◆ rrange_t

Definition at line 77 of file side_actions.hpp.

Constructor & Destructor Documentation

◆ side_actions_container()

wb::side_actions_container::side_actions_container ( )

Definition at line 71 of file side_actions.cpp.

Member Function Documentation

◆ actions()

const action_set& wb::side_actions_container::actions ( ) const
inline

Get the underlying action container.

Definition at line 255 of file side_actions.hpp.

References actions_.

◆ begin() [1/2]

iterator wb::side_actions_container::begin ( )
inline

Returns the iterator for the first (executed earlier) action within the actions queue.

Definition at line 175 of file side_actions.hpp.

References actions_, and begin().

Referenced by begin(), wb::side_actions::begin(), BOOST_AUTO_TEST_CASE(), bump_earlier(), get_turn_impl(), and insert().

◆ begin() [2/2]

const_iterator wb::side_actions_container::begin ( ) const
inline

const versions of the above

Definition at line 179 of file side_actions.hpp.

References actions_.

◆ bump_earlier()

side_actions_container::iterator wb::side_actions_container::bump_earlier ( iterator  position)

Moves an action earlier in the execution order.

i.e. at the front of the queue by one position.

Returns
The action's new position.

Definition at line 187 of file side_actions.cpp.

References actions_, begin(), and end().

Referenced by wb::side_actions::bump_earlier(), and bump_later().

◆ bump_later()

side_actions_container::iterator wb::side_actions_container::bump_later ( iterator  position)

Moves an action later in the execution order.

i.e. at the back of the queue by one position.

Returns
The action's new position.

Definition at line 200 of file side_actions.cpp.

References bump_earlier().

◆ clear()

void wb::side_actions_container::clear ( )
inline

Empties the action queue.

Definition at line 140 of file side_actions.hpp.

References actions_, and turn_beginnings_.

Referenced by wb::side_actions::clear().

◆ empty()

bool wb::side_actions_container::empty ( ) const
inline

Indicates whether the action queue is empty.

Definition at line 197 of file side_actions.hpp.

References actions_.

Referenced by wb::side_actions::empty(), and wb::side_actions::execute().

◆ end() [1/2]

iterator wb::side_actions_container::end ( )
inline

Returns the iterator for the position after the last executed action within the actions queue.

Definition at line 186 of file side_actions.hpp.

References actions_, and end().

Referenced by bump_earlier(), end(), wb::side_actions::end(), erase(), wb::side_actions::execute(), wb::side_actions::find_first_action_of(), get_turn_impl(), insert(), push_front(), queue(), and turn_begin().

◆ end() [2/2]

const_iterator wb::side_actions_container::end ( ) const
inline

const versions of the above

Definition at line 190 of file side_actions.hpp.

References actions_.

◆ erase() [1/2]

side_actions_container::iterator wb::side_actions_container::erase ( iterator  first,
iterator  last 
)

Deletes the action at the specified position.

Returns
last

Definition at line 249 of file side_actions.cpp.

References erase().

◆ erase() [2/2]

side_actions_container::iterator wb::side_actions_container::erase ( iterator  position)

Deletes the action at the specified position.

Returns
The position of the element after the one deleted, or end() if the queue is empty.

Definition at line 205 of file side_actions.cpp.

References actions_, end(), get_turn(), size(), turn_beginnings_, and turn_end().

Referenced by BOOST_AUTO_TEST_CASE(), erase(), wb::side_actions::raw_turn_shift(), and wb::side_actions::safe_erase().

◆ get() [1/2]

template<typename T >
action_set::index<T>::type& wb::side_actions_container::get ( )
inline

◆ get() [2/2]

template<typename T >
action_set::index<T>::type const& wb::side_actions_container::get ( ) const
inline

Definition at line 162 of file side_actions.hpp.

References actions_.

◆ get_turn()

std::size_t wb::side_actions_container::get_turn ( const_iterator  it) const

Returns the turn of a given iterator planned execution.

The value returned is the difference between the planned turn and the current turn.

Return values
0If the action is planned for the current turn.

Definition at line 96 of file side_actions.cpp.

References get_turn_impl(), and num_turns().

Referenced by erase(), wb::side_actions::get_turn(), and position_in_turn().

◆ get_turn_impl()

std::size_t wb::side_actions_container::get_turn_impl ( std::size_t  begin,
std::size_t  end,
const_iterator  it 
) const
private

Binary search to find the occurring turn of the action pointed by an iterator.

Definition at line 77 of file side_actions.cpp.

References begin(), end(), ERR_WB, and turn_beginnings_.

Referenced by get_turn().

◆ insert()

side_actions_container::iterator wb::side_actions_container::insert ( iterator  position,
action_ptr  action 
)

Inserts an action at the specified position.

The planned turn of the inserted action is the same as the planned turn of position-1 before the insertion. If position == begin(), the new action will became the first action of the current turn.

Parameters
positionThe iterator before which action will be inserted.
actionThe action to insert.
Returns
The inserted action's position.
Return values
end()When the action can't be inserted.

Definition at line 140 of file side_actions.cpp.

References actions_, begin(), end(), and turn_beginnings_.

Referenced by BOOST_AUTO_TEST_CASE(), push_front(), wb::side_actions::safe_insert(), and wb::side_actions::synced_insert().

◆ iter_turn() [1/2]

range_t wb::side_actions_container::iter_turn ( std::size_t  turn_num)
inline

Returns an iterator range corresponding to the requested turn.

Definition at line 246 of file side_actions.hpp.

References turn_begin(), and turn_end().

Referenced by wb::side_actions::iter_turn().

◆ iter_turn() [2/2]

crange_t wb::side_actions_container::iter_turn ( std::size_t  turn_num) const
inline

Definition at line 248 of file side_actions.hpp.

References turn_begin(), and turn_end().

◆ modify()

template<typename Modifier >
bool wb::side_actions_container::modify ( iterator  position,
Modifier  mod 
)
inline

Definition at line 258 of file side_actions.hpp.

References actions_.

Referenced by wb::side_actions::update_recruited_unit().

◆ num_turns()

std::size_t wb::side_actions_container::num_turns ( ) const
inline

Returns the number of turns that have plans.

If the container holds only one action on turn 1 (that is turn 0 is empty), this function will still returns 2. Indeed, turn 0 has an "empty" plan.

Note
The current turn is counted. That is if num_turns()==0 then empty()==true.

Definition at line 211 of file side_actions.hpp.

References turn_beginnings_.

Referenced by BOOST_AUTO_TEST_CASE(), get_turn(), wb::side_actions::num_turns(), queue(), and turn_begin().

◆ position_in_turn()

std::size_t wb::side_actions_container::position_in_turn ( const_iterator  it) const

◆ project() [1/2]

template<typename T , typename U >
action_set::index<T>::type::iterator wb::side_actions_container::project ( it)
inline

Projects an iterator on a given index.

Definition at line 168 of file side_actions.hpp.

References actions_.

Referenced by wb::side_actions::find_first_action_of().

◆ project() [2/2]

template<typename T , typename U >
action_set::index<T>::type::const_iterator wb::side_actions_container::project ( it) const
inline

Definition at line 170 of file side_actions.hpp.

References actions_.

◆ push_front()

side_actions_container::iterator wb::side_actions_container::push_front ( std::size_t  turn,
action_ptr  action 
)

Pushes an action in front of a given turn.

Returns
The inserted action's position

Definition at line 123 of file side_actions.cpp.

References end(), insert(), queue(), turn_begin(), turn_beginnings_, and turn_size().

Referenced by wb::side_actions::safe_insert().

◆ queue()

side_actions_container::iterator wb::side_actions_container::queue ( std::size_t  turn_num,
action_ptr  action 
)

Queues an action to be executed last.

Returns
The queued action's position
Return values
end()when the action can't be inserted

Definition at line 157 of file side_actions.cpp.

References actions_, end(), num_turns(), turn_beginnings_, turn_end(), and turn_size().

Referenced by BOOST_AUTO_TEST_CASE(), push_front(), and wb::side_actions::synced_enqueue().

◆ rbegin() [1/2]

reverse_iterator wb::side_actions_container::rbegin ( )
inline

reverse version of the above

Definition at line 177 of file side_actions.hpp.

References actions_, and rbegin().

Referenced by rbegin(), and wb::side_actions::rbegin().

◆ rbegin() [2/2]

const_reverse_iterator wb::side_actions_container::rbegin ( ) const
inline

const reverse versions of the above

Definition at line 181 of file side_actions.hpp.

References actions_.

◆ rend() [1/2]

reverse_iterator wb::side_actions_container::rend ( )
inline

reverse version of the above

Definition at line 188 of file side_actions.hpp.

References actions_, and rend().

Referenced by rend(), and wb::side_actions::rend().

◆ rend() [2/2]

const_reverse_iterator wb::side_actions_container::rend ( ) const
inline

const reverse versions of the above

Definition at line 192 of file side_actions.hpp.

References actions_.

◆ replace()

bool wb::side_actions_container::replace ( iterator  it,
action_ptr  act 
)
inline

Replaces the action at a given position with another action.

Definition at line 153 of file side_actions.hpp.

References actions_.

Referenced by wb::side_actions::execute_net_cmd().

◆ riter_turn() [1/2]

rrange_t wb::side_actions_container::riter_turn ( std::size_t  turn_num)
inline

Definition at line 247 of file side_actions.hpp.

References turn_rbegin(), and turn_rend().

Referenced by wb::side_actions::riter_turn().

◆ riter_turn() [2/2]

crrange_t wb::side_actions_container::riter_turn ( std::size_t  turn_num) const
inline

Definition at line 249 of file side_actions.hpp.

References turn_rbegin(), and turn_rend().

◆ size()

std::size_t wb::side_actions_container::size ( ) const
inline

Returns the number of actions in the action queue.

Definition at line 202 of file side_actions.hpp.

References actions_.

Referenced by erase(), and wb::side_actions::size().

◆ turn_begin() [1/2]

side_actions_container::iterator wb::side_actions_container::turn_begin ( std::size_t  turn_num)

Returns the iterator for the first (executed earlier) action of a given turn within the actions queue.

Definition at line 106 of file side_actions.cpp.

References end(), num_turns(), and turn_beginnings_.

Referenced by BOOST_AUTO_TEST_CASE(), iter_turn(), position_in_turn(), push_front(), wb::side_actions::turn_begin(), turn_end(), turn_rend(), and turn_size().

◆ turn_begin() [2/2]

side_actions_container::const_iterator wb::side_actions_container::turn_begin ( std::size_t  turn_num) const

Definition at line 114 of file side_actions.cpp.

References end(), num_turns(), and turn_beginnings_.

◆ turn_end() [1/2]

iterator wb::side_actions_container::turn_end ( std::size_t  turn_num)
inline

◆ turn_end() [2/2]

const_iterator wb::side_actions_container::turn_end ( std::size_t  turn_num) const
inline

Definition at line 239 of file side_actions.hpp.

References turn_begin().

◆ turn_rbegin() [1/2]

reverse_iterator wb::side_actions_container::turn_rbegin ( std::size_t  turn_num)
inline

Definition at line 232 of file side_actions.hpp.

References turn_end().

Referenced by riter_turn(), and wb::side_actions::turn_rbegin().

◆ turn_rbegin() [2/2]

const_reverse_iterator wb::side_actions_container::turn_rbegin ( std::size_t  turn_num) const
inline

Definition at line 233 of file side_actions.hpp.

References turn_end().

◆ turn_rend() [1/2]

reverse_iterator wb::side_actions_container::turn_rend ( std::size_t  turn_num)
inline

Definition at line 240 of file side_actions.hpp.

References turn_begin().

Referenced by riter_turn(), and wb::side_actions::turn_rend().

◆ turn_rend() [2/2]

const_reverse_iterator wb::side_actions_container::turn_rend ( std::size_t  turn_num) const
inline

Definition at line 241 of file side_actions.hpp.

References turn_begin().

◆ turn_shift()

void wb::side_actions_container::turn_shift ( )
inline

Shift turn.

The turn 0 is deleted, the actions of turn n are moved to turn n-1.

Precondition
turn_size(0)==0

Definition at line 148 of file side_actions.hpp.

References turn_beginnings_, and turn_size().

Referenced by wb::side_actions::raw_turn_shift().

◆ turn_size()

std::size_t wb::side_actions_container::turn_size ( std::size_t  turn_num) const
inline

Returns the number of actions planned for turn turn_num.

Definition at line 252 of file side_actions.hpp.

References turn_begin(), and turn_end().

Referenced by BOOST_AUTO_TEST_CASE(), push_front(), queue(), turn_shift(), and wb::side_actions::turn_size().

Member Data Documentation

◆ actions_

action_set wb::side_actions_container::actions_
private

◆ turn_beginnings_

action_limits wb::side_actions_container::turn_beginnings_
private

Contains a list of iterator to the beginning of each turn.

Invariant
turn_beginnings_.front()==actions_.begin() || actions_.empty()

Definition at line 272 of file side_actions.hpp.

Referenced by clear(), erase(), get_turn_impl(), insert(), num_turns(), push_front(), queue(), turn_begin(), and turn_shift().


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