1 /* 2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "Resolvable.h" 8 9 #include <string.h> 10 11 #include "Version.h" 12 13 14 Resolvable::Resolvable(::Package* package) 15 : 16 fPackage(package), 17 fFamily(NULL), 18 fName(), 19 fVersion(NULL), 20 fCompatibleVersion(NULL) 21 { 22 } 23 24 25 Resolvable::~Resolvable() 26 { 27 delete fVersion; 28 delete fCompatibleVersion; 29 } 30 31 32 status_t 33 Resolvable::Init(const char* name, ::Version* version, 34 ::Version* compatibleVersion) 35 { 36 fVersion = version; 37 fCompatibleVersion = compatibleVersion; 38 39 if (!fName.SetTo(name)) 40 return B_NO_MEMORY; 41 42 return B_OK; 43 } 44 45 46 void 47 Resolvable::AddDependency(Dependency* dependency) 48 { 49 fDependencies.Add(dependency); 50 dependency->SetResolvable(this); 51 } 52 53 54 void 55 Resolvable::RemoveDependency(Dependency* dependency) 56 { 57 fDependencies.Remove(dependency); 58 dependency->SetResolvable(NULL); 59 } 60 61 62 void 63 Resolvable::MoveDependencies(ResolvableDependencyList& dependencies) 64 { 65 if (fDependencies.IsEmpty()) 66 return; 67 68 for (ResolvableDependencyList::Iterator it = fDependencies.GetIterator(); 69 Dependency* dependency = it.Next();) { 70 dependency->SetResolvable(NULL); 71 } 72 73 dependencies.MoveFrom(&fDependencies); 74 } 75