feat/dataset-detail-chart #5
|
|
@ -0,0 +1,29 @@
|
|||
#pragma once
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
namespace geopro::app {
|
||||
|
||||
class DatasetDetailPage; // 前置
|
||||
|
||||
// dd 类型驱动的图表策略:决定某 ddCode 的详情页如何加载/渲染。
|
||||
struct IDatasetChartStrategy {
|
||||
virtual ~IDatasetChartStrategy() = default;
|
||||
virtual std::string ddCode() const = 0;
|
||||
};
|
||||
|
||||
class ChartStrategyRegistry {
|
||||
public:
|
||||
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::app
|
||||
|
|
@ -80,4 +80,7 @@ target_sources(geopro_tests PRIVATE render/test_terrain.cpp)
|
|||
target_link_libraries(geopro_tests PRIVATE geopro_render ${VTK_LIBRARIES})
|
||||
vtk_module_autoinit(TARGETS geopro_tests MODULES ${VTK_LIBRARIES})
|
||||
|
||||
target_include_directories(geopro_tests PRIVATE ${CMAKE_SOURCE_DIR}/src/app)
|
||||
target_sources(geopro_tests PRIVATE app/test_chart_strategy_registry.cpp)
|
||||
|
||||
add_subdirectory(spike) # spike S3: banded contour 渲染验证
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "panels/chart/IDatasetChartStrategy.hpp"
|
||||
using namespace geopro::app;
|
||||
namespace {
|
||||
struct Fake : IDatasetChartStrategy { std::string ddCode() const override { return "dd_inversion_data"; } };
|
||||
}
|
||||
TEST(ChartStrategyRegistry, FindsRegisteredAndDegradesUnknown) {
|
||||
ChartStrategyRegistry reg;
|
||||
reg.add(std::make_unique<Fake>());
|
||||
EXPECT_TRUE(reg.supports("dd_inversion_data"));
|
||||
EXPECT_NE(reg.find("dd_inversion_data"), nullptr);
|
||||
EXPECT_FALSE(reg.supports("dd_unknown"));
|
||||
EXPECT_EQ(reg.find("dd_unknown"), nullptr);
|
||||
}
|
||||
Loading…
Reference in New Issue