LibreOffice Module sc (master) 1
columnset.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#include <columnset.hxx>
11#include <algorithm>
12
13namespace sc {
14
15void ColumnSet::set(SCTAB nTab, SCCOL nCol)
16{
17 TabsType::iterator itTab = maTabs.find(nTab);
18 if (itTab == maTabs.end())
19 {
20 std::pair<TabsType::iterator,bool> r =
21 maTabs.emplace(nTab, ColsType());
22
23 if (!r.second)
24 // insertion failed.
25 return;
26
27 itTab = r.first;
28 }
29
30 ColsType& rCols = itTab->second;
31 rCols.insert(nCol);
32}
33
34void ColumnSet::getColumns(SCTAB nTab, std::vector<SCCOL>& rCols) const
35{
36 std::vector<SCCOL> aCols;
37 TabsType::const_iterator itTab = maTabs.find(nTab);
38 if (itTab == maTabs.end())
39 {
40 rCols.swap(aCols); // empty it.
41 return;
42 }
43
44 const ColsType& rTabCols = itTab->second;
45 aCols.assign(rTabCols.begin(), rTabCols.end());
46
47 // Sort and remove duplicates.
48 std::sort(aCols.begin(), aCols.end());
49 std::vector<SCCOL>::iterator itCol = std::unique(aCols.begin(), aCols.end());
50 aCols.erase(itCol, aCols.end());
51
52 rCols.swap(aCols);
53}
54
55bool ColumnSet::hasTab(SCTAB nTab) const
56{
57 return maTabs.find(nTab) != maTabs.end();
58}
59
60bool ColumnSet::empty() const
61{
62 return maTabs.empty();
63}
64
65}
66
67/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
TabsType maTabs
Definition: columnset.hxx:27
std::unordered_set< SCCOL > ColsType
Definition: columnset.hxx:25
bool hasTab(SCTAB nTab) const
Definition: columnset.cxx:55
void getColumns(SCTAB nTab, std::vector< SCCOL > &rCols) const
Definition: columnset.cxx:34
bool empty() const
Definition: columnset.cxx:60
void set(SCTAB nTab, SCCOL nCol)
Definition: columnset.cxx:15
CAUTION! The following defines must be in the same namespace as the respective type.
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21