xref: /haiku/src/kits/package/solver/SolverResult.cpp (revision a3e794ae459fec76826407f8ba8c94cd3535f128)
1 /*
2  * Copyright 2013, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Ingo Weinhold <ingo_weinhold@gmx.de>
7  */
8 
9 
10 #include <package/solver/SolverResult.h>
11 
12 
13 namespace BPackageKit {
14 
15 
16 // #pragma mark - BSolverResultElement
17 
18 
19 BSolverResultElement::BSolverResultElement(BType type, BSolverPackage* package)
20 	:
21 	fType(type),
22 	fPackage(package)
23 {
24 }
25 
26 
27 BSolverResultElement::BSolverResultElement(const BSolverResultElement& other)
28 	:
29 	fType(other.fType),
30 	fPackage(other.fPackage)
31 {
32 }
33 
34 
35 BSolverResultElement::~BSolverResultElement()
36 {
37 }
38 
39 
40 BSolverResultElement::BType
41 BSolverResultElement::Type() const
42 {
43 	return fType;
44 }
45 
46 
47 BSolverPackage*
48 BSolverResultElement::Package() const
49 {
50 	return fPackage;
51 }
52 
53 
54 BSolverResultElement&
55 BSolverResultElement::operator=(const BSolverResultElement& other)
56 {
57 	fType = other.fType;
58 	fPackage = other.fPackage;
59 	return *this;
60 }
61 
62 
63 // #pragma mark - BSolverResult
64 
65 
66 BSolverResult::BSolverResult()
67 	:
68 	fElements(20, true)
69 {
70 }
71 
72 
73 BSolverResult::~BSolverResult()
74 {
75 }
76 
77 
78 bool
79 BSolverResult::IsEmpty() const
80 {
81 	return fElements.IsEmpty();
82 }
83 
84 
85 int32
86 BSolverResult::CountElements() const
87 {
88 	return fElements.CountItems();
89 }
90 
91 
92 const BSolverResultElement*
93 BSolverResult::ElementAt(int32 index) const
94 {
95 	return fElements.ItemAt(index);
96 }
97 
98 
99 void
100 BSolverResult::MakeEmpty()
101 {
102 	fElements.MakeEmpty();
103 }
104 
105 
106 bool
107 BSolverResult::AppendElement(const BSolverResultElement& element)
108 {
109 	BSolverResultElement* newElement
110 		= new(std::nothrow) BSolverResultElement(element);
111 	if (newElement == NULL || !fElements.AddItem(newElement)) {
112 		delete newElement;
113 		return false;
114 	}
115 
116 	return true;
117 }
118 
119 
120 }	// namespace BPackageKit
121