LCOV - code coverage report
Current view: top level - sc/inc - dpcache.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 2 4 50.0 %
Date: 2014-11-03 Functions: 2 5 40.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : #ifndef INCLUDED_SC_INC_DPCACHE_HXX
      20             : #define INCLUDED_SC_INC_DPCACHE_HXX
      21             : 
      22             : #include "global.hxx"
      23             : #include "dpnumgroupinfo.hxx"
      24             : #include "calcmacros.hxx"
      25             : #include <tools/date.hxx>
      26             : 
      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>
      32             : 
      33             : #include <vector>
      34             : #include <set>
      35             : 
      36             : struct ScQueryParam;
      37             : class ScDPObject;
      38             : class ScDPItemData;
      39             : struct ScDPNumGroupInfo;
      40             : 
      41             : /**
      42             :  * This class represents the cached data part of the datapilot cache table
      43             :  * implementation.
      44             :  */
      45             : class SC_DLLPUBLIC ScDPCache : boost::noncopyable
      46             : {
      47             :     typedef boost::unordered_set<OUString, OUStringHash> StringSetType;
      48             : 
      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;
      54             : 
      55          36 :     struct GroupItems : boost::noncopyable
      56             :     {
      57             :         ItemsType maItems;
      58             :         ScDPNumGroupInfo maInfo;
      59             :         sal_Int32 mnGroupType;
      60             : 
      61             :         GroupItems();
      62             :         GroupItems(const ScDPNumGroupInfo& rInfo, sal_Int32 nGroupType);
      63             :     };
      64             : 
      65         410 :     struct Field : boost::noncopyable
      66             :     {
      67             :         /**
      68             :          * Optional items for grouped field.
      69             :          */
      70             :         boost::scoped_ptr<GroupItems> mpGroup;
      71             : 
      72             :         /**
      73             :          * Unique values in the field, stored in ascending order.
      74             :          */
      75             :         ItemsType maItems;
      76             : 
      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.
      81             :          */
      82             :         IndexArrayType maData;
      83             : 
      84             :         sal_uLong mnNumFormat;
      85             : 
      86             :         Field();
      87             :     };
      88             : 
      89             :     /**
      90             :      * Interface for connecting to database source.  Column index is 0-based.
      91             :      */
      92           0 :     class DBConnector
      93             :     {
      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           0 :         virtual ~DBConnector() {}
     102             :     };
     103             : 
     104             : private:
     105             : 
     106             :     ScDocument* mpDoc;
     107             :     long mnColumnCount;
     108             : 
     109             :     /**
     110             :      * All pivot table objects that references this cache.
     111             :      */
     112             :     mutable ObjectSetType maRefObjects;
     113             : 
     114             :     typedef boost::ptr_vector<Field> FieldsType;
     115             :     typedef boost::ptr_vector<GroupItems> GroupFieldsType;
     116             : 
     117             :     FieldsType maFields;
     118             :     GroupFieldsType maGroupFields;
     119             :     mutable StringSetType maStringPool;
     120             : 
     121             :     LabelsType maLabelNames; // Stores dimension names and the data layout dimension name at position 0.
     122             :     mdds::flat_segment_tree<SCROW, bool> maEmptyRows;
     123             :     SCROW mnDataSize;
     124             :     SCROW mnRowCount;
     125             : 
     126             :     bool mbDisposing;
     127             : 
     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;
     133             : 
     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;
     142             : 
     143             :     /**
     144             :      * Return a group type identifier.  The values correspond with
     145             :      * com::sun::star::sheet::DataPilotFieldGroupBy constant values.
     146             :      *
     147             :      * @param nDim 0-based dimension index.
     148             :      *
     149             :      * @return group type identifier, or 0 on failure.
     150             :      */
     151             :     sal_Int32 GetGroupType(long nDim) const;
     152             : 
     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;
     158             : 
     159             :     const IndexArrayType* GetFieldIndexArray( size_t nDim ) const;
     160             :     const ItemsType& GetDimMemberValues( SCCOL nDim ) const;
     161             :     bool InitFromDoc(ScDocument* pDoc, const ScRange& rRange);
     162             :     bool InitFromDataBase(DBConnector& rDB);
     163             : 
     164             :     /**
     165             :      * Row count is the number of records plus any trailing empty rows in case
     166             :      * the source data is sheet and contains trailing empty rows.
     167             :      */
     168             :     SCROW GetRowCount() const;
     169             : 
     170             :     /**
     171             :      * Data size is the number of records without any trailing empty rows for
     172             :      * sheet source data.  For any other source type, this should equal the
     173             :      * row count.
     174             :      */
     175             :     SCROW GetDataSize() const;
     176             :     SCROW GetItemDataId( sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty ) const;
     177             :     OUString GetDimensionName(LabelsType::size_type nDim) const;
     178             :     bool IsRowEmpty(SCROW nRow) const;
     179             :     bool ValidQuery(SCROW nRow, const ScQueryParam& rQueryParam) const;
     180             : 
     181             :     ScDocument* GetDoc() const;
     182             :     long GetColumnCount() const;
     183             : 
     184             :     const ScDPItemData* GetItemDataById( long nDim, SCROW nId ) const;
     185             : 
     186             :     size_t GetFieldCount() const;
     187             :     size_t GetGroupFieldCount() const;
     188             : 
     189             :     ScDPCache(ScDocument* pDoc);
     190             :     ~ScDPCache();
     191             : 
     192             : #if DEBUG_PIVOT_TABLE
     193             :     void Dump() const;
     194             : #endif
     195             : 
     196             : private:
     197             :     void PostInit();
     198             :     void Clear();
     199             :     void AddLabel(const OUString& rLabel);
     200             :     const GroupItems* GetGroupItems(long nDim) const;
     201             : };
     202             : 
     203             : #endif
     204             : 
     205             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10