Line data Source code
1 : /*! 2 : * \file esys/repo/manifest/capture_capture.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2023 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/capture.h" 20 : 21 : namespace esys::repo::manifest 22 : { 23 : 24 5 : Capture::Capture() = default; 25 : 26 5 : Capture::~Capture() = default; 27 : 28 2 : void Capture::add_item(const std::string &path, const std::string &revision) 29 : { 30 2 : auto item = std::make_shared<Item>(path, revision); 31 2 : m_map_path_item[path] = item; 32 2 : m_items.push_back(item); 33 2 : } 34 : 35 9 : void Capture::add_item(std::shared_ptr<Item> item) 36 : { 37 9 : m_items.push_back(item); 38 9 : } 39 : 40 3 : void Capture::clear() 41 : { 42 3 : m_items.clear(); 43 3 : m_map_path_item.clear(); 44 3 : } 45 : 46 0 : std::shared_ptr<Capture::Item> Capture::find_item(const std::string &path) const 47 : { 48 0 : auto it = m_map_path_item.find(path); 49 : 50 0 : if (it == m_map_path_item.end()) return nullptr; 51 0 : return it->second; 52 : } 53 : 54 5 : std::vector<std::shared_ptr<Capture::Item>> &Capture::get_items() 55 : { 56 5 : return m_items; 57 : } 58 40 : const std::vector<std::shared_ptr<Capture::Item>> &Capture::get_items() const 59 : { 60 40 : return m_items; 61 : } 62 : 63 0 : std::map<std::string, std::shared_ptr<Capture::Item>, std::less<>> &Capture::get_map() 64 : { 65 0 : return m_map_path_item; 66 : } 67 : 68 0 : const std::map<std::string, std::shared_ptr<Capture::Item>, std::less<>> &Capture::get_map() const 69 : { 70 0 : return m_map_path_item; 71 : } 72 : 73 4 : bool Capture::operator==(const Capture &other) const 74 : { 75 4 : if (get_items().size() != other.get_items().size()) return false; 76 : 77 8 : for (auto idx = 0; idx < get_items().size(); ++idx) 78 : { 79 6 : if ((get_items()[idx] == nullptr) || (other.get_items()[idx] == nullptr)) return false; 80 6 : if (*get_items()[idx] != *other.get_items()[idx]) return false; 81 : } 82 : return true; 83 : } 84 : 85 0 : bool Capture::operator!=(const Capture &other) const 86 : { 87 0 : return !operator==(other); 88 : } 89 : 90 9 : Capture::Item::Item() = default; 91 : 92 2 : Capture::Item::Item(const std::string &path, const std::string &revision) 93 2 : : m_path(path) 94 2 : , m_revision(revision) 95 : { 96 2 : } 97 : 98 11 : Capture::Item::~Item() = default; 99 : 100 9 : void Capture::Item::set_path(const std::string &path) 101 : { 102 9 : m_path = path; 103 9 : } 104 : 105 27 : const std::string &Capture::Item::get_path() const 106 : { 107 27 : return m_path; 108 : } 109 : 110 9 : void Capture::Item::set_revision(const std::string &revision) 111 : { 112 9 : m_revision = revision; 113 9 : } 114 : 115 27 : const std::string &Capture::Item::get_revision() const 116 : { 117 27 : return m_revision; 118 : } 119 : 120 5 : void Capture::Item::set_remote_name(const std::string &remote_name) 121 : { 122 5 : m_remote_name = remote_name; 123 5 : } 124 : 125 23 : const std::string &Capture::Item::get_remote_name() const 126 : { 127 23 : return m_remote_name; 128 : } 129 : 130 5 : void Capture::Item::set_remote_url(const std::string &remote_url) 131 : { 132 5 : m_remote_url = remote_url; 133 5 : } 134 : 135 23 : const std::string &Capture::Item::get_remote_url() const 136 : { 137 23 : return m_remote_url; 138 : } 139 : 140 6 : bool Capture::Item::operator==(const Item &other) const 141 : { 142 6 : if (get_path() != other.get_path()) return false; 143 6 : if (get_revision() != other.get_revision()) return false; 144 6 : if (get_remote_name() != other.get_remote_name()) return false; 145 6 : if (get_remote_url() != other.get_remote_url()) return false; 146 : 147 : return true; 148 : } 149 : 150 6 : bool Capture::Item::operator!=(const Item &other) const 151 : { 152 6 : return !operator==(other); 153 : } 154 : 155 : } // namespace esys::repo::manifest