1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #ifndef INCLUDED_SC_INC_DPRESFILTER_HXX
11 #define INCLUDED_SC_INC_DPRESFILTER_HXX
13 #include "dpitemdata.hxx"
18 #include <unordered_map>
20 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{
21 struct DataPilotFieldFilter
;
24 struct ScDPResultFilter
33 ScDPResultFilter(const OUString
& rDimName
, bool bDataLayout
);
37 * This class maintains pivot table calculation result in a tree structure
38 * which represents the logical structure of pivot table result layout as
39 * presented in the sheet.
41 * <p>The root node has two child nodes if the pivot table consists of both
42 * column and row dimensions. The first child stores the result tree that is
43 * first filtered by row dimensions then by column dimensions. The second
44 * child stores the result tree that is filtered by column dimensions only
45 * (for column grand totals).</p>
47 * <p>If the pivot table layout only consists of either column or row
48 * dimensions, the root node only has one child node.</p>
53 typedef std::vector
<double> ValuesType
;
59 typedef std::map
<OUString
, std::shared_ptr
<MemberNode
> > MembersType
;
60 typedef std::map
<OUString
, DimensionNode
*> DimensionsType
;
64 MembersType maChildMembersValueNames
;
65 MembersType maChildMembersValues
;
68 DimensionNode(const DimensionNode
&) = delete;
69 const DimensionNode
& operator=(const DimensionNode
&) = delete;
73 void dump(int nLevel
) const;
80 DimensionsType maChildDimensions
;
83 MemberNode(const MemberNode
&) = delete;
84 const MemberNode
& operator=(const MemberNode
&) = delete;
88 void dump(int nLevel
) const;
92 typedef std::pair
<OUString
, OUString
> NamePairType
;
96 size_t operator() (const NamePairType
& rPair
) const;
98 typedef std::unordered_map
<NamePairType
, double, NamePairHash
> LeafValuesType
;
99 LeafValuesType maLeafValues
;
101 OUString maPrimaryDimName
;
102 std::unique_ptr
<MemberNode
> mpRoot
;
107 ScDPResultTree(const ScDPResultTree
&) = delete;
108 const ScDPResultTree
& operator=(const ScDPResultTree
&) = delete;
111 * Add a single value filter path. The filters are expected to be sorted
112 * by row dimension order then by column dimension order.
114 * @param rFilter set of filters.
115 * @param fVal result value, as displayed in the table output.
117 void add(const std::vector
<ScDPResultFilter
>& rFilter
, double fVal
);
119 void swap(ScDPResultTree
& rOther
);
124 const ValuesType
* getResults(
125 const css::uno::Sequence
< css::sheet::DataPilotFieldFilter
>& rFilters
) const;
127 double getLeafResult(const css::sheet::DataPilotFieldFilter
& rFilter
) const;
129 #if DEBUG_PIVOT_TABLE
134 struct ScDPResultFilterContext
136 ScDPResultTree maFilterSet
;
137 std::vector
<ScDPResultFilter
> maFilters
;
141 ScDPResultFilterContext();
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */