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/.
12 #include <rtl/ustring.hxx>
13 #include "calcmacros.hxx"
18 #include <unordered_map>
20 namespace com::sun::star::uno
22 template <typename
> class Sequence
;
24 namespace com::sun::star::sheet
26 struct DataPilotFieldFilter
;
29 struct ScDPResultFilter
36 bool mbDataLayout
: 1;
38 ScDPResultFilter(OUString aDimName
, bool bDataLayout
);
42 * This class maintains pivot table calculation result in a tree structure
43 * which represents the logical structure of pivot table result layout as
44 * presented in the sheet.
46 * <p>The root node has two child nodes if the pivot table consists of both
47 * column and row dimensions. The first child stores the result tree that is
48 * first filtered by row dimensions then by column dimensions. The second
49 * child stores the result tree that is filtered by column dimensions only
50 * (for column grand totals).</p>
52 * <p>If the pivot table layout only consists of either column or row
53 * dimensions, the root node only has one child node.</p>
58 typedef std::vector
<double> ValuesType
;
62 typedef std::map
<OUString
, std::shared_ptr
<MemberNode
>> MembersType
;
66 MembersType maChildMembersValueNames
;
67 MembersType maChildMembersValues
;
70 void dump(int nLevel
) const;
77 std::map
<OUString
, DimensionNode
> maChildDimensions
;
80 MemberNode(const MemberNode
&) = delete;
81 const MemberNode
& operator=(const MemberNode
&) = delete;
85 void dump(int nLevel
) const;
89 typedef std::pair
<OUString
, OUString
> NamePairType
;
93 size_t operator()(const NamePairType
& rPair
) const;
95 typedef std::unordered_map
<NamePairType
, double, NamePairHash
> LeafValuesType
;
96 LeafValuesType maLeafValues
;
98 OUString maPrimaryDimName
;
99 std::unique_ptr
<MemberNode
> mpRoot
;
103 ScDPResultTree(const ScDPResultTree
&) = delete;
104 const ScDPResultTree
& operator=(const ScDPResultTree
&) = delete;
107 * Add a single value filter path. The filters are expected to be sorted
108 * by row dimension order then by column dimension order.
110 * @param rFilter set of filters.
111 * @param fVal result value, as displayed in the table output.
113 void add(const std::vector
<ScDPResultFilter
>& rFilter
, double fVal
);
115 void swap(ScDPResultTree
& rOther
);
121 getResults(const css::uno::Sequence
<css::sheet::DataPilotFieldFilter
>& rFilters
) const;
123 double getLeafResult(const css::sheet::DataPilotFieldFilter
& rFilter
) const;
125 #if DEBUG_PIVOT_TABLE
130 struct ScDPResultFilterContext
132 ScDPResultTree maFilterSet
;
133 std::vector
<ScDPResultFilter
> maFilters
;
137 ScDPResultFilterContext();
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */