xref: /aoo42x/main/sc/inc/dpgroup.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_DPGROUP_HXX
25 #define SC_DPGROUP_HXX
26 
27 #include <vector>
28 #include <hash_set>
29 #include <boost/shared_ptr.hpp>
30 
31 #include "dptabdat.hxx"
32 #include "scdllapi.h"
33 // Wang Xu Ming -- 2009-8-17
34 // DataPilot Migration - Cache&&Performance
35 #include "dpglobal.hxx"
36 // End Comments
37 class ScDocument;
38 class SvNumberFormatter;
39 
40 // --------------------------------------------------------------------
41 
42 //! API struct?
43 struct ScDPNumGroupInfo
44 {
45     sal_Bool Enable;
46     sal_Bool DateValues;
47     sal_Bool AutoStart;
48     sal_Bool AutoEnd;
49     double   Start;
50     double   End;
51     double   Step;
52 
ScDPNumGroupInfoScDPNumGroupInfo53     ScDPNumGroupInfo() : Enable(sal_False), DateValues(sal_False), AutoStart(sal_False), AutoEnd(sal_False),
54                          Start(0.0), End(0.0), Step(0.0) {}
55 };
56 
57 // --------------------------------------------------------------------
58 
59 //  ScDPDateGroupHelper is used as part of ScDPGroupDimension (additional dim.)
60 //  or ScDPNumGroupDimension (innermost, replaces the original dim.).
61 //  Source index, name and result collection are stored at the parent.
62 
63 class ScDPDateGroupHelper
64 {
65     ScDPNumGroupInfo    aNumInfo;       // only start and end (incl. auto flags) are used
66     sal_Int32           nDatePart;      // single part
67 
68 public:
69                 ScDPDateGroupHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
70                 ~ScDPDateGroupHelper();
71 
GetDatePart() const72     sal_Int32   GetDatePart() const { return nDatePart; }
GetNumInfo() const73     const ScDPNumGroupInfo& GetNumInfo() const { return aNumInfo; }
74 
75     // Wang Xu Ming -- 2009-9-8
76     // DataPilot Migration - Cache&&Performance
77     void        FillColumnEntries( SCCOL nSourceDim, ScDPTableDataCache* pCahe , std::vector< SCROW >& rEntries,
78         const std::vector< SCROW >& rOriginal  ) const;
79     // End Comments
80 };
81 
82 // --------------------------------------------------------------------
83 
84 typedef ::std::vector<ScDPItemData> ScDPItemDataVec;
85 
86 class ScDPGroupItem
87 {
88     ScDPItemData    aGroupName;     // name of group item
89     ScDPItemDataVec aElements;      // names of items in original dimension
90 
91 public:
92                 ScDPGroupItem( const ScDPItemData& rName );
93                 ~ScDPGroupItem();
94 
95     void        AddElement( const ScDPItemData& rName );
96 
GetName() const97     const ScDPItemData& GetName() const     { return aGroupName; }
98     bool        HasElement( const ScDPItemData& rData ) const;
99     bool        HasCommonElement( const ScDPGroupItem& rOther ) const;
100 
101     void        FillGroupFilter( ScDPCacheTable::GroupFilter& rFilter ) const;
102 };
103 
104 typedef ::std::vector<ScDPGroupItem> ScDPGroupItemVec;
105 
106 class ScDPGroupDimension
107 {
108     long                        nSourceDim;
109     long                        nGroupDim;
110     String                      aGroupName;
111     ScDPDateGroupHelper*        pDateHelper;
112     ScDPGroupItemVec            aItems;
113     // Wang Xu Ming -- 2009-9-4
114     // DataPilot Migration - Cache&&Performance
115    mutable  ::std::vector< SCROW >            maMemberEntries;
116     // End Comments
117 public:
118                 ScDPGroupDimension( long nSource, const String& rNewName );
119                 ScDPGroupDimension( const ScDPGroupDimension& rOther );
120                 ~ScDPGroupDimension();
121 
122 	ScDPGroupDimension&	operator=( const ScDPGroupDimension& rOther );
123 
124     void        AddItem( const ScDPGroupItem& rItem );
125     void        SetGroupDim( long nDim );           // called from AddGroupDimension
126 
GetSourceDim() const127     long        GetSourceDim() const    { return nSourceDim; }
GetGroupDim() const128     long        GetGroupDim() const     { return nGroupDim; }
GetName() const129     const      String& GetName() const       { return aGroupName; }
130 
131 // Wang Xu Ming -- 2009-9-2
132 // DataPilot Migration - Cache&&Performance
133     const std::vector< SCROW >&  GetColumnEntries( const ScDPCacheTable&  rCacheTable, const std::vector< SCROW >& rOriginal ) const;
134 // End Comments
135     const ScDPGroupItem* GetGroupForData( const ScDPItemData& rData ) const;  // rData = entry in original dim.
136     const ScDPGroupItem* GetGroupForName( const ScDPItemData& rName ) const;  // rName = entry in group dim.
137     const ScDPGroupItem* GetGroupByIndex( size_t nIndex ) const;
138 
GetDateHelper() const139     const ScDPDateGroupHelper* GetDateHelper() const    { return pDateHelper; }
140 
141     void        MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
142 
143     void        DisposeData();
144 
GetItemCount() const145     size_t      GetItemCount() const { return aItems.size(); }
146 };
147 
148 typedef ::std::vector<ScDPGroupDimension> ScDPGroupDimensionVec;
149 
150 // --------------------------------------------------------------------
151 
152 class SC_DLLPUBLIC ScDPNumGroupDimension
153 {
154     ScDPNumGroupInfo            aGroupInfo;         // settings
155     ScDPDateGroupHelper*        pDateHelper;
156 // Wang Xu Ming -- 2009-9-4
157 // DataPilot Migration - Cache&&Performance
158     mutable  ::std::vector< SCROW >            maMemberEntries;
159 // End Comments
160     mutable bool                bHasNonInteger;     // initialized in GetNumEntries
161     mutable sal_Unicode         cDecSeparator;      // initialized in GetNumEntries
162 
163 public:
164                 ScDPNumGroupDimension();
165                 ScDPNumGroupDimension( const ScDPNumGroupInfo& rInfo );
166                 ScDPNumGroupDimension( const ScDPNumGroupDimension& rOther );
167                 ~ScDPNumGroupDimension();
168 
169 	ScDPNumGroupDimension&	operator=( const ScDPNumGroupDimension& rOther );
170 
GetInfo() const171     const ScDPNumGroupInfo& GetInfo() const     { return aGroupInfo; }
HasNonInteger() const172     bool        HasNonInteger() const           { return bHasNonInteger; }
GetDecSeparator() const173     sal_Unicode GetDecSeparator() const         { return cDecSeparator; }
174 
GetDateHelper() const175     const ScDPDateGroupHelper* GetDateHelper() const    { return pDateHelper; }
176 
177     const std::vector< SCROW >& GetNumEntries( SCCOL nSourceDim, ScDPTableDataCache* pCache,
178                     const std::vector< SCROW >& rOriginal  ) const;
179 
180     void        MakeDateHelper( const ScDPNumGroupInfo& rInfo, sal_Int32 nPart );
181 
182     void        DisposeData();
183 };
184 
185 // --------------------------------------------------------------------
186 //
187 //  proxy implementation of ScDPTableData to add grouped items
188 //
189 
190 class ScDPGroupTableData : public ScDPTableData
191 {
192     typedef ::std::hash_set< ::rtl::OUString, ::rtl::OUStringHash, ::std::equal_to< ::rtl::OUString > > StringHashSet;
193 
194     ::boost::shared_ptr<ScDPTableData> pSourceData;
195     long                    nSourceCount;
196     ScDPGroupDimensionVec   aGroups;
197     ScDPNumGroupDimension*  pNumGroups;     // array[nSourceCount]
198     ScDocument*             pDoc;
199     StringHashSet           aGroupNames;
200 
201 // Wang Xu Ming -- 2009-8-17
202 // DataPilot Migration - Cache&&Performance
203     void       					 FillGroupValues( SCROW* pItemDataIndex, long nCount, const long* pDims );
204     virtual long 				GetSourceDim( long nDim );
205 // End Comments
206 
207     bool        IsNumGroupDimension( long nDimension ) const;
208     void        GetNumGroupInfo( long nDimension, ScDPNumGroupInfo& rInfo,
209                                     bool& rNonInteger, sal_Unicode& rDecimal );
210 
211     void        ModifyFilterCriteria(::std::vector<ScDPCacheTable::Criterion>& rCriteria);
212 
213 public:
214                 // takes ownership of pSource
215                 ScDPGroupTableData( const ::boost::shared_ptr<ScDPTableData>& pSource, ScDocument* pDocument );
216     virtual     ~ScDPGroupTableData();
217 
218     void        AddGroupDimension( const ScDPGroupDimension& rGroup );
219     void        SetNumGroupDimension( long nIndex, const ScDPNumGroupDimension& rGroup );
220     long        GetDimensionIndex( const String& rName );
221 
GetDocument()222     ScDocument* GetDocument()   { return pDoc; }
223 
224     virtual long                    GetColumnCount();
225 // Wang Xu Ming -- 2009-8-17
226 // DataPilot Migration - Cache&&Performance
227     virtual   long                            	            GetMembersCount( long nDim );
228     virtual    const std::vector< SCROW >& GetColumnEntries( long nColumn ) ;
229     virtual const ScDPItemData* GetMemberById( long nDim, long nId);
230     virtual long Compare( long nDim, long nDataId1, long nDataId2);
231 
232 // End Comments
233     virtual String                  getDimensionName(long nColumn);
234     virtual sal_Bool                    getIsDataLayoutDimension(long nColumn);
235     virtual sal_Bool                    IsDateDimension(long nDim);
236     virtual sal_uLong                  GetNumberFormat(long nDim);
237     virtual void                    DisposeData();
238     virtual void                    SetEmptyFlags( sal_Bool bIgnoreEmptyRows, sal_Bool bRepeatIfEmpty );
239 
240     virtual bool                    IsRepeatIfEmpty();
241 
242     virtual void                    CreateCacheTable();
243     virtual void                    FilterCacheTable(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria, const ::std::hash_set<sal_Int32>& rDataDims);
244     virtual void                    GetDrillDownData(const ::std::vector<ScDPCacheTable::Criterion>& rCriteria,
245                                                      const ::std::hash_set<sal_Int32>& rCatDims,
246                                                      ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& rData);
247     virtual void                    CalcResults(CalcInfo& rInfo, bool bAutoShow);
248     virtual const ScDPCacheTable&   GetCacheTable() const;
249 
250     virtual sal_Bool                    IsBaseForGroup(long nDim) const;
251     virtual long                    GetGroupBase(long nGroupDim) const;
252     virtual sal_Bool                    IsNumOrDateGroup(long nDim) const;
253     virtual sal_Bool                    IsInGroup( const ScDPItemData& rGroupData, long nGroupIndex,
254                                                const ScDPItemData& rBaseData, long nBaseIndex ) const;
255     virtual sal_Bool                    HasCommonElement( const ScDPItemData& rFirstData, long nFirstIndex,
256                                                       const ScDPItemData& rSecondData, long nSecondIndex ) const;
257 };
258 
259 
260 #endif
261 
262