Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pImpl to several classes #1183

Merged
merged 8 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions include/libdnf5/base/log_event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,29 @@ class LogEvent {
const libdnf5::transaction::TransactionItemType spec_type,
const std::string & spec);
LogEvent(libdnf5::GoalProblem problem, const SolverProblems & solver_problems);
~LogEvent() = default;
~LogEvent();

LogEvent(const LogEvent & src);
LogEvent & operator=(const LogEvent & src);

LogEvent(LogEvent && src) noexcept;
LogEvent & operator=(LogEvent && src) noexcept;

/// @return GoalAction for which goal event was created
libdnf5::GoalAction get_action() const { return action; };
libdnf5::GoalAction get_action() const;
/// @return GoalProblem that specify the type of report
libdnf5::GoalProblem get_problem() const { return problem; };
libdnf5::GoalProblem get_problem() const;
/// @return Additional information (internal), that are required for formatted string
const std::set<std::string> get_additional_data() const { return additional_data; };
const std::set<std::string> & get_additional_data() const;
/// @return GoalJobSetting if it is relevant for the particular GoalProblem
const libdnf5::GoalJobSettings * get_job_settings() const {
return job_settings ? &job_settings.value() : nullptr;
};
const libdnf5::GoalJobSettings * get_job_settings() const;
/// @return SPEC if it is relevant for the particular GoalProblem
const std::string * get_spec() const { return spec ? &spec.value() : nullptr; };
const std::string * get_spec() const;
/// @return SolverProblems if they are relevant for the particular GoalProblem
const SolverProblems * get_solver_problems() const { return solver_problems ? &solver_problems.value() : nullptr; };
const SolverProblems * get_solver_problems() const;

/// Convert an element from resolve log to string;
std::string to_string() const {
return to_string(action, problem, additional_data, job_settings, spec_type, spec, solver_problems);
};
std::string to_string() const;

private:
/// Convert an element from resolve log to string;
Expand All @@ -77,14 +79,8 @@ class LogEvent {
const std::optional<std::string> & spec,
const std::optional<SolverProblems> & solver_problems);

libdnf5::GoalAction action;
libdnf5::GoalProblem problem;

std::set<std::string> additional_data;
std::optional<libdnf5::GoalJobSettings> job_settings;
std::optional<libdnf5::transaction::TransactionItemType> spec_type;
std::optional<std::string> spec;
std::optional<SolverProblems> solver_problems;
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5::base
Expand Down
9 changes: 3 additions & 6 deletions include/libdnf5/base/solver_problems.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "goal_elements.hpp"

#include "libdnf5/common/impl_ptr.hpp"


namespace libdnf5::base {

Expand All @@ -52,9 +50,7 @@ class SolverProblems {
/// be rendered into a string by the `problem_to_string()` method.
// @replaces libdnf/Goal.describeProblemRules(unsigned i, bool pkgs);
// @replaces libdnf/Goal.describeAllProblemRules(bool pkgs);
std::vector<std::vector<std::pair<libdnf5::ProblemRules, std::vector<std::string>>>> get_problems() const {
return problems;
};
std::vector<std::vector<std::pair<libdnf5::ProblemRules, std::vector<std::string>>>> get_problems() const;

/// Convert SolverProblems class to string representative;
std::string to_string() const;
Expand All @@ -65,7 +61,8 @@ class SolverProblems {
private:
friend class Transaction;

std::vector<std::vector<std::pair<libdnf5::ProblemRules, std::vector<std::string>>>> problems;
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5::base
Expand Down
16 changes: 11 additions & 5 deletions include/libdnf5/conf/config_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "libdnf5/common/exception.hpp"
#include "libdnf5/common/preserve_order_map.hpp"

#include <map>
#include <string>


Expand Down Expand Up @@ -86,6 +85,15 @@ struct ConfigParser {
public:
using Container = PreserveOrderMap<std::string, PreserveOrderMap<std::string, std::string>>;

ConfigParser();
~ConfigParser();

ConfigParser(const ConfigParser & src);
ConfigParser & operator=(const ConfigParser & src);

ConfigParser(ConfigParser && src) noexcept;
ConfigParser & operator=(ConfigParser && src) noexcept;

/**
* @brief Reads/parse one INI file
*
Expand Down Expand Up @@ -132,10 +140,8 @@ struct ConfigParser {
Container & get_data() noexcept;

private:
Container data;
int item_number{0};
std::string header;
std::map<std::string, std::string> raw_items;
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5
Expand Down
17 changes: 9 additions & 8 deletions include/libdnf5/conf/vars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "libdnf5/base/base_weak.hpp"

#include <map>
#include <set>
#include <string>
#include <vector>

Expand Down Expand Up @@ -60,16 +59,18 @@ struct Vars {
Priority priority;
};

Vars(const libdnf5::BaseWeakPtr & base) : base(base) {}
Vars(const libdnf5::BaseWeakPtr & base);
Vars(libdnf5::Base & base);

~Vars();

/// @brief Substitute DNF vars in the input text.
///
/// @param text The text for substitution
/// @return The substituted text
std::string substitute(const std::string & text) const;

const std::map<std::string, Variable> & get_variables() const { return variables; }
const std::map<std::string, Variable> & get_variables() const;

/// @brief Set particular variable to a value
///
Expand All @@ -89,17 +90,17 @@ struct Vars {
///
/// @param name Name of the variable
/// @return true if there is such an element, otherwise false
bool contains(const std::string & name) const { return variables.find(name) != variables.end(); }
bool contains(const std::string & name) const;

/// @brief Get value of particular variable.
///
/// @param name Name of the variable
const std::string & get_value(const std::string & name) const { return variables.at(name).value; }
const std::string & get_value(const std::string & name) const;

/// @brief Get particular variable.
///
/// @param name Name of the variable
const Variable & get(const std::string & name) const { return variables.at(name); }
const Variable & get(const std::string & name) const;

static std::unique_ptr<std::string> detect_release(const BaseWeakPtr & base, const std::string & install_root_path);

Expand Down Expand Up @@ -160,8 +161,8 @@ struct Vars {
/// @return releasever_major, releasever_minor
static std::tuple<std::string, std::string> split_releasever(const std::string & releasever);

BaseWeakPtr base;
std::map<std::string, Variable> variables;
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5
Expand Down
19 changes: 8 additions & 11 deletions include/libdnf5/repo/repo_sack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ class RepoSack : public sack::Sack<Repo> {
const std::vector<std::string> & paths, bool calculate_checksum = false);

/// @return `true` if the system repository has been initialized (via `get_system_repo()`).
bool has_system_repo() const noexcept { return system_repo; }
bool has_system_repo() const noexcept;

/// @return `true` if the command line repository has been initialized (via `get_cmdline_repo()`).
bool has_cmdline_repo() const noexcept { return cmdline_repo; }
bool has_cmdline_repo() const noexcept;

/// Dumps libsolv's rpm debugdata of all loaded repositories.
/// @param dir The directory into which to dump the debugdata.
Expand Down Expand Up @@ -135,7 +135,7 @@ class RepoSack : public sack::Sack<Repo> {
/// @param import_keys If true, attempts to download and import keys for repositories that failed key validation
void update_and_load_repos(libdnf5::repo::RepoQuery & repos, bool import_keys = true);

RepoSackWeakPtr get_weak_ptr() { return RepoSackWeakPtr(this, &sack_guard); }
RepoSackWeakPtr get_weak_ptr();

/// @return The `Base` object to which this object belongs.
/// @since 5.0
Expand All @@ -152,31 +152,28 @@ class RepoSack : public sack::Sack<Repo> {
/// are created from info in system state.
void fix_group_missing_xml();

~RepoSack();

private:
friend class libdnf5::Base;
friend class RepoQuery;
friend class rpm::PackageSack;

explicit RepoSack(const libdnf5::BaseWeakPtr & base) : base(base) {}
explicit RepoSack(const libdnf5::BaseWeakPtr & base);
explicit RepoSack(libdnf5::Base & base);

/// Loads repositories configuration overrides from drop-in directories. No new repositories are created.
/// Only the configuration of the corresponding existing repositories is modified.
void load_repos_configuration_overrides();

WeakPtrGuard<RepoSack, false> sack_guard;

/// If not created yet, creates the cmdline repository and returns it.
/// @return The cmdline repository.
libdnf5::repo::RepoWeakPtr get_cmdline_repo();

void internalize_repos();

BaseWeakPtr base;

repo::Repo * system_repo{nullptr};
repo::Repo * cmdline_repo{nullptr};
bool repos_updated_and_loaded{false};
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5::repo
Expand Down
54 changes: 33 additions & 21 deletions include/libdnf5/rpm/rpm_signature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ using RpmKeyPktPtr = std::unique_ptr<uint8_t, std::function<void(uint8_t * pkt)>

class KeyInfo {
public:
const std::string & get_key_id() const noexcept { return key_id; }
const std::string & get_key_id() const noexcept;
std::string get_short_key_id() const;
const std::vector<std::string> & get_user_ids() const noexcept { return user_ids; }
const std::string & get_fingerprint() const noexcept { return fingerprint; }
const std::string & get_url() const noexcept { return key_url; }
const std::string & get_path() const noexcept { return key_path; }
const std::string & get_raw_key() const noexcept { return raw_key; }
const long int & get_timestamp() const noexcept { return timestamp; }
const std::vector<std::string> & get_user_ids() const noexcept;
const std::string & get_fingerprint() const noexcept;
const std::string & get_url() const noexcept;
const std::string & get_path() const noexcept;
const std::string & get_raw_key() const noexcept;
const long int & get_timestamp() const noexcept;

protected:
friend class RpmSignature;
KeyInfo(
const std::string & key_url,
const std::string & key_path,
Expand All @@ -66,22 +64,35 @@ class KeyInfo {
const std::string & fingerprint,
long int timestamp,
const std::string & raw_key);
std::string key_url;
std::string key_path;
std::string key_id;
std::vector<std::string> user_ids;
std::string fingerprint;
long int timestamp;
std::string raw_key;

~KeyInfo();

KeyInfo(const KeyInfo & src);
KeyInfo & operator=(const KeyInfo & src);

KeyInfo(KeyInfo && src) noexcept;
KeyInfo & operator=(KeyInfo && src) noexcept;

protected:
void add_user_id(const char * user_id);

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

class RpmSignature {
public:
enum class CheckResult { OK, SKIPPED, FAILED_KEY_MISSING, FAILED_NOT_TRUSTED, FAILED_NOT_SIGNED, FAILED };

explicit RpmSignature(const libdnf5::BaseWeakPtr & base) : base(base) {}
explicit RpmSignature(Base & base) : RpmSignature(base.get_weak_ptr()) {}
~RpmSignature(){};
explicit RpmSignature(const libdnf5::BaseWeakPtr & base);
explicit RpmSignature(Base & base);
~RpmSignature();
RpmSignature(const RpmSignature & src);
RpmSignature & operator=(const RpmSignature & src);

RpmSignature(RpmSignature && src) noexcept;
RpmSignature & operator=(RpmSignature && src) noexcept;

/// Check signature of the `package` using public keys stored in rpm database.
/// @param package: package to check.
Expand All @@ -91,7 +102,7 @@ class RpmSignature {
/// CheckResult::FAILED_NOT_TRUSTED - signature is valid but the key is not trusted
/// CheckResult::FAILED_NOT_SIGNED - package is not signed but signature is required
/// CheckResult::FAILED - check failed for another reason
CheckResult check_package_signature(Package package) const;
CheckResult check_package_signature(const Package & pkg) const;

/// Import public key into rpm database.
/// @param key: GPG key to be imported into rpm database.
Expand All @@ -108,7 +119,8 @@ class RpmSignature {
static std::string check_result_to_string(CheckResult result);

private:
BaseWeakPtr base;
class Impl;
std::unique_ptr<Impl> p_impl;
};

} // namespace libdnf5::rpm
Expand Down
Loading
Loading