bool ProjectManager::AddProjectDependency(cbProject* base, cbProject* dependsOn) { if (!base || !dependsOn) return false; // avoid circular dependencies if ( CausesCircularDependency(base, dependsOn) ) return false; ProjectsArray* arr = nullptr; DepsMap::iterator it = m_ProjectDeps.find(base); if (it == m_ProjectDeps.end()) { // create a ProjectsArray* to hold the dependencies for base arr = new ProjectsArray; m_ProjectDeps[base] = arr; } else arr = it->second; // add dependency only if not already there if (arr && arr->Index(dependsOn) == wxNOT_FOUND) { arr->Add(dependsOn); if (m_pWorkspace) m_pWorkspace->SetModified(true); Manager::Get()->GetLogManager()->DebugLog(F(_T("%s now depends on %s (%lu deps)"), base->GetTitle().wx_str(), dependsOn->GetTitle().wx_str(), static_cast<unsigned long>(arr->GetCount()))); } return true; }
void ProjectManager::RemoveProjectFromAllDependencies(cbProject* base) { if (!base) return; DepsMap::iterator it = m_ProjectDeps.begin(); while (it != m_ProjectDeps.end()) { if (it->first == base) { ++it; continue; } ProjectsArray* arr = it->second; // only check projects that do have a dependencies array if (!arr) { ++it; continue; } int index = arr->Index(base); if (index != wxNOT_FOUND) arr->RemoveAt(index); if (m_pWorkspace) m_pWorkspace->SetModified(true); // if it was the last dependency, delete the array if (!arr->GetCount()) { DepsMap::iterator it2 = it++; m_ProjectDeps.erase(it2); delete arr; } else ++it; } Manager::Get()->GetLogManager()->DebugLog(F(_T("Removed %s from all deps"), base->GetTitle().wx_str())); }