Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright IBM Corporation 2009.
7 : : * Copyright 2009 by Sun Microsystems, Inc.
8 : : *
9 : : * OpenOffice.org - a multi-platform office productivity suite
10 : : *
11 : : * This file is part of OpenOffice.org.
12 : : *
13 : : * OpenOffice.org is free software: you can redistribute it and/or modify
14 : : * it under the terms of the GNU Lesser General Public License version 3
15 : : * only, as published by the Free Software Foundation.
16 : : *
17 : : * OpenOffice.org is distributed in the hope that it will be useful,
18 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 : : * GNU Lesser General Public License version 3 for more details
21 : : * (a copy is included in the LICENSE file that accompanied this code).
22 : : *
23 : : * You should have received a copy of the GNU Lesser General Public License
24 : : * version 3 along with OpenOffice.org. If not, see
25 : : * <http://www.openoffice.org/license.html>
26 : : * for a copy of the LGPLv3 License.
27 : : *
28 : : ************************************************************************/
29 : : #ifndef SC_DPTABLECACHE_HXX
30 : : #define SC_DPTABLECACHE_HXX
31 : :
32 : : #include "global.hxx"
33 : : #include "dpnumgroupinfo.hxx"
34 : : #include "dpmacros.hxx"
35 : : #include "tools/date.hxx"
36 : :
37 : : #include <boost/noncopyable.hpp>
38 : : #include <boost/scoped_ptr.hpp>
39 : : #include <boost/ptr_container/ptr_vector.hpp>
40 : : #include <boost/unordered_set.hpp>
41 : : #include <mdds/flat_segment_tree.hpp>
42 : :
43 : : #include <vector>
44 : : #include <set>
45 : :
46 : : struct ScQueryParam;
47 : : class ScDPObject;
48 : : class ScDPItemData;
49 : : struct ScDPNumGroupInfo;
50 : :
51 : : /**
52 : : * This class represents the cached data part of the datapilot cache table
53 : : * implementation.
54 : : */
55 : : class SC_DLLPUBLIC ScDPCache : boost::noncopyable
56 : : {
57 : : typedef boost::unordered_set<rtl::OUString, rtl::OUStringHash> StringSetType;
58 : :
59 : : public:
60 : : typedef std::vector<ScDPItemData> ItemsType;
61 : : typedef std::set<ScDPObject*> ObjectSetType;
62 : : typedef std::vector<rtl::OUString> LabelsType;
63 : : typedef std::vector<SCROW> IndexArrayType;
64 : :
65 : 23 : struct GroupItems : boost::noncopyable
66 : : {
67 : : ItemsType maItems;
68 : : ScDPNumGroupInfo maInfo;
69 : : sal_Int32 mnGroupType;
70 : :
71 : : GroupItems();
72 : : GroupItems(const ScDPNumGroupInfo& rInfo, sal_Int32 nGroupType);
73 : : };
74 : :
75 [ + - ]: 309 : struct Field : boost::noncopyable
76 : : {
77 : : /**
78 : : * Optional items for grouped field.
79 : : */
80 : : boost::scoped_ptr<GroupItems> mpGroup;
81 : :
82 : : /**
83 : : * Unique values in the field, stored in ascending order.
84 : : */
85 : : ItemsType maItems;
86 : :
87 : : /**
88 : : * Original source data represented as indices to the unique value
89 : : * list. The order of the data is as they appear in the original
90 : : * data source.
91 : : */
92 : : IndexArrayType maData;
93 : :
94 : : sal_uLong mnNumFormat;
95 : :
96 : : Field();
97 : : };
98 : :
99 : : /**
100 : : * Interface for connecting to database source. Column index is 0-based.
101 : : */
102 : 0 : class DBConnector
103 : : {
104 : : public:
105 : : virtual long getColumnCount() const = 0;
106 : : virtual rtl::OUString getColumnLabel(long nCol) const = 0;
107 : : virtual bool first() = 0;
108 : : virtual bool next() = 0;
109 : : virtual void finish() = 0;
110 : : virtual void getValue(long nCol, ScDPItemData& rData, short& rNumType) const = 0;
111 [ # # ]: 0 : virtual ~DBConnector() { };
112 : : };
113 : :
114 : : private:
115 : :
116 : : ScDocument* mpDoc;
117 : : long mnColumnCount;
118 : :
119 : : /**
120 : : * All pivot table objects that references this cache.
121 : : */
122 : : mutable ObjectSetType maRefObjects;
123 : :
124 : : typedef boost::ptr_vector<Field> FieldsType;
125 : : typedef boost::ptr_vector<GroupItems> GroupFieldsType;
126 : :
127 : : FieldsType maFields;
128 : : GroupFieldsType maGroupFields;
129 : : mutable StringSetType maStringPool;
130 : :
131 : : LabelsType maLabelNames; // Stores dimension names.
132 : : mdds::flat_segment_tree<SCROW, bool> maEmptyRows;
133 : :
134 : : bool mbDisposing;
135 : :
136 : : public:
137 : : const rtl::OUString* InternString(const rtl::OUString& rStr) const;
138 : : void AddReference(ScDPObject* pObj) const;
139 : : void RemoveReference(ScDPObject* pObj) const;
140 : : const ObjectSetType& GetAllReferences() const;
141 : :
142 : : SCROW GetIdByItemData(long nDim, const ScDPItemData& rItem) const;
143 : : rtl::OUString GetFormattedString(long nDim, const ScDPItemData& rItem) const;
144 : : long AppendGroupField();
145 : : void ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType);
146 : : SCROW SetGroupItem(long nDim, const ScDPItemData& rData);
147 : : void GetGroupDimMemberIds(long nDim, std::vector<SCROW>& rIds) const;
148 : : void ClearGroupFields();
149 : : const ScDPNumGroupInfo* GetNumGroupInfo(long nDim) const;
150 : : sal_Int32 GetGroupType(long nDim) const;
151 : :
152 : : SCCOL GetDimensionIndex(const rtl::OUString& sName) const;
153 : : sal_uLong GetNumberFormat( long nDim ) const;
154 : : bool IsDateDimension( long nDim ) const ;
155 : : long GetDimMemberCount(long nDim) const;
156 : : SCROW GetOrder( long nDim, SCROW nIndex ) const;
157 : :
158 : : const ItemsType& GetDimMemberValues( SCCOL nDim ) const;
159 : : bool InitFromDoc(ScDocument* pDoc, const ScRange& rRange);
160 : : bool InitFromDataBase(DBConnector& rDB);
161 : :
162 : : SCROW GetRowCount() const;
163 : : SCROW GetItemDataId( sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty ) const;
164 : : rtl::OUString GetDimensionName(LabelsType::size_type nDim) const;
165 : : bool IsRowEmpty(SCROW nRow) const;
166 : : bool ValidQuery(SCROW nRow, const ScQueryParam& rQueryParam) const;
167 : :
168 : : ScDocument* GetDoc() const;
169 : : long GetColumnCount() const;
170 : :
171 : : const ScDPItemData* GetItemDataById( long nDim, SCROW nId ) const;
172 : :
173 : : ScDPCache(ScDocument* pDoc);
174 : : ~ScDPCache();
175 : :
176 : : #if DEBUG_PIVOT_TABLE
177 : : void Dump() const;
178 : : #endif
179 : :
180 : : private:
181 : : void PostInit();
182 : : void Clear();
183 : : void AddLabel(const rtl::OUString& rLabel);
184 : : const GroupItems* GetGroupItems(long nDim) const;
185 : : };
186 : :
187 : : #endif
188 : :
189 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|