Bump version to 4.3-4
[LibreOffice.git] / sc / inc / dpcache.hxx
blob4647227a43e8df43fc940416709e4dbfc2165a5a
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SC_INC_DPCACHE_HXX
20 #define INCLUDED_SC_INC_DPCACHE_HXX
22 #include "global.hxx"
23 #include "dpnumgroupinfo.hxx"
24 #include "calcmacros.hxx"
25 #include <tools/date.hxx>
27 #include <boost/noncopyable.hpp>
28 #include <boost/scoped_ptr.hpp>
29 #include <boost/ptr_container/ptr_vector.hpp>
30 #include <boost/unordered_set.hpp>
31 #include <mdds/flat_segment_tree.hpp>
33 #include <vector>
34 #include <set>
36 struct ScQueryParam;
37 class ScDPObject;
38 class ScDPItemData;
39 struct ScDPNumGroupInfo;
41 /**
42 * This class represents the cached data part of the datapilot cache table
43 * implementation.
45 class SC_DLLPUBLIC ScDPCache : boost::noncopyable
47 typedef boost::unordered_set<OUString, OUStringHash> StringSetType;
49 public:
50 typedef std::vector<ScDPItemData> ItemsType;
51 typedef std::set<ScDPObject*> ObjectSetType;
52 typedef std::vector<OUString> LabelsType;
53 typedef std::vector<SCROW> IndexArrayType;
55 struct GroupItems : boost::noncopyable
57 ItemsType maItems;
58 ScDPNumGroupInfo maInfo;
59 sal_Int32 mnGroupType;
61 GroupItems();
62 GroupItems(const ScDPNumGroupInfo& rInfo, sal_Int32 nGroupType);
65 struct Field : boost::noncopyable
67 /**
68 * Optional items for grouped field.
70 boost::scoped_ptr<GroupItems> mpGroup;
72 /**
73 * Unique values in the field, stored in ascending order.
75 ItemsType maItems;
77 /**
78 * Original source data represented as indices to the unique value
79 * list. The order of the data is as they appear in the original
80 * data source.
82 IndexArrayType maData;
84 sal_uLong mnNumFormat;
86 Field();
89 /**
90 * Interface for connecting to database source. Column index is 0-based.
92 class DBConnector
94 public:
95 virtual long getColumnCount() const = 0;
96 virtual OUString getColumnLabel(long nCol) const = 0;
97 virtual bool first() = 0;
98 virtual bool next() = 0;
99 virtual void finish() = 0;
100 virtual void getValue(long nCol, ScDPItemData& rData, short& rNumType) const = 0;
101 virtual ~DBConnector() {}
104 private:
106 ScDocument* mpDoc;
107 long mnColumnCount;
110 * All pivot table objects that references this cache.
112 mutable ObjectSetType maRefObjects;
114 typedef boost::ptr_vector<Field> FieldsType;
115 typedef boost::ptr_vector<GroupItems> GroupFieldsType;
117 FieldsType maFields;
118 GroupFieldsType maGroupFields;
119 mutable StringSetType maStringPool;
121 LabelsType maLabelNames; // Stores dimension names.
122 mdds::flat_segment_tree<SCROW, bool> maEmptyRows;
123 SCROW mnDataSize;
124 SCROW mnRowCount;
126 bool mbDisposing;
128 public:
129 const OUString* InternString(const OUString& rStr) const;
130 void AddReference(ScDPObject* pObj) const;
131 void RemoveReference(ScDPObject* pObj) const;
132 const ObjectSetType& GetAllReferences() const;
134 SCROW GetIdByItemData(long nDim, const ScDPItemData& rItem) const;
135 OUString GetFormattedString(long nDim, const ScDPItemData& rItem) const;
136 long AppendGroupField();
137 void ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo, sal_Int32 nGroupType);
138 SCROW SetGroupItem(long nDim, const ScDPItemData& rData);
139 void GetGroupDimMemberIds(long nDim, std::vector<SCROW>& rIds) const;
140 void ClearGroupFields();
141 const ScDPNumGroupInfo* GetNumGroupInfo(long nDim) const;
144 * Return a group type identifier. The values correspond with
145 * com::sun::star::sheet::DataPilotFieldGroupBy constant values.
147 * @param nDim 0-based dimension index.
149 * @return group type identifier, or 0 on failure.
151 sal_Int32 GetGroupType(long nDim) const;
153 SCCOL GetDimensionIndex(const OUString& sName) const;
154 sal_uLong GetNumberFormat( long nDim ) const;
155 bool IsDateDimension( long nDim ) const ;
156 long GetDimMemberCount(long nDim) const;
157 SCROW GetOrder( long nDim, SCROW nIndex ) const;
159 const ItemsType& GetDimMemberValues( SCCOL nDim ) const;
160 bool InitFromDoc(ScDocument* pDoc, const ScRange& rRange);
161 bool InitFromDataBase(DBConnector& rDB);
163 SCROW GetRowCount() const;
164 SCROW GetDataSize() const;
165 SCROW GetItemDataId( sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty ) const;
166 OUString GetDimensionName(LabelsType::size_type nDim) const;
167 bool IsRowEmpty(SCROW nRow) const;
168 bool ValidQuery(SCROW nRow, const ScQueryParam& rQueryParam) const;
170 ScDocument* GetDoc() const;
171 long GetColumnCount() const;
173 const ScDPItemData* GetItemDataById( long nDim, SCROW nId ) const;
175 size_t GetFieldCount() const;
176 size_t GetGroupFieldCount() const;
178 ScDPCache(ScDocument* pDoc);
179 ~ScDPCache();
181 #if DEBUG_PIVOT_TABLE
182 void Dump() const;
183 #endif
185 private:
186 void PostInit();
187 void Clear();
188 void AddLabel(const OUString& rLabel);
189 const GroupItems* GetGroupItems(long nDim) const;
192 #endif
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */