1 /*
2 * Copyright (C) 2018 Red Hat, Inc.
3 *
4 * Licensed under the GNU Lesser General Public License Version 2.1
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef LIBDNF_DEPENDENCYCONTAINER_HPP
22 #define LIBDNF_DEPENDENCYCONTAINER_HPP
23
24
25 #include <solv/queue.h>
26 #include <memory>
27 #include "libdnf/dnf-sack.h"
28
29 namespace libdnf {
30
31 struct Dependency;
32
33 struct DependencyContainer
34 {
35 public:
36 DependencyContainer(const DependencyContainer &src);
37 DependencyContainer(DependencyContainer &&src);
38 explicit DependencyContainer(DnfSack *sack);
39 DependencyContainer(DnfSack *sack, const Queue &queue);
40 DependencyContainer(DnfSack *sack, Queue &&queue);
41 ~DependencyContainer();
42
43 DependencyContainer &operator=(const DependencyContainer &src);
44 DependencyContainer &operator=(DependencyContainer &&src) noexcept;
45 bool operator==(const DependencyContainer &r) const;
46 bool operator!=(const DependencyContainer &r) const;
47
48 void add(Dependency *dependency);
49 void add(Id id);
50
51 /**
52 * @brief Adds a reldep from Char*. Only globs in name are proccessed. The proccess is slow
53 * therefore if reldepStr is not a glob please use addReldep() instead.
54 *
55 * @param reldepStr p_reldepStr: Char*
56 * @return bool - false if parsing or reldep creation fails
57 */
58 bool addReldepWithGlob(const char *reldepStr);
59
60 /**
61 * @brief Adds a reldep from Char*. It does not support globs.
62 *
63 * @param reldepStr p_reldepStr: Char*
64 * @return bool false if parsing or reldep creation fails
65 */
66 bool addReldep(const char *reldepStr);
67 void extend(DependencyContainer *container);
68
69 std::unique_ptr<Dependency> get(int index) const noexcept;
70 Dependency *getPtr(int index) const noexcept;
71 Id getId(int index) const noexcept;
72 int count() const noexcept;
73
74 const Queue &getQueue() const noexcept;
75
76 private:
77 DnfSack *sack;
78 Queue queue;
79 };
80
getId(int index) const81 inline Id DependencyContainer::getId(int index) const noexcept
82 {
83 return queue.elements[index];
84 }
85
86 }
87
88 #endif //LIBDNF_DEPENDENCYCONTAINER_HPP
89