Line data Source code
1 : /*! 2 : * \file esys/repo/manifest/groups_manifest.cpp 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 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/groups.h" 20 : 21 : namespace esys::repo::manifest 22 : { 23 : 24 48 : Groups::Groups() 25 48 : : std::enable_shared_from_this<Groups>() 26 : { 27 48 : } 28 : 29 48 : Groups::~Groups() = default; 30 : 31 34 : void Groups::add_group(std::shared_ptr<Group> group) 32 : { 33 34 : get_groups().push_back(group); 34 34 : m_map_groups_by_name[group->get_name()] = group; 35 34 : } 36 : 37 40 : std::vector<std::shared_ptr<Group>> &Groups::get_groups() 38 : { 39 40 : return m_groups; 40 : } 41 : 42 0 : const std::vector<std::shared_ptr<Group>> &Groups::get_groups() const 43 : { 44 0 : return m_groups; 45 : } 46 : 47 92 : std::shared_ptr<Group> Groups::find_group_by_name(const std::string &name) 48 : { 49 92 : auto it = m_map_groups_by_name.find(name); 50 : 51 92 : if (it == m_map_groups_by_name.end()) return nullptr; 52 62 : return it->second; 53 : } 54 : 55 90 : std::shared_ptr<Group> Groups::find_or_new_group_by_name(const std::string &name) 56 : { 57 90 : auto group = find_group_by_name(name); 58 : 59 90 : if (group != nullptr) return group; 60 : 61 30 : group = std::make_shared<Group>(name); 62 60 : add_group(group); 63 30 : return group; 64 0 : } 65 : 66 57 : void Groups::clear() 67 : { 68 57 : m_groups.clear(); 69 57 : m_map_groups_by_name.clear(); 70 57 : } 71 : 72 : } // namespace esys::repo::manifest