添加了请求控制类

添加了注释
This commit is contained in:
jackfiled 2022-06-10 23:33:20 +08:00
parent 6380265faa
commit 35fa35de3f
3 changed files with 159 additions and 0 deletions

56
include/queryModel.h Normal file
View File

@ -0,0 +1,56 @@
//
// Created by ricardo on 2022/6/10.
//
#ifndef AUTO_BUS_GUI_QUERYMODEL_H
#define AUTO_BUS_GUI_QUERYMODEL_H
#include "railsModel.h"
struct bus_query {
/**
*
*/
int time;
/**
*
*/
int type;
/**
* /
*/
rail_node_t *node;
/**
*
*/
struct bus_query *next_node;
};
typedef struct bus_query bus_query_t;
class QueryModel
{
public:
bus_query_t *queries = nullptr;
/**
*
*
*/
~QueryModel();
/**
*
* @param type
* @param node
*/
void CreateQuery(int type, rail_node_t *node);
/**
*
* @param target_query
*/
void DeleteQuery(bus_query_t *target_query);
};
#endif //AUTO_BUS_GUI_QUERYMODEL_H

View File

@ -40,7 +40,18 @@ public:
*/
rail_node_t *rails;
/**
*
* @param distance
* @param node_number
*/
explicit RailsModel(int distance = 2, int node_number = 5);
/**
*
* @param head
* @param id
* @return
*/
rail_node_t *FindNode(int node_num) const;
~RailsModel();

92
src/queryModel.cpp Normal file
View File

@ -0,0 +1,92 @@
//
// Created by ricardo on 2022/6/10.
//
#include "queryModel.h"
QueryModel::~QueryModel()
{
if(queries != nullptr)
{
bus_query_t *p = queries;
while (p != nullptr)
{
bus_query_t *temp = p;
p = p->next_node;
free(temp);
}
queries = nullptr;
}
}
void QueryModel::CreateQuery(int type, rail_node_t *node)
{
auto *p = (bus_query_t *)malloc(sizeof (bus_query_t));
p->node = node;
p->type = type;
p->next_node = nullptr;
if (queries == nullptr)
{
queries = p;
}
else
{
bus_query_t *query = queries;
/**
*
*/
bool flag = false;
do
{
if(query->node == p->node and query->type == p->type)
{
flag = true;
break;
}
query = query->next_node;
} while (query != nullptr);
if (flag)
{
// 存在相同的请求
free(p);
}
else
{
// 在不存在相同的请求时
bus_query_t *last_query = queries;
while (last_query->next_node != nullptr)
{
last_query = last_query->next_node;
}
last_query->next_node = p;
}
}
}
void QueryModel::DeleteQuery(bus_query_t *target_query)
{
if (target_query == queries)
{
queries = target_query->next_node;
}
else
{
bus_query_t *query = queries;
// 找到被删除节点的上一个节点
while (query->next_node != target_query)
{
query = query->next_node;
}
query->next_node = target_query->next_node;
}
free(target_query);
}