| 1943 | //----------------------------------------------------------------------------- |
| 1944 | |
| 1945 | bool ModuleManager::removeModuleDefinition( ModuleDefinition* pModuleDefinition ) |
| 1946 | { |
| 1947 | // Sanity! |
| 1948 | AssertFatal( pModuleDefinition != NULL, "Cannot remove module definition if it is NULL." ); |
| 1949 | |
| 1950 | // Fetch module Id. |
| 1951 | StringTableEntry moduleId = pModuleDefinition->getModuleId(); |
| 1952 | |
| 1953 | // Is the module definition registered with this module manager? |
| 1954 | if ( pModuleDefinition->getModuleManager() != this ) |
| 1955 | { |
| 1956 | // No, so warn. |
| 1957 | Con::warnf("Cannot remove module definition '%s' as it is not registered with this module manager.", moduleId ); |
| 1958 | return false; |
| 1959 | } |
| 1960 | |
| 1961 | // Is the module definition loaded? |
| 1962 | if ( pModuleDefinition->getLoadCount() > 0 ) |
| 1963 | { |
| 1964 | // No, so warn. |
| 1965 | Con::warnf("Cannot remove module definition '%s' as it is loaded.", moduleId ); |
| 1966 | return false; |
| 1967 | } |
| 1968 | |
| 1969 | // Find module Id. |
| 1970 | typeModuleIdDatabaseHash::iterator moduleItr = mModuleIdDatabase.find( moduleId ); |
| 1971 | |
| 1972 | // Sanity! |
| 1973 | AssertFatal( moduleItr != mModuleIdDatabase.end(), "Failed to find module definition." ); |
| 1974 | |
| 1975 | // Fetch modules definitions. |
| 1976 | ModuleDefinitionEntry* pDefinitions = moduleItr->value; |
| 1977 | |
| 1978 | // Fetch version Id. |
| 1979 | const U32 versionId = pModuleDefinition->getVersionId(); |
| 1980 | |
| 1981 | // Iterate module definitions. |
| 1982 | for ( ModuleDefinitionEntry::iterator definitionItr = pDefinitions->begin(); definitionItr != pDefinitions->end(); ++definitionItr ) |
| 1983 | { |
| 1984 | // Skip if this isn't the version Id we're searching for. |
| 1985 | if ( versionId != (*definitionItr)->getVersionId() ) |
| 1986 | continue; |
| 1987 | |
| 1988 | // Remove definition entry. |
| 1989 | pDefinitions->erase( definitionItr ); |
| 1990 | |
| 1991 | // Remove notification before we delete it. |
| 1992 | clearNotify( pModuleDefinition ); |
| 1993 | |
| 1994 | // Delete module definition. |
| 1995 | pModuleDefinition->deleteObject(); |
| 1996 | |
| 1997 | // Are there any modules left for this module Id? |
| 1998 | if ( findModuleId( moduleId ) == NULL ) |
| 1999 | { |
| 2000 | bool moduleIdFound = false; |
| 2001 | |
| 2002 | // No, so remove from groups. |
no test coverage detected