Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / dpresfilter.hxx
blob66971098588787fc7e3196707eacdf4a64d567fc
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 #ifndef INCLUDED_SC_INC_DPRESFILTER_HXX
11 #define INCLUDED_SC_INC_DPRESFILTER_HXX
13 #include "dpitemdata.hxx"
15 #include <memory>
16 #include <map>
17 #include <vector>
18 #include <unordered_map>
20 namespace com { namespace sun { namespace star { namespace sheet {
21 struct DataPilotFieldFilter;
22 }}}}
24 struct ScDPResultFilter
26 OUString maDimName;
27 OUString maValueName;
28 OUString maValue;
30 bool mbHasValue:1;
31 bool mbDataLayout:1;
33 ScDPResultFilter(const OUString& rDimName, bool bDataLayout);
36 /**
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>
50 class ScDPResultTree
52 public:
53 typedef std::vector<double> ValuesType;
55 private:
57 struct MemberNode;
58 struct DimensionNode;
59 typedef std::map<OUString, std::shared_ptr<MemberNode> > MembersType;
60 typedef std::map<OUString, DimensionNode*> DimensionsType;
62 struct DimensionNode
64 MembersType maChildMembersValueNames;
65 MembersType maChildMembersValues;
67 DimensionNode();
68 DimensionNode(const DimensionNode&) = delete;
69 const DimensionNode& operator=(const DimensionNode&) = delete;
70 ~DimensionNode();
72 #if DEBUG_PIVOT_TABLE
73 void dump(int nLevel) const;
74 #endif
77 struct MemberNode
79 ValuesType maValues;
80 DimensionsType maChildDimensions;
82 MemberNode();
83 MemberNode(const MemberNode&) = delete;
84 const MemberNode& operator=(const MemberNode&) = delete;
85 ~MemberNode();
87 #if DEBUG_PIVOT_TABLE
88 void dump(int nLevel) const;
89 #endif
92 typedef std::pair<OUString, OUString> NamePairType;
94 struct NamePairHash
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;
104 public:
106 ScDPResultTree();
107 ScDPResultTree(const ScDPResultTree&) = delete;
108 const ScDPResultTree& operator=(const ScDPResultTree&) = delete;
109 ~ScDPResultTree();
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);
121 bool empty() const;
122 void clear();
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
130 void dump() const;
131 #endif
134 struct ScDPResultFilterContext
136 ScDPResultTree maFilterSet;
137 std::vector<ScDPResultFilter> maFilters;
138 long mnCol;
139 long mnRow;
141 ScDPResultFilterContext();
144 #endif
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */