42 lines
1.7 KiB
C++
42 lines
1.7 KiB
C++
#pragma once
|
||
#include <map>
|
||
#include <memory>
|
||
#include <string>
|
||
#include <vector>
|
||
#include "DatasetDetailTab.hpp"
|
||
namespace geopro::controller {
|
||
|
||
// dd 类型驱动的图表策略:决定某 ddCode 的详情页如何加载/渲染。
|
||
struct IDatasetChartStrategy {
|
||
virtual ~IDatasetChartStrategy() = default;
|
||
virtual std::string ddCode() const = 0;
|
||
// 该类型的页签集(标题/render kind/加载键/惰性/分页)。控制器据此建页签 + 驱动加载,
|
||
// 取代硬编码的 hasGridPhase()/ddCode 判断。
|
||
virtual std::vector<TabSpec> tabs() const = 0;
|
||
};
|
||
|
||
class ChartStrategyRegistry {
|
||
public:
|
||
ChartStrategyRegistry() = default;
|
||
// 禁拷贝(含 unique_ptr,本就不可拷贝;显式 delete 让意图清晰)。
|
||
// 保留移动:map 移动只搬节点,find() 返回的裸指针指向的策略对象地址不变、仍有效;
|
||
// 且测试 makeInversionRegistry() 按值返回需要移动。
|
||
ChartStrategyRegistry(const ChartStrategyRegistry&) = delete;
|
||
ChartStrategyRegistry& operator=(const ChartStrategyRegistry&) = delete;
|
||
ChartStrategyRegistry(ChartStrategyRegistry&&) = default;
|
||
ChartStrategyRegistry& operator=(ChartStrategyRegistry&&) = default;
|
||
|
||
void add(std::unique_ptr<IDatasetChartStrategy> s) {
|
||
const std::string code = s->ddCode();
|
||
map_[code] = std::move(s);
|
||
}
|
||
IDatasetChartStrategy* find(const std::string& ddCode) const {
|
||
auto it = map_.find(ddCode);
|
||
return it == map_.end() ? nullptr : it->second.get();
|
||
}
|
||
bool supports(const std::string& ddCode) const { return map_.count(ddCode) > 0; }
|
||
private:
|
||
std::map<std::string, std::unique_ptr<IDatasetChartStrategy>> map_;
|
||
};
|
||
} // namespace geopro::controller
|