Line data Source code
1 : /*! 2 : * \file esys/repo/manifest/repository_manifest.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2020-2021 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #include "esys/repo/esysrepo_prec.h" 19 : #include "esys/repo/manifest/repository.h" 20 : #include "esys/repo/manifest/group.h" 21 : #include "esys/repo/manifest/location.h" 22 : 23 : #include <boost/filesystem.hpp> 24 : 25 : namespace esys::repo::manifest 26 : { 27 : 28 583 : Repository::Repository() = default; 29 : 30 61 : Repository::Repository(const std::string &name, const std::string &path) 31 61 : : m_name(name) 32 61 : , m_path(path) 33 : { 34 61 : } 35 : 36 644 : Repository::~Repository() = default; 37 : 38 581 : void Repository::set_name(const std::string &name) 39 : { 40 581 : m_name = name; 41 581 : } 42 : 43 1297 : const std::string &Repository::get_name() const 44 : { 45 1297 : return m_name; 46 : } 47 : 48 581 : void Repository::set_path(const std::string &path) 49 : { 50 581 : boost::filesystem::path gen_path = path; 51 : 52 1743 : m_path = gen_path.generic_path().string(); 53 581 : } 54 : 55 2851 : const std::string &Repository::get_path() const 56 : { 57 2851 : return m_path; 58 : } 59 : 60 203 : void Repository::set_revision(const std::string &revision) 61 : { 62 203 : m_revision = revision; 63 203 : } 64 : 65 498 : const std::string &Repository::get_revision() const 66 : { 67 498 : return m_revision; 68 : } 69 : 70 996 : void Repository::set_location(const std::string &location_str) 71 : { 72 996 : m_location_str = location_str; 73 996 : } 74 : 75 32 : const std::string &Repository::get_location_str() const 76 : { 77 32 : return m_location_str; 78 : } 79 : 80 943 : void Repository::set_location(Location *location) 81 : { 82 943 : m_location = location; 83 943 : if (location == nullptr) return; 84 : 85 943 : set_location(location->get_name()); 86 : } 87 : 88 245 : Location *Repository::get_location() const 89 : { 90 245 : return m_location; 91 : } 92 : 93 28 : std::string Repository::get_url() const 94 : { 95 28 : if (get_location() == nullptr) return ""; 96 : 97 28 : std::string url = get_location()->get_address() + "/" + get_name(); 98 56 : return url; 99 28 : } 100 : 101 194 : std::vector<Group *> &Repository::get_groups() 102 : { 103 194 : return m_groups; 104 : } 105 : 106 42 : const std::vector<Group *> &Repository::get_groups() const 107 : { 108 42 : return m_groups; 109 : } 110 : 111 4 : void Repository::set_sync_s(std::optional<bool> sync_s) 112 : { 113 4 : m_sync_s = sync_s; 114 4 : } 115 : 116 279 : const std::optional<bool> &Repository::get_sync_s() const 117 : { 118 279 : return m_sync_s; 119 : } 120 : 121 7 : void Repository::add_depends(std::shared_ptr<Depends> depends) 122 : { 123 7 : if (depends == nullptr) return; 124 7 : m_depends.push_back(depends); 125 : } 126 : 127 759 : std::vector<std::shared_ptr<Depends>> &Repository::get_depends() 128 : { 129 759 : return m_depends; 130 : } 131 : 132 24 : const std::vector<std::shared_ptr<Depends>> &Repository::get_depends() const 133 : { 134 24 : return m_depends; 135 : } 136 : 137 0 : void Repository::clear_depends() 138 : { 139 0 : m_depends.clear(); 140 0 : } 141 : 142 8 : bool Repository::operator==(const Repository &repository) const 143 : { 144 8 : if (get_name() != repository.get_name()) return false; 145 8 : if (get_path() != repository.get_path()) return false; 146 8 : if (get_revision() != repository.get_revision()) return false; 147 8 : if (get_location_str() != repository.get_location_str()) return false; 148 8 : if (get_url() != repository.get_url()) return false; 149 16 : if (get_sync_s() != repository.get_sync_s()) return false; 150 : 151 8 : if (get_groups().size() != repository.get_groups().size()) return false; 152 : 153 14 : for (std::size_t idx = 0; idx < get_groups().size(); ++idx) 154 : { 155 6 : if (get_groups()[idx]->get_name() != repository.get_groups()[idx]->get_name()) return false; 156 : } 157 : 158 8 : if (get_depends().size() != repository.get_depends().size()) return false; 159 8 : for (std::size_t idx = 0; idx < get_depends().size(); ++idx) 160 : { 161 0 : if (*get_depends()[idx] != *repository.get_depends()[idx]) return false; 162 : } 163 : 164 : return true; 165 : } 166 : 167 8 : bool Repository::operator!=(const Repository &repository) const 168 : { 169 8 : return !operator==(repository); 170 : } 171 : 172 : } // namespace esys::repo::manifest