Fawkes API  Fawkes Development Version
fawkes::NavGraphPath::Traversal Class Reference

Sub-class representing a navgraph path traversal. More...

#include <>>

Public Member Functions

 Traversal ()
 Constructor. More...
 
 Traversal (const NavGraphPath *path)
 Constructor. More...
 
const NavGraphNodecurrent () const
 Get current node in path. More...
 
const NavGraphNodepeek_next () const
 Peek on the next node. More...
 
size_t current_index () const
 Get index of current node in path. More...
 
bool next ()
 Move on traversal to next node. More...
 
void reset ()
 Reset an ongoing traversal. More...
 
bool last () const
 Check if the current node is the last node in the path. More...
 
size_t remaining () const
 Get the number of remaining nodes in path traversal. More...
 
float remaining_cost () const
 Get the remaining cost to the goal. More...
 
bool running () const
 Check if traversal is currently runnung. More...
 
void invalidate ()
 Invalidate this traversal. More...
 
void set_current (size_t new_current)
 Set the current node. More...
 
const NavGraphPathpath () const
 Get parent path the traversal belongs to. More...
 
 operator bool () const
 Check if traversal is initialized. More...
 

Friends

class NavGraphPath
 

Detailed Description

Sub-class representing a navgraph path traversal.

A traversal is a step-by-step run through the node sequence (in order). There maybe any number of traversal open for a given path. But they become invalid should new nodes be set on the path. After creating a new traversal, you always need to call next for each new node including the first one. Code could look like this.

NavGraphPath path = navgraph->search_path("from-here", "to-there");
NavGraphPath::Traversal traversal = path.traversal();
while (traversal.next()) {
const NavGraphNode &current = traversal.current();
// operate on node
if (traversal.last()) {
// current is the last node on the path and traversal
// will end after this iteration.
}
}
Author
Tim Niemueller

Definition at line 41 of file navgraph_path.h.

Constructor & Destructor Documentation

◆ Traversal() [1/2]

fawkes::NavGraphPath::Traversal::Traversal ( )

Constructor.

Definition at line 248 of file navgraph_path.cpp.

◆ Traversal() [2/2]

fawkes::NavGraphPath::Traversal::Traversal ( const NavGraphPath path)

Constructor.

Parameters
pathparent path to traverse

Definition at line 257 of file navgraph_path.cpp.

Member Function Documentation

◆ current()

const NavGraphNode & fawkes::NavGraphPath::Traversal::current ( ) const

Get current node in path.

Returns
current node in traversal
Exceptions
Exceptionif no traversal is active, i.e. next() has not been called after a traversal reset or if the path has already been traversed completley.

Definition at line 287 of file navgraph_path.cpp.

Referenced by NavGraphThread::loop().

◆ current_index()

size_t fawkes::NavGraphPath::Traversal::current_index ( ) const

Get index of current node in path.

Returns
index of current node in traversal
Exceptions
Exceptionif no traversal is active, i.e. next() has not been called after a traversal reset or if the path has already been traversed completley.

Definition at line 333 of file navgraph_path.cpp.

Referenced by NavGraphThread::fam_event(), and NavGraphThread::loop().

◆ invalidate()

void fawkes::NavGraphPath::Traversal::invalidate ( )

Invalidate this traversal.

This will reset the parent path and the current node. This traversal can now longer be used afterwards other than assigning a new traversal.

Definition at line 269 of file navgraph_path.cpp.

Referenced by NavGraphThread::loop(), NavGraphVisualizationThread::reset_plan(), and NavGraphVisualizationThread::set_graph().

◆ last()

bool fawkes::NavGraphPath::Traversal::last ( ) const

Check if the current node is the last node in the path.

Returns
true if the current node is the last node in the path, false otherwise

Definition at line 361 of file navgraph_path.cpp.

Referenced by NavGraphVisualizationThread::loop(), and NavGraphThread::loop().

◆ next()

bool fawkes::NavGraphPath::Traversal::next ( )

Move on traversal to next node.

Returns
bool, if there was another node to traverse, false otherwise

Definition at line 347 of file navgraph_path.cpp.

Referenced by NavGraphThread::loop().

◆ operator bool()

fawkes::NavGraphPath::Traversal::operator bool ( ) const
inline

◆ path()

const NavGraphPath& fawkes::NavGraphPath::Traversal::path ( ) const
inline

Get parent path the traversal belongs to.

Returns
parent path

Definition at line 63 of file navgraph_path.h.

Referenced by NavGraphThread::fam_event(), NavGraphVisualizationThread::loop(), and NavGraphThread::loop().

◆ peek_next()

const NavGraphNode & fawkes::NavGraphPath::Traversal::peek_next ( ) const

Peek on the next node.

Get the node following the current node without advancing the current index (the current node remains the same).

Returns
node following the current node
Exceptions
OutOfBoundsExceptionif the traversal has not been started with an initial call to next() or if the traversal has already ended or is currently at the last node.

Definition at line 307 of file navgraph_path.cpp.

Referenced by NavGraphThread::loop().

◆ remaining()

size_t fawkes::NavGraphPath::Traversal::remaining ( ) const

Get the number of remaining nodes in path traversal.

The number of remaining nodes is the number of nodes including the current node up until the last node in the path.

Returns
number of remaining nodes in path traversal

Definition at line 374 of file navgraph_path.cpp.

Referenced by NavGraphThread::fam_event(), NavGraphVisualizationThread::loop(), and NavGraphThread::loop().

◆ remaining_cost()

float fawkes::NavGraphPath::Traversal::remaining_cost ( ) const

Get the remaining cost to the goal.

This sums the costs from the current to the goal node using the default registered cost function of the parent navgraph.

Returns
cost from current to goal node

Definition at line 388 of file navgraph_path.cpp.

References fawkes::NavGraphPath::cost(), and fawkes::NavGraph::cost().

Referenced by NavGraphThread::loop().

◆ reset()

void fawkes::NavGraphPath::Traversal::reset ( void  )

Reset an ongoing traversal.

A new traversal afterwards will start the traversal from the beginning.

Definition at line 410 of file navgraph_path.cpp.

◆ running()

bool fawkes::NavGraphPath::Traversal::running ( ) const

Check if traversal is currently runnung.

Returns
true if current() will return a valid result

Definition at line 322 of file navgraph_path.cpp.

Referenced by NavGraphThread::fam_event(), and NavGraphThread::loop().

◆ set_current()

void fawkes::NavGraphPath::Traversal::set_current ( size_t  new_current)

Set the current node.

Parameters
new_currentnew current node
Exceptions
OutOfBoundsExceptionthrown if new current node is beyond number of nodes in path.

Definition at line 422 of file navgraph_path.cpp.

Referenced by NavGraphThread::loop().


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