64 lines
1.5 KiB
C
64 lines
1.5 KiB
C
|
/**
|
|||
|
* @file TopicMonitorFactory.h
|
|||
|
* @author jinchao
|
|||
|
* @brief 主题监控工厂类
|
|||
|
* @version 1.0
|
|||
|
* @date 2025-03-10
|
|||
|
*
|
|||
|
* @copyright Copyright (c) 2025 COMAC
|
|||
|
*
|
|||
|
*/
|
|||
|
#pragma once
|
|||
|
#include <QString>
|
|||
|
#include <QSharedPointer>
|
|||
|
#include "TopicMonitor.h"
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 主题监控工厂类
|
|||
|
*/
|
|||
|
class TopicMonitorFactory
|
|||
|
{
|
|||
|
public:
|
|||
|
/**
|
|||
|
* @brief 获取工厂单例
|
|||
|
* @return TopicMonitorFactory&: 工厂单例的引用
|
|||
|
*/
|
|||
|
static TopicMonitorFactory &getInstance();
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 根据主题名称创建或获取对应的监控类实例
|
|||
|
* @param modelName: 主题名称
|
|||
|
* @param parent: 父对象
|
|||
|
* @return QSharedPointer<TopicMonitor>: 监控类实例的共享指针
|
|||
|
*/
|
|||
|
QSharedPointer<TopicMonitor> createMonitor(const QString &modelName, QObject *parent = nullptr);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 注册新的监控类型
|
|||
|
* @param modelName: 主题名称
|
|||
|
* @param creator: 创建函数
|
|||
|
*/
|
|||
|
void registerMonitorType(const QString &modelName,
|
|||
|
std::function<TopicMonitor *(QObject *)> creator);
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 清除所有缓存的监控器实例
|
|||
|
*/
|
|||
|
void clearMonitors();
|
|||
|
|
|||
|
private:
|
|||
|
/**
|
|||
|
* @brief 私有构造函数,确保单例
|
|||
|
*/
|
|||
|
TopicMonitorFactory() {}
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 存储主题前缀到创建函数的映射
|
|||
|
*/
|
|||
|
QMap<QString, std::function<TopicMonitor *(QObject *)>> m_creators;
|
|||
|
|
|||
|
/**
|
|||
|
* @brief 缓存每种类型的监控器实例(类型前缀 -> 监控器实例)
|
|||
|
*/
|
|||
|
QMap<QString, QSharedPointer<TopicMonitor>> m_monitorInstances;
|
|||
|
};
|