DHART
Loading...
Searching...
No Matches
HF::Pathfinding::BoostGraphDeleter Struct Reference

Deleter for the BoostGraph. More...

#include <path_finder.h>

Public Member Functions

void operator() (BoostGraph *bg) const
 Delete a boost graph. More...
 

Detailed Description

Deleter for the BoostGraph.

Remarks
BoostGraphDeleter is needed by std::unique_ptr to destroy a BoostGraph; it is not meant to be called directly.
Implementation based on standard library reference for unique pointer https://en.cppreference.com/w/cpp/memory/unique_ptr
Warning
BoostGraphDeleter is only for use with std::unique_ptr. You do not want to pass the address of a stack-allocated BoostGraph to BoostGraphDeleter.operator()(). BoostGraphDeleter.operator() calls operator delete on the (BoostGraph *) argument, and passing the address of a stack-allocated BoostGraph for said argument will result in undefined behavior.
See also
CreateBoostGraph for BoostGraphDeleter's intended use.

Definition at line 53 of file path_finder.h.

Member Function Documentation

◆ operator()()

void HF::Pathfinding::BoostGraphDeleter::operator() ( BoostGraph bg) const

Delete a boost graph.

Parameters
bgPointer to the boost graph to delete.
// be sure to #include "path_finder.h", #include "boost_graph.h", #include
// "node.h", #include "graph.h", and #include <vector>
// For this example, we must have a BoostGraph instance to use with
// BoostGraphDeleter. In order to create a BoostGraph, we must first create a
// Graph instance first. We must prepare the nodes, their edges, and the weights
// (distances) of each edge.
// Create the nodes
HF::SpatialStructures::Node node_0(1.0f, 1.0f, 2.0f);
HF::SpatialStructures::Node node_1(2.0f, 3.0f, 4.0f, 5);
HF::SpatialStructures::Node node_2(11.0f, 22.0f, 140.0f);
// Create a container (vector) of nodes
std::vector<HF::SpatialStructures::Node> nodes = { node_0, node_1, node_2 };
// Create matrices for edges and distances, edges.size() == distances().size()
std::vector<std::vector<int>> edges = { { 1, 2 }, { 2 }, { 1 } };
std::vector<std::vector<float>> distances = { { 1.0f, 2.5f }, { 54.0f }, { 39.0f } };
// Now you can create a Graph - note that nodes, edges, and distances are passed
// by reference
HF::SpatialStructures::Graph graph(edges, distances, nodes);
// Passing Graph graph to BoostGraph bg, by reference
// Read below on BoostGraphDeleter -- this is important.
// BoostGraphDeleter is needed by std::unique_ptr to destroy a BoostGraph; it is
// not meant to be called directly. You do not want to pass the address of a
// stack-allocated BoostGraph to BoostGraphDeleter::operator().
// BoostGraphDeleter's operator() calls operator delete on the (BoostGraph *)
// argument, and passing the address of a stack-allocated BoostGraph for said
// argument will result in undefined behavior.
// In other words, do __not__ do the following:
// Create a stack-allocated BoostGraph from a HF::SpatialStructures::Graph graph
HF::Pathfinding::BoostGraph boostGraph(graph); // not created using operator new
// Using a BoostGraphDeleter on the (address of a) stack-allocated BoostGraph
bg_deleter(&boostGraph); // calls operator delete for a (BoostGraph *)
A graph usable with the BoostGraphLibrary.
Definition: boost_graph.h:166
Deleter for the BoostGraph.
Definition: path_finder.h:53
A Graph of nodes connected by edges that supports both integers and HF::SpatialStructures::Node.
Definition: graph.h:486
A point in space with an ID.
Definition: node.h:38

Definition at line 325 of file path_finder.cpp.


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