1 /* 2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "ResolvableFamily.h" 8 9 #include "Package.h" 10 #include "Volume.h" 11 12 13 void 14 ResolvableFamily::AddResolvable(Resolvable* resolvable, 15 ResolvableDependencyList& dependenciesToUpdate) 16 { 17 // Find the insertion point in the list. We sort by mount type -- the more 18 // specific the higher the priority. 19 MountType mountType 20 = resolvable->Package()->Volume()->MountType(); 21 Resolvable* otherResolvable = NULL; 22 for (FamilyResolvableList::Iterator it = fResolvables.GetIterator(); 23 (otherResolvable = it.Next()) != NULL;) { 24 if (otherResolvable->Package()->Volume()->MountType() 25 <= mountType) { 26 break; 27 } 28 } 29 30 fResolvables.InsertBefore(otherResolvable, resolvable); 31 resolvable->SetFamily(this); 32 33 // all dependencies after the inserted resolvable potentially need to be 34 // updated 35 while ((resolvable = fResolvables.GetNext(resolvable)) != NULL) 36 resolvable->MoveDependencies(dependenciesToUpdate); 37 } 38 39 40 void 41 ResolvableFamily::RemoveResolvable(Resolvable* resolvable, 42 ResolvableDependencyList& dependenciesToUpdate) 43 { 44 resolvable->SetFamily(NULL); 45 fResolvables.Remove(resolvable); 46 47 // the removed resolvable's dependencies need to be updated 48 resolvable->MoveDependencies(dependenciesToUpdate); 49 } 50 51 52 bool 53 ResolvableFamily::ResolveDependency(Dependency* dependency) 54 { 55 for (FamilyResolvableList::Iterator it = fResolvables.GetIterator(); 56 Resolvable* resolvable = it.Next();) { 57 if (!dependency->ResolvableVersionMatches(resolvable->Version())) 58 continue; 59 60 Version* compatibleVersion = resolvable->CompatibleVersion() != NULL 61 ? resolvable->CompatibleVersion() : resolvable->Version(); 62 if (dependency->ResolvableCompatibleVersionMatches(compatibleVersion)) { 63 resolvable->AddDependency(dependency); 64 return true; 65 } 66 } 67 68 return false; 69 } 70