Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / dpresfilter.hxx
blobbc7ffc1f62b3023e0a166e7e1c19f4a50742e987
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 __SC_DPRESFILTER_HXX__
11 #define __SC_DPRESFILTER_HXX__
13 #include "dpitemdata.hxx"
15 #include <map>
16 #include <vector>
17 #include <boost/noncopyable.hpp>
18 #include <boost/unordered_map.hpp>
21 namespace com { namespace sun { namespace star { namespace sheet {
22 struct DataPilotFieldFilter;
23 }}}}
25 struct ScDPResultFilter
27 OUString maDimName;
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 : boost::noncopyable
52 public:
53 typedef std::vector<double> ValuesType;
55 private:
57 struct MemberNode;
58 struct DimensionNode;
59 typedef std::map<OUString, MemberNode*> MembersType;
60 typedef std::map<OUString, DimensionNode*> DimensionsType;
62 struct DimensionNode : boost::noncopyable
64 const MemberNode* mpParent;
65 MembersType maChildMembers;
67 DimensionNode(const MemberNode* pParent);
68 ~DimensionNode();
70 #if DEBUG_PIVOT_TABLE
71 void dump(int nLevel) const;
72 #endif
75 struct MemberNode : boost::noncopyable
77 const DimensionNode* mpParent;
78 ValuesType maValues;
79 DimensionsType maChildDimensions;
81 MemberNode(const DimensionNode* pParent);
82 ~MemberNode();
84 #if DEBUG_PIVOT_TABLE
85 void dump(int nLevel) const;
86 #endif
89 typedef std::pair<OUString, OUString> NamePairType;
91 struct NamePairHash
93 size_t operator() (const NamePairType& rPair) const;
95 typedef boost::unordered_map<NamePairType, double, NamePairHash> LeafValuesType;
96 LeafValuesType maLeafValues;
98 OUString maPrimaryDimName;
99 MemberNode* mpRoot;
101 public:
103 ScDPResultTree();
104 ~ScDPResultTree();
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 nCol column position relative to the top-left cell within the
112 * data field range.
113 * @param nRow row position relative to the top-left cell within the data
114 * field range.
115 * @param fVal result value, as displayed in the table output.
117 void add(const std::vector<ScDPResultFilter>& rFilter, long nCol, long nRow, double fVal);
119 void swap(ScDPResultTree& rOther);
121 bool empty() const;
122 void clear();
124 const ValuesType* getResults(
125 const com::sun::star::uno::Sequence<
126 com::sun::star::sheet::DataPilotFieldFilter>& rFilters) const;
128 double getLeafResult(const com::sun::star::sheet::DataPilotFieldFilter& rFilter) const;
130 #if DEBUG_PIVOT_TABLE
131 void dump() const;
132 #endif
135 struct ScDPResultFilterContext
137 ScDPResultTree maFilterSet;
138 std::vector<ScDPResultFilter> maFilters;
139 long mnCol;
140 long mnRow;
142 ScDPResultFilterContext();
145 #endif
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */