2024-12-12 13:32:28 +08:00
|
|
|
|
#pragma once
|
2024-10-23 02:09:01 +08:00
|
|
|
|
|
|
|
|
|
#include<hgl/graph/VKNamespace.h>
|
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
class GraphModule;
|
|
|
|
|
class GraphModuleManager;
|
|
|
|
|
|
|
|
|
|
class GraphModuleFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
GraphModuleFactory()=default;
|
|
|
|
|
virtual ~GraphModuleFactory()=default;
|
|
|
|
|
|
|
|
|
|
virtual GraphModule *Create(GraphModuleManager *)=0;
|
|
|
|
|
};//class GraphModuleFactory
|
|
|
|
|
|
|
|
|
|
bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *);
|
|
|
|
|
|
|
|
|
|
template<typename T> class RegistryGraphModule:public GraphModuleFactory
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
GraphModule *Create(GraphModuleManager *gmm) override
|
|
|
|
|
{
|
|
|
|
|
if(!gmm)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
2024-12-17 13:57:21 +08:00
|
|
|
|
Map<AnsiIDName,GraphModule *> dgm_map;
|
|
|
|
|
|
|
|
|
|
//检查依赖模块
|
|
|
|
|
{
|
|
|
|
|
const auto &dependent_modules=T::GetDependentModules();
|
|
|
|
|
|
|
|
|
|
if(!dependent_modules.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
for(const AnsiIDName &name:dependent_modules)
|
|
|
|
|
{
|
|
|
|
|
GraphModule *dgm=gmm->GetModule(name,true);
|
|
|
|
|
|
|
|
|
|
if(!dgm)
|
|
|
|
|
return(nullptr);
|
|
|
|
|
|
|
|
|
|
dgm_map.Add(name,dgm);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-24 13:10:01 +08:00
|
|
|
|
GraphModule *gm=new T(gmm);
|
2024-11-09 00:11:43 +08:00
|
|
|
|
|
2024-12-24 13:10:01 +08:00
|
|
|
|
if(!gm->InitDependentModules(dgm))
|
2024-12-21 17:25:30 +08:00
|
|
|
|
{
|
|
|
|
|
delete gm;
|
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-09 00:11:43 +08:00
|
|
|
|
if(!gm->Init())
|
|
|
|
|
{
|
|
|
|
|
delete gm;
|
|
|
|
|
return(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-09 19:28:31 +08:00
|
|
|
|
return(gm);
|
2024-10-23 02:09:01 +08:00
|
|
|
|
}
|
|
|
|
|
};//template<typename T> class RegistryGraphModule:public GraphModuleFactory
|
|
|
|
|
|
2024-11-09 19:28:31 +08:00
|
|
|
|
#define REGISTRY_GRAPH_MODULE(Class) {RegistryGraphModuleFactory(#Class,new RegistryGraphModule<Class>);}
|
2024-10-23 02:09:01 +08:00
|
|
|
|
|
2024-12-12 13:32:28 +08:00
|
|
|
|
VK_NAMESPACE_END
|