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, 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< iterator > | action_limits |
Public Member Functions | |
side_actions_container () | |
iterator | insert (iterator position, const action_ptr &action) |
Inserts an action at the specified position. More... | |
iterator | queue (std::size_t turn_num, const action_ptr &action) |
Queues an action to be executed last. More... | |
iterator | push_front (std::size_t turn, const 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_set & | actions () 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... | |
Datastructure holding the actions of a side on multiple turns.
Definition at line 41 of file side_actions.hpp.
typedef std::deque<iterator> wb::side_actions_container::action_limits |
Definition at line 81 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, 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.
typedef action_set::index<chronological>::type::const_iterator wb::side_actions_container::const_iterator |
Definition at line 72 of file side_actions.hpp.
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.
typedef std::pair<const_iterator,const_iterator> wb::side_actions_container::crange_t |
Definition at line 78 of file side_actions.hpp.
typedef std::pair<const_reverse_iterator,const_reverse_iterator> wb::side_actions_container::crrange_t |
Definition at line 79 of file side_actions.hpp.
typedef action_set::index<chronological>::type::iterator wb::side_actions_container::iterator |
Definition at line 71 of file side_actions.hpp.
typedef std::pair<iterator,iterator> wb::side_actions_container::range_t |
Definition at line 76 of file side_actions.hpp.
typedef action_set::index<chronological>::type::reverse_iterator wb::side_actions_container::reverse_iterator |
Definition at line 73 of file side_actions.hpp.
typedef std::pair<reverse_iterator,reverse_iterator> wb::side_actions_container::rrange_t |
Definition at line 77 of file side_actions.hpp.
wb::side_actions_container::side_actions_container | ( | ) |
Definition at line 72 of file side_actions.cpp.
|
inline |
Get the underlying action container.
Definition at line 255 of file side_actions.hpp.
References actions_.
|
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().
|
inline |
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.
Definition at line 188 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.
Definition at line 201 of file side_actions.cpp.
References bump_earlier().
|
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().
|
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().
|
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().
|
inline |
side_actions_container::iterator wb::side_actions_container::erase | ( | iterator | first, |
iterator | last | ||
) |
Deletes the action at the specified position.
Definition at line 250 of file side_actions.cpp.
References erase().
side_actions_container::iterator wb::side_actions_container::erase | ( | iterator | position | ) |
Deletes the action at the specified position.
Definition at line 206 of file side_actions.cpp.
References actions_, end(), utils::find(), 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().
|
inline |
Returns a given index.
Definition at line 160 of file side_actions.hpp.
References actions_.
Referenced by wb::side_actions::actions_of(), wb::side_actions::count_actions_of(), wb::side_actions::find_first_action_at(), wb::side_actions::find_first_action_of(), wb::side_actions::find_last_action_of(), and wb::side_actions::unit_has_actions().
|
inline |
Definition at line 162 of file side_actions.hpp.
References actions_.
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.
0 | If the action is planned for the current turn. |
Definition at line 97 of file side_actions.cpp.
References get_turn_impl(), and num_turns().
Referenced by erase(), wb::side_actions::get_turn(), and position_in_turn().
|
private |
Binary search to find the occurring turn of the action pointed by an iterator.
Definition at line 78 of file side_actions.cpp.
References begin(), end(), ERR_WB, and turn_beginnings_.
Referenced by get_turn().
side_actions_container::iterator wb::side_actions_container::insert | ( | iterator | position, |
const 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.
position | The iterator before which action will be inserted. |
action | The action to insert. |
end() | When the action can't be inserted. |
Definition at line 141 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().
|
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().
|
inline |
Definition at line 248 of file side_actions.hpp.
References turn_begin(), and turn_end().
|
inline |
Definition at line 258 of file side_actions.hpp.
References actions_.
Referenced by wb::side_actions::update_recruited_unit().
|
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.
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().
std::size_t wb::side_actions_container::position_in_turn | ( | const_iterator | it | ) | const |
Returns the position of a given iterator in its turn.
Definition at line 102 of file side_actions.cpp.
References get_turn(), and turn_begin().
Referenced by wb::side_actions::bump_earlier(), wb::side_actions::insert_action(), wb::side_actions::make_net_cmd_bump_later(), wb::side_actions::make_net_cmd_insert(), wb::side_actions::make_net_cmd_refresh(), wb::side_actions::make_net_cmd_remove(), wb::side_actions::make_net_cmd_replace(), and wb::side_actions::remove_action().
|
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().
|
inline |
Definition at line 170 of file side_actions.hpp.
References actions_.
side_actions_container::iterator wb::side_actions_container::push_front | ( | std::size_t | turn, |
const action_ptr & | action | ||
) |
Pushes an action in front of a given turn.
Definition at line 124 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 | ( | std::size_t | turn_num, |
const action_ptr & | action | ||
) |
Queues an action to be executed last.
end() | when the action can't be inserted |
Definition at line 158 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().
|
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().
|
inline |
const reverse versions of the above
Definition at line 181 of file side_actions.hpp.
References actions_.
|
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().
|
inline |
const reverse versions of the above
Definition at line 192 of file side_actions.hpp.
References actions_.
|
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().
|
inline |
Definition at line 247 of file side_actions.hpp.
References turn_rbegin(), and turn_rend().
Referenced by wb::side_actions::riter_turn().
|
inline |
Definition at line 249 of file side_actions.hpp.
References turn_rbegin(), and turn_rend().
|
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().
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 107 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().
side_actions_container::const_iterator wb::side_actions_container::turn_begin | ( | std::size_t | turn_num | ) | const |
Definition at line 115 of file side_actions.cpp.
References end(), num_turns(), and turn_beginnings_.
|
inline |
Definition at line 238 of file side_actions.hpp.
References turn_begin().
Referenced by BOOST_AUTO_TEST_CASE(), erase(), iter_turn(), queue(), wb::side_actions::turn_end(), turn_rbegin(), and turn_size().
|
inline |
Definition at line 239 of file side_actions.hpp.
References turn_begin().
|
inline |
Definition at line 232 of file side_actions.hpp.
References turn_end().
Referenced by riter_turn(), and wb::side_actions::turn_rbegin().
|
inline |
Definition at line 233 of file side_actions.hpp.
References turn_end().
|
inline |
Definition at line 240 of file side_actions.hpp.
References turn_begin().
Referenced by riter_turn(), and wb::side_actions::turn_rend().
|
inline |
Definition at line 241 of file side_actions.hpp.
References turn_begin().
|
inline |
Shift turn.
The turn 0 is deleted, the actions of turn n are moved to turn n-1.
Definition at line 148 of file side_actions.hpp.
References turn_beginnings_, and turn_size().
Referenced by wb::side_actions::raw_turn_shift().
|
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().
|
private |
|
private |
Contains a list of iterator to the beginning of each turn.
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().