The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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, 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,
iterator
range_t
 
typedef std::pair
< reverse_iterator,
reverse_iterator
rrange_t
 
typedef std::pair
< const_iterator,
const_iterator
crange_t
 
typedef std::pair
< const_reverse_iterator,
const_reverse_iterator
crrange_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 (size_t turn_num, action_ptr action)
 Queues an action to be executed last. More...
 
iterator push_front (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 >::typeget ()
 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...
 
size_t size () const
 Returns the number of actions in the action queue. More...
 
size_t num_turns () const
 Returns the number of turns that have plans. More...
 
size_t get_turn (const_iterator it) const
 Returns the turn of a given iterator planned execution. More...
 
size_t position_in_turn (const_iterator it) const
 Returns the position of a given iterator in its turn. More...
 
iterator turn_begin (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 (size_t turn_num) const
 
reverse_iterator turn_rbegin (size_t turn_num)
 
const_reverse_iterator turn_rbegin (size_t turn_num) const
 
iterator turn_end (size_t turn_num)
 
const_iterator turn_end (size_t turn_num) const
 
reverse_iterator turn_rend (size_t turn_num)
 
const_reverse_iterator turn_rend (size_t turn_num) const
 
range_t iter_turn (size_t turn_num)
 Returns an iterator range corresponding to the requested turn. More...
 
rrange_t riter_turn (size_t turn_num)
 
crange_t iter_turn (size_t turn_num) const
 
crrange_t riter_turn (size_t turn_num) const
 
size_t turn_size (size_t turn_num) const
 Returns the number of actions planned for turn turn_num. More...
 
action_set const & actions () const
 Get the underlying action container. More...
 

Private Member Functions

size_t get_turn_impl (size_t begin, size_t end, const_iterator it) const
 Binary search to find the occuring 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 42 of file side_actions.hpp.

Member Typedef Documentation

Definition at line 82 of file side_actions.hpp.

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, 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 70 of file side_actions.hpp.

Definition at line 73 of file side_actions.hpp.

Definition at line 75 of file side_actions.hpp.

Definition at line 79 of file side_actions.hpp.

Definition at line 80 of file side_actions.hpp.

Definition at line 72 of file side_actions.hpp.

Definition at line 77 of file side_actions.hpp.

Definition at line 74 of file side_actions.hpp.

Definition at line 78 of file side_actions.hpp.

Constructor & Destructor Documentation

wb::side_actions_container::side_actions_container ( )

Definition at line 72 of file side_actions.cpp.

Member Function Documentation

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

Get the underlying action container.

Definition at line 256 of file side_actions.hpp.

References actions_.

iterator wb::side_actions_container::begin ( )
inline

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

Definition at line 176 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().

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

const versions of the above

Definition at line 180 of file side_actions.hpp.

References actions_.

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 184 of file side_actions.cpp.

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

Referenced by wb::side_actions::bump_earlier(), and 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 197 of file side_actions.cpp.

References bump_earlier().

void wb::side_actions_container::clear ( )
inline

Empties the action queue.

Definition at line 141 of file side_actions.hpp.

References actions_, and turn_beginnings_.

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

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

Indicates whether the action queue is empty.

Definition at line 198 of file side_actions.hpp.

References actions_.

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

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 187 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().

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

const versions of the above

Definition at line 191 of file side_actions.hpp.

References actions_.

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 202 of file side_actions.cpp.

References actions_, end(), gui2::event::find(), get_turn(), next, 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().

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 238 of file side_actions.cpp.

References erase().

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

Definition at line 163 of file side_actions.hpp.

References actions_.

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 93 of file side_actions.cpp.

References get_turn_impl(), and num_turns().

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

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

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

Definition at line 78 of file side_actions.cpp.

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

Referenced by get_turn().

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 137 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().

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

Returns an iterator range corresponding to the requested turn.

Definition at line 247 of file side_actions.hpp.

References turn_begin(), and turn_end().

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

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

Definition at line 249 of file side_actions.hpp.

References turn_begin(), and turn_end().

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 212 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().

size_t wb::side_actions_container::position_in_turn ( const_iterator  it) const
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 169 of file side_actions.hpp.

References actions_.

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

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

Definition at line 171 of file side_actions.hpp.

References actions_.

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

Pushes an action in front of a given turn.

Returns
The inserted action's position

Definition at line 120 of file side_actions.cpp.

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

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

side_actions_container::iterator wb::side_actions_container::queue ( 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 154 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().

reverse_iterator wb::side_actions_container::rbegin ( )
inline

reverse version of the above

Definition at line 178 of file side_actions.hpp.

References actions_, and rbegin().

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

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

const reverse versions of the above

Definition at line 182 of file side_actions.hpp.

References actions_.

reverse_iterator wb::side_actions_container::rend ( )
inline

reverse version of the above

Definition at line 189 of file side_actions.hpp.

References actions_, and rend().

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

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

const reverse versions of the above

Definition at line 193 of file side_actions.hpp.

References actions_.

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 154 of file side_actions.hpp.

References actions_.

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

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

Definition at line 248 of file side_actions.hpp.

References turn_rbegin(), and turn_rend().

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

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

Definition at line 250 of file side_actions.hpp.

References turn_rbegin(), and turn_rend().

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

Returns the number of actions in the action queue.

Definition at line 203 of file side_actions.hpp.

References actions_.

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

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

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

Definition at line 103 of file side_actions.cpp.

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

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

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

Definition at line 111 of file side_actions.cpp.

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

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

Definition at line 239 of file side_actions.hpp.

References turn_begin().

Referenced by erase(), iter_turn(), queue(), wb::side_actions::turn_end(), turn_rbegin(), and turn_size().

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

Definition at line 240 of file side_actions.hpp.

References turn_begin().

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

Definition at line 233 of file side_actions.hpp.

References turn_end().

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

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

Definition at line 234 of file side_actions.hpp.

References turn_end().

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

Definition at line 241 of file side_actions.hpp.

References turn_begin().

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

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

Definition at line 242 of file side_actions.hpp.

References turn_begin().

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 149 of file side_actions.hpp.

References turn_beginnings_, and turn_size().

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

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

Returns the number of actions planned for turn turn_num.

Definition at line 253 of file side_actions.hpp.

References turn_begin(), and turn_end().

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

Member Data Documentation

action_set wb::side_actions_container::actions_
private
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: