void Comploader::registerFactory(const std::string& component_name, ComponentFactory* factory) { log_debug("Comploader::registerFactory(" << component_name << ", " << factory << ')'); if (currentFactoryMap) currentFactoryMap->insert(ComponentLibrary::factoryMapType::value_type(component_name, factory)); else { librarymap_type& librarymap = getLibrarymap(); log_debug("register component without library-name"); librarymap_type::iterator it = librarymap.find(std::string()); if (it == librarymap.end()) { // empty library not in map - create a new empty library-object it = librarymap.insert( librarymap_type::value_type(std::string(), ComponentLibrary())).first; } it->second.registerFactory(component_name, factory); } }
ComponentLibrary& Comploader::fetchLib(const std::string& libname) { log_debug("fetchLib \"" << libname << '"'); std::string n = libname; bool local = false; if (!n.empty() && n[0] == '!') { local = true; n.erase(0, 1); } librarymap_type& librarymap = getLibrarymap(); librarymap_type::iterator it = librarymap.find(n); if (it == librarymap.end()) { ComponentLibrary::factoryMapType factoryMap; currentFactoryMap = &factoryMap; ValueResetter<ComponentLibrary::factoryMapType*> valueResetter(currentFactoryMap, 0); // load library log_info("load library \"" << n << '"'); ComponentLibrary lib; for (TntConfig::CompPathType::const_iterator p = TntConfig::it().compPath.begin(); !lib && p != TntConfig::it().compPath.end(); ++p) { log_debug("load library \"" << n << "\" from " << *p << " dir"); lib = ComponentLibrary(*p, n, local); } if (!lib) { log_debug("load library \"" << n << "\" from current dir"); lib = ComponentLibrary(".", n, local); } #ifdef PKGLIBDIR if (!lib) { log_debug("load library \"" << n << "\" from package lib dir <" << PKGLIBDIR << '>'); lib = ComponentLibrary(PKGLIBDIR, n, local); } #endif if (!lib) { log_debug("library \"" << n << "\" in current dir not found - search lib-path"); lib = ComponentLibrary(n, local); } if (!lib) throw LibraryNotFound(n); lib.factoryMap = factoryMap; log_debug("insert new library " << n); it = librarymap.insert(librarymap_type::value_type(n, lib)).first; } else log_debug("library " << n << " found"); return it->second; }
#include <gui/gui.h> #include <Fusion.h> ComponentLibrary UserInterfaceDB::m_library = ComponentLibrary(); // This function prototype are for use with the standard objects compiled into this dll void update(LIBRARY *library); UserInterfaceDB::UserInterfaceDB(){} UserInterfaceDB::~UserInterfaceDB() { RemoveAllUI(); } bool UserInterfaceDB::Initialise(void) { m_moduledb = fusion->GetModuleDB(); m_library.Initialise(m_moduledb); m_library.AddLibrary(update); return true; } UserInterface * UserInterfaceDB::AddUI(SceneGraph *scene) { UserInterface *ui = new UserInterface(m_moduledb,scene); m_interface_list.push_back(ui); return ui; }