166 lines
4.8 KiB
C++
166 lines
4.8 KiB
C++
#pragma once
|
|
#include <new>
|
|
#include <utility>
|
|
#include <string>
|
|
|
|
|
|
/** @struct Point
|
|
* @param x width value
|
|
* @param y heighth value
|
|
* @param z Depth value
|
|
* @param first_edge Offset of the first edge in memory for a point.
|
|
* @param e_count Number of edges for a point.
|
|
*/
|
|
struct Point {
|
|
std::string name;
|
|
float x, y, z;
|
|
int first_edge = -1;
|
|
int e_count = 0;
|
|
bool is_active = false;
|
|
};
|
|
|
|
|
|
/** @struct Edge
|
|
* @brief Stores the end point and weight of the edge.
|
|
* @param end_point Index of the point this edge goes to.
|
|
* @param e_weight Weight of the edge.
|
|
* @param next_edge Memory location of the next edge in the Edge Buffer.
|
|
*/
|
|
struct Edge {
|
|
int end_point;
|
|
float e_weight;
|
|
int next_edge = -1;
|
|
};
|
|
|
|
/** @class Graph
|
|
* @brief Defines the default values for the private variables.
|
|
*
|
|
* @param next_free_point The index of the next memory location in the Point buffer, where the next added point will go.
|
|
* @param num_points The number of points currently being stored in the Point buffer.
|
|
*
|
|
* @param next_free_edge The index of the next memory locaiton in the Edge buffer where the next added edge will go.
|
|
* @param num_edges The number of edges currently being stored in the buffer.
|
|
*
|
|
* @param next_possible_edge The offset to the next possible edge memory location.
|
|
*
|
|
* @param p_capacity The total number of points able to be stored in the buffer.
|
|
* @param e_capacity The total number of edges able to be stored in the buffer.
|
|
*
|
|
* @param all_points The buffer that stores all of the points in the graph.
|
|
* @param all_edges The buffer that stores all the edges in the graph.
|
|
*/
|
|
class Graph {
|
|
private:
|
|
int next_free_point = -1;
|
|
size_t num_points = 0;
|
|
|
|
int next_free_edge = -1;
|
|
size_t num_edges = 0;
|
|
|
|
size_t next_possible_edge = 0;
|
|
|
|
size_t p_capacity = 0;
|
|
size_t e_capacity = 0;
|
|
|
|
Point* all_points = nullptr;
|
|
Edge* all_edges = nullptr;
|
|
public:
|
|
|
|
/** Constructor
|
|
* @brief Creates a new Graph.
|
|
* @param max_points Maximum number of points in the Graph.
|
|
* @param max_edges Maximum number of edges in the Graph.
|
|
*/
|
|
Graph(size_t p_capacity, size_t e_capacity) noexcept;
|
|
|
|
|
|
/** Deconstructor
|
|
* @brief Deletes all_points and all_edges from memory
|
|
*/
|
|
~Graph();
|
|
|
|
/** Move Constructor
|
|
* @brief Instructions to move the current graph object from one memory location to another without copying.
|
|
* @param new_location The new memory location to move the graph to.
|
|
*/
|
|
Graph(Graph&& new_location) noexcept;
|
|
|
|
/** Debug Function: print_graph
|
|
* @brief Prints all points and their edges.
|
|
*
|
|
* @return Console print statement.
|
|
*/
|
|
void print_graph() noexcept;
|
|
|
|
/** Debug Function: print_points
|
|
* @brief Prints all points.
|
|
*
|
|
* @returns Console print statement.
|
|
*/
|
|
void print_points() noexcept;
|
|
/** Debug function: print_edges
|
|
* @brief Prints all edges.
|
|
*
|
|
* @returns Console print statement.
|
|
*/
|
|
void print_edges() noexcept;
|
|
|
|
/** Getter Function: get_points
|
|
* @brief Gets the memory address of all of the points on given graph.
|
|
*
|
|
* @returns The address of the first Point in the graph.
|
|
*/
|
|
Point* get_points() noexcept;
|
|
|
|
/** Getter Function: get_p_edges
|
|
* @brief Gets the address of the first edge for Point P at index p_index.
|
|
*
|
|
* @param p_index The index (int) of the point.
|
|
* @returns Edge* : the address of the first edge for p_index.
|
|
* */
|
|
Edge* get_p_edges(int p_index) noexcept;
|
|
|
|
/** add_point
|
|
* @brief Adds a point onto the graph.
|
|
*
|
|
* @param name The name of the point.
|
|
* @param x The width value.
|
|
* @param y The heighth value.
|
|
* @param z The depth value.
|
|
* @returns The memory location of the point.
|
|
*/
|
|
Point* add_point(std::string name, float x, float y, float z) noexcept;
|
|
|
|
/** delete_point
|
|
* @brief Removes a point from the graph.
|
|
*
|
|
* @param p_index The index of the point to be deleted.
|
|
* @returns True on successful deletion.
|
|
*/
|
|
bool delete_point(int p_index) noexcept;
|
|
|
|
/** add_edge
|
|
* @brief Adds an edge between two points.
|
|
*
|
|
* @param e_start The index of the starting point.
|
|
* @param e_end The index of the ending point.
|
|
*
|
|
* @returns A pointer to the newly added edge.
|
|
**/
|
|
Edge* add_edge(int e_start, int e_end, float weight) noexcept;
|
|
|
|
|
|
/** delete_edge
|
|
* @brief Deletes on edge from Point A to Point B.
|
|
*
|
|
* @param e_start The index of the starting point.
|
|
* @param e_end The index of the ending point.
|
|
*
|
|
* @return TRUE if the edge was found and deleted, FALSE otherwise.
|
|
*/
|
|
bool delete_edge(int e_start, int e_end) noexcept;
|
|
|
|
//Enforcing deletions to prevent memory spikes.
|
|
Graph(const Graph&) = delete;
|
|
Graph& operator=(const Graph&) = delete;
|
|
}; |