DHART
Loading...
Searching...
No Matches
HF::SpatialStructures::Path Struct Reference

A collection of nodes that form a path. More...

#include <path.h>

+ Collaboration diagram for HF::SpatialStructures::Path:

Public Member Functions

 Path::Path ()
 Construct an empty path. More...
 
 Path::Path (const std::vector< PathMember > &pm)
 Construct a path from an ordered list of PathMembers. More...
 
void AddNode (int node, float cost)
 Add a new node to the path. More...
 
bool empty () const
 Determine if this path has any nodes in it. More...
 
int size () const
 Determine how many nodes are in this path. More...
 
void Reverse ()
 Reverse the direction of this path. More...
 
bool operator== (const Path &p2) const
 Determine if this path is identical to p2. More...
 
PathMember operator[] (int i) const
 Retrieve the node and cost in this path at index i. More...
 
PathMemberGetPMPointer ()
 Get a pointer to the path's underlying path members vector. More...
 

Public Attributes

std::vector< PathMembermembers
 Ordered array of PathMembers that comprise the path. More...
 

Detailed Description

A collection of nodes that form a path.

Definition at line 76 of file path.h.

Member Function Documentation

◆ AddNode()

void HF::SpatialStructures::Path::AddNode ( int  node,
float  cost 
)

Add a new node to the path.

Constructs a PathMember and appends it to the underlying members vector.

Parameters
nodeThe identifier for the PathMember
costThe cost (weight) for the PathMember
// be sure to #include "path.h"
// Create the PathMembers
// Create the container of PathMembers
std::vector<HF::SpatialStructures::PathMember> members{ p0, p1, p2, p3 };
// Create the path, using the container of PathMembers
int node_id = 278;
float cost = 8.92f;
path.AddNode(node_id, cost); // A PathMember is constructed within AddNode from node_id and cost
// and is then appended to the underlying
// members vector (via push_back)
The ID of a node, and the cost cost to the node after it.
Definition: path.h:19
A collection of nodes that form a path.
Definition: path.h:76
std::vector< PathMember > members
Ordered array of PathMembers that comprise the path.
Definition: path.h:78

Definition at line 12 of file path.cpp.

References members.

Referenced by HF::Pathfinding::ConstructShortestPathFromPred().

+ Here is the caller graph for this function:

◆ empty()

bool HF::SpatialStructures::Path::empty ( ) const

Determine if this path has any nodes in it.

Checks if the size of members is zero.

Returns
True if the underyling members vector is empty, false otherwise
// be sure to #include "path.h"
// There are no PathMembers in path's members container.
// if empty() returns true, that means the underlying members vector is of size 0
// (no members) otherwise, empty returns false. In this case, path.empty() returns true.
std::string result = path.empty() ? "is empty" : "has at least one member";
std::cout << "The Path object " << result << std::endl;
bool empty() const
Determine if this path has any nodes in it.
Definition: path.cpp:16

Definition at line 16 of file path.cpp.

References members.

Referenced by CreatePath().

+ Here is the caller graph for this function:

◆ GetPMPointer()

PathMember * HF::SpatialStructures::Path::GetPMPointer ( )

Get a pointer to the path's underlying path members vector.

// be sure to #include "path.h"
// Create the PathMembers
// Create the container of PathMembers
std::vector<HF::SpatialStructures::PathMember> members{p0, p1, p2, p3};
HF::SpatialStructures::Path path(members); // Create the Path object, path
HF::SpatialStructures::PathMember *ptr = path.GetPMPointer();
// You now have a pointer to the underlying buffer of the members vector with in a PathMember.
HF::SpatialStructures::PathMember *finish = ptr + path.size();
while (curr != finish) {
std::cout << "Cost: " << curr->cost << " "
<< "Node: " << curr->node << std::endl;
++curr;
}
float cost
Cost of traversing to the next path member in the path.
Definition: path.h:20
int node
ID of the node this represents in the graph.
Definition: path.h:21

Definition at line 56 of file path.cpp.

References members.

Referenced by CreatePath(), GetPathInfo(), and HF::Pathfinding::InsertPathsIntoArray().

+ Here is the caller graph for this function:

◆ operator==()

bool HF::SpatialStructures::Path::operator== ( const Path p2) const

Determine if this path is identical to p2.

Parameters
p2The Path to compare against this path
Returns
True, if all PathMember elements in p2 are equal to all PathMember elements in this path, false otherwise
See also
PathMember.operator==()
// be sure to #include "path.h"
HF::SpatialStructures::PathMember p0 = { 3.14f, 3 }; // Create all the PathMember objects
std::vector<HF::SpatialStructures::PathMember> members_0{p0, p1}; // Create the HF::SpatialStructures::PathMember vectors
std::vector<HF::SpatialStructures::PathMember> members_1{p2, p3};
std::vector<HF::SpatialStructures::PathMember> members_2{p4, p5};
std::vector<HF::SpatialStructures::PathMember> members_3{p1, p0};
HF::SpatialStructures::Path path_0(members_0); // Create the Path objects
HF::SpatialStructures::Path path_1(members_1);
HF::SpatialStructures::Path path_2(members_2);
HF::SpatialStructures::Path path_3(members_3);
bool same_values_same_order = path_0 == path_1;
bool totally_different = path_0 == path_2;
bool same_values_different_order = path_0 == path_3;
// path_0 and path_1 share the same PathMember values, with an identical permutation, so
// they are equivalent.
// path_0 and path_2 are not equivalent, because they have completely different
// PathMember values.
// path_0 and path_3 are not equivalent, because although they have PathMember objects
// of the same values, the order in which path_0 and path_3 have their member vectors
// arranged are different.

Definition at line 28 of file path.cpp.

References size().

+ Here is the call graph for this function:

◆ operator[]()

PathMember HF::SpatialStructures::Path::operator[] ( int  i) const

Retrieve the node and cost in this path at index i.

Parameters
iThe index for the desired PathMember element within members.
Returns
A PathMember within the members vector, at index i, by value.
Exceptions
std::out_of_rangei extended past the number of nodes in the path.
// be sure to #include "path.h"
// Create the PathMembers
// Create the container of PathMembers
std::vector<HF::SpatialStructures::PathMember> members{p0, p1, p2, p3};
HF::SpatialStructures::Path path(members); // Create the Path object, path
const int desired_index = 2;
HF::SpatialStructures::PathMember result = path[desired_index]; // a copy of the element at desired_index
// within the
// internal members
// vector is
// assigned to result

Definition at line 48 of file path.cpp.

References members.

◆ Path::Path() [1/2]

HF::SpatialStructures::Path::Path::Path ( )
inline

Construct an empty path.

// be sure to #include "path.h"

Definition at line 88 of file path.h.

◆ Path::Path() [2/2]

HF::SpatialStructures::Path::Path::Path ( const std::vector< PathMember > &  pm)

Construct a path from an ordered list of PathMembers.

// be sure to #include "path.h"
// Create the PathMembers
// Create the container of PathMembers
std::vector<HF::SpatialStructures::PathMember> members{p0, p1, p2, p3};
// Create the path, using the container of PathMembers

◆ Reverse()

void HF::SpatialStructures::Path::Reverse ( )

Reverse the direction of this path.

Invokes std::reverse to reverse the contents of the underlying members vector using iterators

// be sure to #include "path.h"
// Create the PathMembers
// Create the container of PathMembers
std::vector<HF::SpatialStructures::PathMember> members{p0, p1, p2, p3};
HF::SpatialStructures::Path path(members); // Create the Path object, path
path.AddNode(278, 3.14f); // Append one more PathMember to path
path.Reverse(); // The order of the PathMembers within members is now that of
// p3, p2, p1, p0

Definition at line 24 of file path.cpp.

References members.

Referenced by HF::Pathfinding::ConstructShortestPathFromPred().

+ Here is the caller graph for this function:

◆ size()

int HF::SpatialStructures::Path::size ( ) const

Determine how many nodes are in this path.

Returns
The length of this path.
// be sure to #include "path.h"
// Create the PathMembers
// Create the container of PathMembers
std::vector<HF::SpatialStructures::PathMember> members{p0, p1, p2, p3};
HF::SpatialStructures::Path path(members); // Create the Path object, path
path.AddNode(278, 3.14f); // Add one more PathMember to path
std::string result = path.size() >= 5 ? "at least 5 members" : "under 5 members";
std::cout << "The Path object has " << result << std::endl;

Definition at line 20 of file path.cpp.

References members.

Referenced by HF::Pathfinding::ConstructShortestPathFromPred(), CreatePath(), GetPathInfo(), HF::Pathfinding::InsertPathsIntoArray(), std::operator<<(), and operator==().

+ Here is the caller graph for this function:

Member Data Documentation

◆ members

std::vector<PathMember> HF::SpatialStructures::Path::members

Ordered array of PathMembers that comprise the path.

Definition at line 78 of file path.h.

Referenced by AddNode(), empty(), GetPMPointer(), operator[](), Reverse(), and size().


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