LibreOffice Module sc (master) 1
SparklineList.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 */
10
11#include <SparklineList.hxx>
12
13namespace sc
14{
16
17void SparklineList::addSparkline(std::shared_ptr<Sparkline> const& pSparkline)
18{
19 auto pWeakGroup = std::weak_ptr<SparklineGroup>(pSparkline->getSparklineGroup());
20
21 auto[iterator, bInserted]
22 = m_aSparklineGroupMap.try_emplace(pWeakGroup, std::vector<std::weak_ptr<Sparkline>>());
23 iterator->second.push_back(std::weak_ptr<Sparkline>(pSparkline));
24 if (bInserted)
25 m_aSparklineGroups.push_back(pWeakGroup);
26}
27
28void SparklineList::removeSparkline(std::shared_ptr<Sparkline> const& pSparkline)
29{
30 auto pWeakGroup = std::weak_ptr<SparklineGroup>(pSparkline->getSparklineGroup());
31 auto iteratorGroup = m_aSparklineGroupMap.find(pWeakGroup);
32 if (iteratorGroup != m_aSparklineGroupMap.end())
33 {
34 auto& rWeakSparklines = iteratorGroup->second;
35
36 for (auto iterator = rWeakSparklines.begin(); iterator != rWeakSparklines.end();)
37 {
38 auto pCurrentSparkline = iterator->lock();
39
40 if (pCurrentSparkline && pCurrentSparkline != pSparkline)
41 {
42 iterator++;
43 }
44 else
45 {
46 iterator = rWeakSparklines.erase(iterator);
47 }
48 }
49 }
50}
51
52std::vector<std::shared_ptr<SparklineGroup>> SparklineList::getSparklineGroups()
53{
54 std::vector<std::shared_ptr<SparklineGroup>> toReturn;
55
56 for (auto iterator = m_aSparklineGroups.begin(); iterator != m_aSparklineGroups.end();)
57 {
58 auto pWeakGroup = *iterator;
59 if (auto pSparklineGroup = pWeakGroup.lock())
60 {
61 toReturn.push_back(pSparklineGroup);
62 iterator++;
63 }
64 else
65 {
66 iterator = m_aSparklineGroups.erase(iterator);
67 }
68 }
69 return toReturn;
70}
71
72std::vector<std::shared_ptr<Sparkline>>
73SparklineList::getSparklinesFor(std::shared_ptr<SparklineGroup> const& pSparklineGroup)
74{
75 std::vector<std::shared_ptr<Sparkline>> toReturn;
76
77 std::weak_ptr<SparklineGroup> pWeakGroup(pSparklineGroup);
78 auto iteratorGroup = m_aSparklineGroupMap.find(pWeakGroup);
79
80 if (iteratorGroup == m_aSparklineGroupMap.end())
81 return toReturn;
82
83 auto& rWeakSparklines = iteratorGroup->second;
84
85 for (auto iterator = rWeakSparklines.begin(); iterator != rWeakSparklines.end();)
86 {
87 if (auto aSparkline = iterator->lock())
88 {
89 toReturn.push_back(aSparkline);
90 iterator++;
91 }
92 else
93 {
94 iterator = rWeakSparklines.erase(iterator);
95 }
96 }
97
98 return toReturn;
99}
100
101} // end sc
102
103/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< std::weak_ptr< SparklineGroup > > m_aSparklineGroups
void removeSparkline(std::shared_ptr< Sparkline > const &pSparkline)
void addSparkline(std::shared_ptr< Sparkline > const &pSparkline)
std::map< std::weak_ptr< SparklineGroup >, std::vector< std::weak_ptr< Sparkline > >, std::owner_less<> > m_aSparklineGroupMap
std::vector< std::shared_ptr< Sparkline > > getSparklinesFor(std::shared_ptr< SparklineGroup > const &pSparklineGroup)
std::vector< std::shared_ptr< SparklineGroup > > getSparklineGroups()
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15