2 * Copyright 2013, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <ingo_weinhold@gmx.de>
10 #include <package/solver/SolverPackageSpecifierList.h>
15 #include <package/solver/SolverPackageSpecifier.h>
18 namespace BPackageKit
{
20 class BSolverPackageSpecifierList::Vector
21 : public std::vector
<BSolverPackageSpecifier
> {
25 std::vector
<BSolverPackageSpecifier
>()
29 Vector(const std::vector
<BSolverPackageSpecifier
>& other
)
31 std::vector
<BSolverPackageSpecifier
>(other
)
37 BSolverPackageSpecifierList::BSolverPackageSpecifierList()
44 BSolverPackageSpecifierList::BSolverPackageSpecifierList(
45 const BSolverPackageSpecifierList
& other
)
53 BSolverPackageSpecifierList::~BSolverPackageSpecifierList()
60 BSolverPackageSpecifierList::IsEmpty() const
62 return fSpecifiers
== NULL
|| fSpecifiers
->empty();
67 BSolverPackageSpecifierList::CountSpecifiers() const
69 return fSpecifiers
!= NULL
? fSpecifiers
->size() : 0;
73 const BSolverPackageSpecifier
*
74 BSolverPackageSpecifierList::SpecifierAt(int32 index
) const
76 if (fSpecifiers
== NULL
|| index
< 0
77 || (size_t)index
>= fSpecifiers
->size()) {
81 return &(*fSpecifiers
)[index
];
86 BSolverPackageSpecifierList::AppendSpecifier(
87 const BSolverPackageSpecifier
& specifier
)
90 if (fSpecifiers
== NULL
) {
91 fSpecifiers
= new(std::nothrow
) Vector
;
92 if (fSpecifiers
== NULL
)
96 fSpecifiers
->push_back(specifier
);
98 } catch (std::bad_alloc
&) {
105 BSolverPackageSpecifierList::AppendSpecifier(BSolverPackage
* package
)
107 return AppendSpecifier(BSolverPackageSpecifier(package
));
112 BSolverPackageSpecifierList::AppendSpecifier(const BString
& selectString
)
114 return AppendSpecifier(BSolverPackageSpecifier(selectString
));
119 BSolverPackageSpecifierList::AppendSpecifiers(const char* const* selectStrings
,
122 for (int32 i
= 0; i
< count
; i
++) {
123 if (!AppendSpecifier(selectStrings
[i
])) {
124 for (int32 k
= i
- 1; k
>= 0; k
--)
125 fSpecifiers
->pop_back();
135 BSolverPackageSpecifierList::MakeEmpty()
137 fSpecifiers
->clear();
141 BSolverPackageSpecifierList
&
142 BSolverPackageSpecifierList::operator=(const BSolverPackageSpecifierList
& other
)
150 if (other
.fSpecifiers
== NULL
)
154 fSpecifiers
= new(std::nothrow
) Vector(*other
.fSpecifiers
);
155 } catch (std::bad_alloc
&) {
162 } // namespace BPackageKit