Line data Source code
1 : /*! 2 : * \file esys/repo/manifest/depends_manifest.cpp 3 : * \brief Repository depends edge (ADR-0022) 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2026 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/depends.h" 20 : 21 : namespace esys::repo::manifest 22 : { 23 : 24 7 : Depends::Depends() = default; 25 : 26 7 : Depends::~Depends() = default; 27 : 28 7 : void Depends::set_selector(DependsSelector selector) 29 : { 30 7 : m_selector = selector; 31 7 : } 32 : 33 17 : DependsSelector Depends::get_selector() const 34 : { 35 17 : return m_selector; 36 : } 37 : 38 7 : void Depends::set_value(const std::string &value) 39 : { 40 7 : m_value = value; 41 7 : } 42 : 43 18 : const std::string &Depends::get_value() const 44 : { 45 18 : return m_value; 46 : } 47 : 48 6 : void Depends::set_resolved_path(const std::string &path) 49 : { 50 6 : m_resolved_path = path; 51 6 : } 52 : 53 23 : const std::string &Depends::get_resolved_path() const 54 : { 55 23 : return m_resolved_path; 56 : } 57 : 58 0 : void Depends::clear() 59 : { 60 0 : m_selector = DependsSelector::NOT_SET; 61 0 : m_value.clear(); 62 0 : m_resolved_path.clear(); 63 0 : } 64 : 65 0 : bool Depends::operator==(const Depends &other) const 66 : { 67 0 : return get_selector() == other.get_selector() && get_value() == other.get_value() 68 0 : && get_resolved_path() == other.get_resolved_path(); 69 : } 70 : 71 0 : bool Depends::operator!=(const Depends &other) const 72 : { 73 0 : return !operator==(other); 74 : } 75 : 76 2 : std::string to_string(DependsSelector selector) 77 : { 78 2 : switch (selector) 79 : { 80 2 : case DependsSelector::PATH: return "path"; 81 0 : case DependsSelector::NAME: return "name"; 82 0 : case DependsSelector::PROJECT: return "project"; 83 0 : case DependsSelector::URL: return "url"; 84 0 : default: return ""; 85 : } 86 : } 87 : 88 0 : bool depends_selector_from_string(const std::string &text, DependsSelector &selector) 89 : { 90 0 : if (text == "path") 91 : { 92 0 : selector = DependsSelector::PATH; 93 0 : return true; 94 : } 95 0 : if (text == "name") 96 : { 97 0 : selector = DependsSelector::NAME; 98 0 : return true; 99 : } 100 0 : if (text == "project") 101 : { 102 0 : selector = DependsSelector::PROJECT; 103 0 : return true; 104 : } 105 0 : if (text == "url") 106 : { 107 0 : selector = DependsSelector::URL; 108 0 : return true; 109 : } 110 0 : selector = DependsSelector::NOT_SET; 111 0 : return false; 112 : } 113 : 114 : } // namespace esys::repo::manifest