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_DEPENDENCY_HPP
22 #define LIBDNF_DEPENDENCY_HPP
23 
24 #include <memory>
25 #include <string>
26 #include <vector>
27 #include <solv/knownid.h>
28 
29 #include "libdnf/dnf-sack.h"
30 
31 namespace libdnf {
32 
33 struct Dependency
34 {
35 public:
36     /**
37     * @brief Creates a reldep from Id
38     */
39     Dependency(DnfSack *sack, Id id);
40 
41     /**
42     * @brief Creates a reldep from name, version, and comparison type.
43     *
44     * @param sack p_sack: DnfSack*
45     * @param name p_name: Required
46     * @param version p_version: Can be also NULL
47     * @param cmpType p_cmpType: Can be 0 or HY_EQ, HY_LT, HY_GT, and their combinations
48     */
49     Dependency(DnfSack *sack, const char *name, const char *version, int cmpType);
50 
51     /**
52     * @brief Creates a reldep from Char*. If parsing fails it raises std::runtime_error.
53     *
54     * @param sack p_sack:...
55     * @param dependency p_dependency:...
56     */
57     Dependency(DnfSack *sack, const std::string &dependency);
58     Dependency(const Dependency &dependency);
59     ~Dependency();
60 
61     const char *getName() const;
62     const char *getRelation() const;
63     const char *getVersion() const;
64     const char *toString() const;
65     Id getId() const noexcept;
66 
67 private:
68     friend DependencyContainer;
69 
70     /**
71     * @brief Returns Id of reldep
72     *
73     * @param sack p_sack: DnfSack*
74     * @param name p_name: Required
75     * @param version p_version: Can be also NULL
76     * @param cmpType p_cmpType: Can be 0 or HY_EQ, HY_LT, HY_GT, and their combinations
77     * @return Id
78     */
79     static Id getReldepId(DnfSack *sack, const char *name, const char *version, int cmpType);
80 
81     /**
82     * @brief Returns Id of reldep or raises std::runtime_error if parsing fails
83     *
84     * @param sack p_sack:DnfSack
85     * @param reldepStr p_reldepStr: const Char* of reldep
86     * @return Id
87     */
88     static Id getReldepId(DnfSack *sack, const char * reldepStr);
89 
90     DnfSack *sack;
91     Id id;
92 };
93 
getId() const94 inline Id Dependency::getId() const noexcept { return id; }
95 
96 }
97 
98 #endif //LIBDNF_DEPENDENCY_HPP
99