Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sc / inc / dpresfilter.hxx
blobbe84b8c83c2df6ab3adbc8ace7bdebc733ba7e1e
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>
20 namespace com { namespace sun { namespace star { namespace sheet {
21 struct DataPilotFieldFilter;
22 }}}}
24 struct ScDPResultFilter
26 OUString maDimName;
27 OUString maValue;
29 bool mbHasValue:1;
30 bool mbDataLayout:1;
32 ScDPResultFilter(const OUString& rDimName, bool bDataLayout);
35 /**
36 * This class maintains pivot table calculation result in a tree structure
37 * which represents the logical structure of pivot table result layout as
38 * presented in the sheet.
40 * <p>The root node has two child nodes if the pivot table consists of both
41 * column and row dimensions. The first child stores the result tree that is
42 * first filtered by row dimensions then by column dimensions. The second
43 * child stores the result tree that is filtered by column dimensions only
44 * (for column grand totals).</p>
46 * <p>If the pivot table layout only consists of either column or row
47 * dimensions, the root node only has one child node.</p>
49 class ScDPResultTree : boost::noncopyable
51 public:
52 typedef std::vector<double> ValuesType;
54 private:
56 struct MemberNode;
57 struct DimensionNode;
58 typedef std::map<OUString, MemberNode*> MembersType;
59 typedef std::map<OUString, DimensionNode*> DimensionsType;
61 struct DimensionNode : boost::noncopyable
63 const MemberNode* mpParent;
64 MembersType maChildMembers;
66 DimensionNode(const MemberNode* pParent);
67 ~DimensionNode();
69 #if DEBUG_PIVOT_TABLE
70 void dump(int nLevel) const;
71 #endif
74 struct MemberNode : boost::noncopyable
76 const DimensionNode* mpParent;
77 ValuesType maValues;
78 DimensionsType maChildDimensions;
80 MemberNode(const DimensionNode* pParent);
81 ~MemberNode();
83 #if DEBUG_PIVOT_TABLE
84 void dump(int nLevel) const;
85 #endif
88 OUString maPrimaryDimName;
89 MemberNode* mpRoot;
91 public:
93 ScDPResultTree();
94 ~ScDPResultTree();
96 /**
97 * Add a single value filter path. The filters are expected to be sorted
98 * by row dimension order then by column dimension order.
100 * @param rFilter set of filters.
101 * @param nCol column position relative to the top-left cell within the
102 * data field range.
103 * @param nRow row position relative to the top-left cell within the data
104 * field range.
105 * @param fVal result value, as displayed in the table output.
107 void add(const std::vector<ScDPResultFilter>& rFilter, long nCol, long nRow, double fVal);
109 void swap(ScDPResultTree& rOther);
111 bool empty() const;
112 void clear();
114 const ValuesType* getResults(
115 const com::sun::star::uno::Sequence<
116 com::sun::star::sheet::DataPilotFieldFilter>& rFilters) const;
118 #if DEBUG_PIVOT_TABLE
119 void dump() const;
120 #endif
123 struct ScDPResultFilterContext
125 ScDPResultTree maFilterSet;
126 std::vector<ScDPResultFilter> maFilters;
127 long mnCol;
128 long mnRow;
130 ScDPResultFilterContext();
133 #endif
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */