2022-06-10 21:21:35 +08:00
|
|
|
//
|
|
|
|
// Created by ricardo on 2022/6/10.
|
|
|
|
//
|
|
|
|
|
2022-06-11 19:04:47 +08:00
|
|
|
#ifndef AUTO_BUS_GUI_RAILS_MODEL_H
|
|
|
|
#define AUTO_BUS_GUI_RAILS_MODEL_H
|
2022-06-10 21:21:35 +08:00
|
|
|
#include "cstdlib"
|
|
|
|
|
|
|
|
struct rail_node{
|
|
|
|
/**
|
|
|
|
* 站点的编号
|
|
|
|
*/
|
|
|
|
int id;
|
2022-06-29 17:25:33 +08:00
|
|
|
|
2022-06-10 21:21:35 +08:00
|
|
|
/**
|
|
|
|
* 距离上一个站点的距离
|
|
|
|
*/
|
|
|
|
int last_node_distance;
|
2022-06-29 17:25:33 +08:00
|
|
|
|
2022-06-10 21:21:35 +08:00
|
|
|
/**
|
|
|
|
* 距离下一个站点的距离
|
|
|
|
*/
|
|
|
|
int next_node_distance;
|
2022-06-29 17:25:33 +08:00
|
|
|
|
2022-06-10 21:21:35 +08:00
|
|
|
/**
|
|
|
|
* 指向上一个站点的指针
|
|
|
|
*/
|
|
|
|
struct rail_node* last_node;
|
2022-06-29 17:25:33 +08:00
|
|
|
|
2022-06-10 21:21:35 +08:00
|
|
|
/**
|
|
|
|
* 指向下一个站点的指针
|
|
|
|
*/
|
|
|
|
struct rail_node* next_node;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct rail_node rail_node_t;
|
|
|
|
|
|
|
|
class RailsModel
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* 轨道的头节点
|
|
|
|
*/
|
|
|
|
rail_node_t *rails;
|
|
|
|
|
2022-06-10 23:33:20 +08:00
|
|
|
/**
|
2022-06-26 13:06:22 +08:00
|
|
|
* 轨道上的节点数量
|
2022-06-10 23:33:20 +08:00
|
|
|
*/
|
2022-06-26 13:06:22 +08:00
|
|
|
int node_num;
|
|
|
|
|
2022-06-29 17:25:33 +08:00
|
|
|
/**
|
|
|
|
* 轨道的总长度
|
|
|
|
*/
|
2022-06-27 14:21:07 +08:00
|
|
|
int total_distance;
|
|
|
|
|
2022-06-26 13:06:22 +08:00
|
|
|
explicit RailsModel();
|
|
|
|
|
|
|
|
~RailsModel();
|
|
|
|
|
2022-06-10 23:33:20 +08:00
|
|
|
/**
|
|
|
|
* 查找指定编号的站点指针
|
|
|
|
* @param head 轨道的头节点地址
|
|
|
|
* @param id 需要查找的站点编号
|
|
|
|
* @return 需要查找站点指针
|
|
|
|
*/
|
2022-06-28 18:44:55 +08:00
|
|
|
rail_node_t *FindNode(int node_id) const;
|
2022-06-10 21:21:35 +08:00
|
|
|
|
2022-06-26 13:06:22 +08:00
|
|
|
/**
|
|
|
|
* 创建轨道链表
|
|
|
|
* @param distance 站点之间的距离
|
|
|
|
* @param node_number 站点的数量
|
|
|
|
*/
|
|
|
|
void CreateRails(int distance, int node_number);
|
2022-06-10 21:21:35 +08:00
|
|
|
|
2022-06-26 13:06:22 +08:00
|
|
|
/**
|
|
|
|
* 释放占用的内存空间
|
|
|
|
*/
|
|
|
|
void FreeRails();
|
2022-06-10 21:21:35 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-06-11 19:04:47 +08:00
|
|
|
#endif //AUTO_BUS_GUI_RAILS_MODEL_H
|