Skip to content

Commit

Permalink
Store "share_ptr<Repo>" instead of copy of "Repo" into "RepoDict"
Browse files Browse the repository at this point in the history
Storing copy of copy of Repo into RepoDict is not good idea.
Probably we do not want n kopies of the same repo. So we will store pointer to the original repo.
But who will be responsible for memory management? OK, there is shared_ptr.
  • Loading branch information
jrohel authored and dmach committed Oct 31, 2017
1 parent 232a4a6 commit 28c9af8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
8 changes: 4 additions & 4 deletions libdnf/repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const vector<string>& Repo::get_baseurl() {
}


void RepoDict::set_repos(const map<string, Repo>& repos) {
void RepoDict::set_repos(const map<string, shared_ptr<Repo>> & repos) {
_repos = repos;
}

const map<string, Repo>& RepoDict::get_repos() {
const map<string, shared_ptr<Repo>> & RepoDict::get_repos() {
return _repos;
}

void RepoDict::add_repo(Repo repo) {
_repos[repo.get_repoid()] = repo;
void RepoDict::add_repo(shared_ptr<Repo> & repo) {
_repos[repo->get_repoid()] = repo;
}
9 changes: 5 additions & 4 deletions libdnf/repo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include <map>
#include <memory>

#include "package.hpp"

Expand All @@ -27,12 +28,12 @@ class Repo {

class RepoDict {
private:
std::map<std::string, Repo> _repos;
std::map<std::string, std::shared_ptr<Repo>> _repos;

public:
void set_repos(const std::map<std::string,Repo>& value);
const std::map<std::string,Repo>& get_repos();
void add_repo(Repo repo);
void set_repos(const std::map<std::string, std::shared_ptr<Repo>> & value);
const std::map<std::string, std::shared_ptr<Repo>> & get_repos();
void add_repo(std::shared_ptr<Repo> & repo);
};

#endif
15 changes: 8 additions & 7 deletions libdnf/repo.i
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
%module repo


%{
// make SWIG wrap following headers
#include "repo.hpp"
%}


%include <attribute.i>
%include <std_string.i>
%include <std_vector.i>
%include <std_map.i>
%include <std_shared_ptr.i>

%shared_ptr(Repo)

%{
// make SWIG wrap following headers
#include "repo.hpp"
%}

namespace std {
%template(list_string) vector<string>;
%template(list_package) vector<Package*>;
%template() map<string, Repo>;
%template() map<string, shared_ptr<Repo>>;
}


Expand Down

0 comments on commit 28c9af8

Please sign in to comment.