/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * */ #include namespace sc { SparklineList::SparklineList() = default; void SparklineList::addSparkline(std::shared_ptr const& pSparkline) { auto pWeakGroup = std::weak_ptr(pSparkline->getSparklineGroup()); auto[iterator, bInserted] = m_aSparklineGroupMap.try_emplace(pWeakGroup, std::vector>()); iterator->second.push_back(std::weak_ptr(pSparkline)); if (bInserted) m_aSparklineGroups.push_back(pWeakGroup); } void SparklineList::removeSparkline(std::shared_ptr const& pSparkline) { auto pWeakGroup = std::weak_ptr(pSparkline->getSparklineGroup()); auto iteratorGroup = m_aSparklineGroupMap.find(pWeakGroup); if (iteratorGroup != m_aSparklineGroupMap.end()) { auto& rWeakSparklines = iteratorGroup->second; for (auto iterator = rWeakSparklines.begin(); iterator != rWeakSparklines.end();) { auto pCurrentSparkline = iterator->lock(); if (pCurrentSparkline && pCurrentSparkline != pSparkline) { iterator++; } else { iterator = rWeakSparklines.erase(iterator); } } } } std::vector> SparklineList::getSparklineGroups() { std::vector> toReturn; for (auto iterator = m_aSparklineGroups.begin(); iterator != m_aSparklineGroups.end();) { auto pWeakGroup = *iterator; if (auto pSparklineGroup = pWeakGroup.lock()) { toReturn.push_back(pSparklineGroup); iterator++; } else { iterator = m_aSparklineGroups.erase(iterator); } } return toReturn; } std::vector> SparklineList::getSparklinesFor(std::shared_ptr const& pSparklineGroup) { std::vector> toReturn; std::weak_ptr pWeakGroup(pSparklineGroup); auto iteratorGroup = m_aSparklineGroupMap.find(pWeakGroup); if (iteratorGroup == m_aSparklineGroupMap.end()) return toReturn; auto& rWeakSparklines = iteratorGroup->second; for (auto iterator = rWeakSparklines.begin(); iterator != rWeakSparklines.end();) { if (auto aSparkline = iterator->lock()) { toReturn.push_back(aSparkline); iterator++; } else { iterator = rWeakSparklines.erase(iterator); } } return toReturn; } } // end sc /* vim:set shiftwidth=4 softtabstop=4 expandtab: */