Skip to content

Commit

Permalink
Add pImpl to libdnf5::comps::EnvironmentQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
kontura authored and jan-kolarik committed Feb 27, 2024
1 parent b0e2460 commit c515b69
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 24 deletions.
37 changes: 14 additions & 23 deletions include/libdnf5/comps/environment/query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "libdnf5/base/base_weak.hpp"
#include "libdnf5/common/sack/query.hpp"
#include "libdnf5/common/weak_ptr.hpp"
#include "libdnf5/comps/environment/environment.hpp"

#include <string>
Expand All @@ -32,42 +31,34 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
namespace libdnf5::comps {



class EnvironmentQuery : public libdnf5::sack::Query<Environment> {
public:
// Create new query with newly composed environments (using only solvables from currently enabled repositories)
explicit EnvironmentQuery(const libdnf5::BaseWeakPtr & base, bool empty = false);
explicit EnvironmentQuery(libdnf5::Base & base, bool empty = false);

void filter_environmentid(const std::string & pattern, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ) {
filter(F::environmentid, pattern, cmp);
}
~EnvironmentQuery();

void filter_environmentid(
const std::vector<std::string> & patterns, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ) {
filter(F::environmentid, patterns, cmp);
}
EnvironmentQuery(const EnvironmentQuery & src);
EnvironmentQuery & operator=(const EnvironmentQuery & src);

void filter_name(const std::string & pattern, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ) {
filter(F::name, pattern, cmp);
}
EnvironmentQuery(EnvironmentQuery && src) noexcept;
EnvironmentQuery & operator=(EnvironmentQuery && src) noexcept;

void filter_name(const std::vector<std::string> & patterns, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ) {
filter(F::name, patterns, cmp);
}
void filter_environmentid(const std::string & pattern, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ);
void filter_environmentid(
const std::vector<std::string> & patterns, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ);

void filter_installed(bool value) { filter(F::is_installed, value, sack::QueryCmp::EQ); }
void filter_name(const std::string & pattern, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ);

private:
struct F {
static std::string environmentid(const Environment & obj) { return obj.get_environmentid(); }
static std::string name(const Environment & obj) { return obj.get_name(); }
static bool is_installed(const Environment & obj) { return obj.get_installed(); }
};
void filter_name(const std::vector<std::string> & patterns, sack::QueryCmp cmp = libdnf5::sack::QueryCmp::EQ);

libdnf5::BaseWeakPtr base;
void filter_installed(bool value);

private:
friend Environment;
class Impl;
std::unique_ptr<Impl> p_impl;
};


Expand Down
57 changes: 56 additions & 1 deletion libdnf5/comps/environment/query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,23 @@ extern "C" {

namespace libdnf5::comps {

class EnvironmentQuery::Impl {
public:
explicit Impl(const libdnf5::BaseWeakPtr & base) : base(base) {}

EnvironmentQuery::EnvironmentQuery(const BaseWeakPtr & base, bool empty) : base(base) {
private:
friend EnvironmentQuery;

struct F {
static std::string environmentid(const Environment & obj) { return obj.get_environmentid(); }
static std::string name(const Environment & obj) { return obj.get_name(); }
static bool is_installed(const Environment & obj) { return obj.get_installed(); }
};

libdnf5::BaseWeakPtr base;
};

EnvironmentQuery::EnvironmentQuery(const BaseWeakPtr & base, bool empty) : p_impl(std::make_unique<Impl>(base)) {
if (empty) {
return;
}
Expand Down Expand Up @@ -101,5 +116,45 @@ EnvironmentQuery::EnvironmentQuery(const BaseWeakPtr & base, bool empty) : base(

EnvironmentQuery::EnvironmentQuery(Base & base, bool empty) : EnvironmentQuery(base.get_weak_ptr(), empty) {}

EnvironmentQuery::~EnvironmentQuery() = default;

EnvironmentQuery::EnvironmentQuery(const EnvironmentQuery & src)
: libdnf5::sack::Query<Environment>(src),
p_impl(new Impl(*src.p_impl)) {}
EnvironmentQuery::EnvironmentQuery(EnvironmentQuery && src) noexcept = default;

EnvironmentQuery & EnvironmentQuery::operator=(const EnvironmentQuery & src) {
libdnf5::sack::Query<Environment>::operator=(src);
if (this != &src) {
if (p_impl) {
*p_impl = *src.p_impl;
} else {
p_impl = std::make_unique<Impl>(*src.p_impl);
}
}

return *this;
}
EnvironmentQuery & EnvironmentQuery::operator=(EnvironmentQuery && src) noexcept = default;

void EnvironmentQuery::filter_environmentid(const std::string & pattern, sack::QueryCmp cmp) {
filter(Impl::F::environmentid, pattern, cmp);
}

void EnvironmentQuery::filter_environmentid(const std::vector<std::string> & patterns, sack::QueryCmp cmp) {
filter(Impl::F::environmentid, patterns, cmp);
}

void EnvironmentQuery::filter_name(const std::string & pattern, sack::QueryCmp cmp) {
filter(Impl::F::name, pattern, cmp);
}

void EnvironmentQuery::filter_name(const std::vector<std::string> & patterns, sack::QueryCmp cmp) {
filter(Impl::F::name, patterns, cmp);
}

void EnvironmentQuery::filter_installed(bool value) {
filter(Impl::F::is_installed, value, sack::QueryCmp::EQ);
}

} // namespace libdnf5::comps

0 comments on commit c515b69

Please sign in to comment.