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 __SC_DPRESFILTER_HXX__
11 #define __SC_DPRESFILTER_HXX__
13 #include "dpitemdata.hxx"
17 #include <boost/noncopyable.hpp>
18 #include <boost/unordered_map.hpp>
21 namespace com
{ namespace sun
{ namespace star
{ namespace sheet
{
22 struct DataPilotFieldFilter
;
25 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>
50 class ScDPResultTree
: boost::noncopyable
53 typedef std::vector
<double> ValuesType
;
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
);
71 void dump(int nLevel
) const;
75 struct MemberNode
: boost::noncopyable
77 const DimensionNode
* mpParent
;
79 DimensionsType maChildDimensions
;
81 MemberNode(const DimensionNode
* pParent
);
85 void dump(int nLevel
) const;
89 typedef std::pair
<OUString
, OUString
> NamePairType
;
93 size_t operator() (const NamePairType
& rPair
) const;
95 typedef boost::unordered_map
<NamePairType
, double, NamePairHash
> LeafValuesType
;
96 LeafValuesType maLeafValues
;
98 OUString maPrimaryDimName
;
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
113 * @param nRow row position relative to the top-left cell within the data
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
);
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
135 struct ScDPResultFilterContext
137 ScDPResultTree maFilterSet
;
138 std::vector
<ScDPResultFilter
> maFilters
;
142 ScDPResultFilterContext();
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */