Merge pull request #19142 from hyarion/refactor/add-template-addobject

Add new addObject<T>() function
This commit is contained in:
Chris Hennes
2025-02-11 09:42:47 -06:00
committed by GitHub
95 changed files with 335 additions and 340 deletions

View File

@@ -59,7 +59,7 @@ map<string, unsigned int> Type::typemap;
vector<TypeData*> Type::typedata;
set<string> Type::loadModuleSet;
void* Type::createInstance()
void* Type::createInstance() const
{
instantiationMethod method = typedata[index]->instMethod;
return method ? (*method)() : nullptr;
@@ -90,30 +90,33 @@ void* Type::createInstanceByName(const char* TypeName, bool bLoadModule)
void Type::importModule(const char* TypeName)
{
// cut out the module name
string Mod = getModuleName(TypeName);
const string mod = getModuleName(TypeName);
// ignore base modules
if (Mod != "App" && Mod != "Gui" && Mod != "Base") {
// remember already loaded modules
set<string>::const_iterator pos = loadModuleSet.find(Mod);
if (pos == loadModuleSet.end()) {
Interpreter().loadModule(Mod.c_str());
#ifdef FC_LOGLOADMODULE
Console().Log("Act: Module %s loaded through class %s \n", Mod.c_str(), TypeName);
#endif
loadModuleSet.insert(Mod);
}
if (mod == "App" || mod == "Gui" || mod == "Base") {
return;
}
// remember already loaded modules
const auto pos = loadModuleSet.find(mod);
if (pos != loadModuleSet.end()) {
return;
}
// lets load the module
Interpreter().loadModule(mod.c_str());
#ifdef FC_LOGLOADMODULE
Console().Log("Act: Module %s loaded through class %s \n", Mod.c_str(), TypeName);
#endif
loadModuleSet.insert(mod);
}
string Type::getModuleName(const char* ClassName)
{
string temp(ClassName);
std::string::size_type pos = temp.find_first_of("::");
string_view classNameView(ClassName);
auto pos = classNameView.find("::");
if (pos != std::string::npos) {
return {temp, 0, pos};
}
return {};
return pos != string_view::npos ? string(classNameView.substr(0, pos)) : string();
}
Type Type::badType()

View File

@@ -88,7 +88,7 @@ public:
~Type() = default;
/// creates a instance of this type
void* createInstance();
void* createInstance() const;
/// Checks whether this type can instantiate
bool canInstantiate() const;
/// creates a instance of the named type