Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / data / columnset.cxx
blob2e1f3aa956e42d0e4efbb77a9667827ed9f9c650
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include "columnset.hxx"
12 namespace sc {
14 void ColumnSet::set(SCTAB nTab, SCCOL nCol)
16 TabsType::iterator itTab = maTabs.find(nTab);
17 if (itTab == maTabs.end())
19 std::pair<TabsType::iterator,bool> r =
20 maTabs.insert(TabsType::value_type(nTab, ColsType()));
22 if (!r.second)
23 // insertion failed.
24 return;
26 itTab = r.first;
29 ColsType& rCols = itTab->second;
30 rCols.insert(nCol);
33 bool ColumnSet::has(SCTAB nTab, SCCOL nCol) const
35 TabsType::const_iterator itTab = maTabs.find(nTab);
36 if (itTab == maTabs.end())
37 return false;
39 const ColsType& rCols = itTab->second;
40 return rCols.count(nCol) > 0;
43 void ColumnSet::getColumns(SCTAB nTab, std::vector<SCCOL>& rCols) const
45 std::vector<SCCOL> aCols;
46 TabsType::const_iterator itTab = maTabs.find(nTab);
47 if (itTab == maTabs.end())
49 rCols.swap(aCols); // empty it.
50 return;
53 const ColsType& rTabCols = itTab->second;
54 aCols.assign(rTabCols.begin(), rTabCols.end());
56 // Sort and remove duplicates.
57 std::sort(aCols.begin(), aCols.end());
58 std::vector<SCCOL>::iterator itCol = std::unique(aCols.begin(), aCols.end());
59 aCols.erase(itCol, aCols.end());
61 rCols.swap(aCols);
66 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */