Version: SMASH-2.0
smash::Actions Class Reference

#include <actions.h>

The Actions class abstracts the storage and manipulation of actions.

Note
The Actions object cannot be copied, because it does not make sense semantically. Move semantics make sense and can be implemented when needed.

Definition at line 29 of file actions.h.

Collaboration diagram for smash::Actions:
[legend]

Public Member Functions

 Actions ()
 Default constructor, creating an empty Actions object. More...
 
 Actions (ActionList &&action_list)
 Creates a new Actions object from an ActionList. More...
 
 Actions (const Actions &)=delete
 Cannot be copied. More...
 
Actionsoperator= (const Actions &)=delete
 Cannot be copied. More...
 
bool is_empty () const
 
ActionPtr pop ()
 Return the first action in the list and removes it from the list. More...
 
void insert (ActionList &&new_acts)
 Insert a list of actions into this object. More...
 
void insert (ActionPtr &&action)
 Insert an action into this container. More...
 
ActionList::size_type size () const
 
void clear ()
 Delete all actions. More...
 
std::vector< ActionPtr >::const_reverse_iterator begin () const
 
std::vector< ActionPtr >::const_reverse_iterator end () const
 

Static Private Member Functions

static bool cmp (const ActionPtr &a, const ActionPtr &b)
 Compare two action pointer such that the maximum is the most recent action. More...
 

Private Attributes

std::vector< ActionPtr > data_
 Dynamic data. More...
 

Constructor & Destructor Documentation

◆ Actions() [1/3]

smash::Actions::Actions ( )
inline

Default constructor, creating an empty Actions object.

Definition at line 32 of file actions.h.

32 {}

◆ Actions() [2/3]

smash::Actions::Actions ( ActionList &&  action_list)
inlineexplicit

Creates a new Actions object from an ActionList.

The actions are stored in a heap and not sorted. The entries of the ActionList are rendered invalid by this constructor.

Parameters
[in]action_listThe ActionList from which to construct the Actions object

Definition at line 42 of file actions.h.

42  : data_(std::move(action_list)) {
43  std::make_heap(data_.begin(), data_.end(), cmp);
44  }
Here is the call graph for this function:

◆ Actions() [3/3]

smash::Actions::Actions ( const Actions )
delete

Cannot be copied.

Member Function Documentation

◆ operator=()

Actions& smash::Actions::operator= ( const Actions )
delete

Cannot be copied.

◆ is_empty()

bool smash::Actions::is_empty ( ) const
inline
Returns
whether the list of actions is empty.

Definition at line 52 of file actions.h.

52 { return data_.empty(); }
Here is the caller graph for this function:

◆ pop()

ActionPtr smash::Actions::pop ( )
inline

Return the first action in the list and removes it from the list.

Exceptions
RuntimeErrorif the list is empty.

Definition at line 59 of file actions.h.

59  {
60  if (data_.empty()) {
61  throw std::runtime_error("Empty actions list!");
62  }
63  std::pop_heap(data_.begin(), data_.end(), cmp);
64  ActionPtr act = std::move(data_.back());
65  data_.pop_back();
66  return act;
67  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [1/2]

void smash::Actions::insert ( ActionList &&  new_acts)
inline

Insert a list of actions into this object.

They're inserted at the right places to keep the complete list a heap.

Parameters
[in]new_actsThe actions that will be inserted.

Definition at line 76 of file actions.h.

76  {
77  for (auto& a : new_acts) {
78  insert(std::move(a));
79  }
80  }
Here is the caller graph for this function:

◆ insert() [2/2]

void smash::Actions::insert ( ActionPtr &&  action)
inline

Insert an action into this container.

The function makes sure that the action is inserted at the right place.

Parameters
[in]actionThe action to insert.

Definition at line 89 of file actions.h.

89  {
90  data_.push_back(std::move(action));
91  std::push_heap(data_.begin(), data_.end(), cmp);
92  }
Here is the call graph for this function:

◆ size()

ActionList::size_type smash::Actions::size ( ) const
inline
Returns
Number of actions.

Definition at line 95 of file actions.h.

95 { return data_.size(); }
Here is the caller graph for this function:

◆ clear()

void smash::Actions::clear ( )
inline

Delete all actions.

Definition at line 98 of file actions.h.

98 { data_.clear(); }

◆ begin()

std::vector<ActionPtr>::const_reverse_iterator smash::Actions::begin ( ) const
inline
Returns
an iterator to the earliest action.

Definition at line 101 of file actions.h.

101  {
102  return data_.crbegin();
103  }

◆ end()

std::vector<ActionPtr>::const_reverse_iterator smash::Actions::end ( ) const
inline
Returns
an iterator to the place following the last action.

Definition at line 106 of file actions.h.

106  {
107  return data_.crend();
108  }

◆ cmp()

static bool smash::Actions::cmp ( const ActionPtr &  a,
const ActionPtr &  b 
)
inlinestaticprivate

Compare two action pointer such that the maximum is the most recent action.

Parameters
[in]aFirst action
[in]bSecond action
Returns
Whether the first action will be executed later than the second.

Definition at line 119 of file actions.h.

119  {
120  return a->time_of_execution() > b->time_of_execution();
121  }
Here is the caller graph for this function:

Member Data Documentation

◆ data_

std::vector<ActionPtr> smash::Actions::data_
private

Dynamic data.

Vector is likely the best container type here. Because std::sort requires random access iterators. Any linked data structure (e.g. list) thus requires a less efficient sort algorithm.

Definition at line 130 of file actions.h.


The documentation for this class was generated from the following file:
smash::Actions::data_
std::vector< ActionPtr > data_
Dynamic data.
Definition: actions.h:130
smash::Actions::insert
void insert(ActionList &&new_acts)
Insert a list of actions into this object.
Definition: actions.h:76
smash::Actions::cmp
static bool cmp(const ActionPtr &a, const ActionPtr &b)
Compare two action pointer such that the maximum is the most recent action.
Definition: actions.h:119