LCOV - code coverage report
Current view: top level - sc/inc - sharedformula.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 17 17 100.0 %
Date: 2015-06-13 12:38:46 Functions: 1 1 100.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             : 
      10             : #ifndef INCLUDED_SC_INC_SHAREDFORMULA_HXX
      11             : #define INCLUDED_SC_INC_SHAREDFORMULA_HXX
      12             : 
      13             : #include "formulacell.hxx"
      14             : #include "mtvelements.hxx"
      15             : 
      16             : #include <vector>
      17             : 
      18             : #define USE_FORMULA_GROUP_LISTENER 1
      19             : 
      20             : namespace sc {
      21             : 
      22             : class StartListeningContext;
      23             : 
      24             : class SharedFormulaUtil
      25             : {
      26             : public:
      27             : 
      28             :     /**
      29             :      * Group formula cells stored in the passed container. The formula cells
      30             :      * in the container are assumed to be all <b>non-shared</b>.
      31             :      */
      32             :     template<typename _Iter>
      33          23 :     static void groupFormulaCells(const _Iter& itBeg, const _Iter& itEnd)
      34             :     {
      35          23 :         _Iter it = itBeg;
      36          23 :         ScFormulaCell* pPrev = *it;
      37          23 :         ScFormulaCell* pCur = NULL;
      38          42 :         for (++it; it != itEnd; ++it, pPrev = pCur)
      39             :         {
      40          17 :             pCur = *it;
      41          17 :             ScFormulaCell::CompareState eState = pCur->CompareByTokenArray(*pPrev);
      42          17 :             if (eState == ScFormulaCell::NotEqual)
      43          28 :                 continue;
      44             : 
      45           4 :             ScFormulaCellGroupRef xGroup = pPrev->GetCellGroup();
      46           4 :             if (xGroup)
      47             :             {
      48             :                 // Extend the group.
      49           2 :                 ++xGroup->mnLength;
      50           2 :                 pCur->SetCellGroup(xGroup);
      51           2 :                 continue;
      52             :             }
      53             : 
      54             :             // Create a new group.
      55           2 :             xGroup = pPrev->CreateCellGroup(2, eState == ScFormulaCell::EqualInvariant);
      56           2 :             pCur->SetCellGroup(xGroup);
      57             :         }
      58          23 :     }
      59             : 
      60             :     /**
      61             :      * Split existing shared formula range at specified position. The cell at
      62             :      * specified position becomes the top cell of the lower shared formula
      63             :      * range after this call.  This method does nothing if the cell at
      64             :      * specified position is not a formula cell.
      65             :      *
      66             :      * @param aPos position of cell to examine.
      67             :      */
      68             :     static void splitFormulaCellGroup(const CellStoreType::position_type& aPos);
      69             : 
      70             :     /**
      71             :      * Split existing shared formula ranges at specified row positions.
      72             :      *
      73             :      * @param rCells cell storage container
      74             :      * @param rBounds row positions at which to split existing shared formula
      75             :      *                ranges. Note that this method will directly modify this
      76             :      *                parameter to sort and remove duplicates.
      77             :      */
      78             :     static void splitFormulaCellGroups(CellStoreType& rCells, std::vector<SCROW>& rBounds);
      79             : 
      80             :     /**
      81             :      * See if two specified adjacent formula cells can be merged, and if they
      82             :      * can, merge them into the same group.
      83             :      *
      84             :      * @param rPos position object of the first cell
      85             :      * @param rCell1 first cell
      86             :      * @param rCell2 second cell located immediately below the first cell.
      87             :      *
      88             :      * @return true if the cells are merged, false otherwise.  If the two
      89             :      *         cells already belong to the same group, it returns false.
      90             :      */
      91             :     static bool joinFormulaCells(
      92             :         const CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2 );
      93             :     /**
      94             :      * Merge with an existing formula group (if any) located immediately above
      95             :      * if the cell at specified position is a formula cell, and its formula
      96             :      * tokens are identical to that of the above formula group.
      97             :      *
      98             :      * @param aPos position of cell to examine.
      99             :      *
     100             :      * @return true if the cells are merged, false otherwise.  If the two
     101             :      *         cells already belong to the same group, it returns false.
     102             :      */
     103             :     static bool joinFormulaCellAbove( const CellStoreType::position_type& aPos );
     104             : 
     105             :     /**
     106             :      * Turn a shared formula cell into a non-shared one, and split it off from
     107             :      * the adjacent formula cell groups.
     108             :      *
     109             :      * @param aPos position of cell to examine
     110             :      * @param rCell formula cell instance
     111             :      */
     112             :     static void unshareFormulaCell(const CellStoreType::position_type& aPos, ScFormulaCell& rCell);
     113             : 
     114             :     /**
     115             :      * Make specified formula cells non-shared ones, and split them off from
     116             :      * their respective adjacent formula cell groups.
     117             :      *
     118             :      * @param rCells cell storage container
     119             :      * @param rRows row positions at which to unshare formula cells.
     120             :      */
     121             :     static void unshareFormulaCells(CellStoreType& rCells, std::vector<SCROW>& rRows);
     122             : 
     123             :     /**
     124             :      * Have all formula cells belonging to a group start listening to their
     125             :      * references.
     126             :      *
     127             :      * @param rCxt context object.
     128             :      * @param ppSharedTop memory position of the pointer of the topmost
     129             :      *                    formula cell instance in the cell storage.  The
     130             :      *                    caller is responsible for ensuring that it is indeed
     131             :      *                    the topmost cell of a shared formula group.
     132             :      */
     133             :     static void startListeningAsGroup( StartListeningContext& rCxt, ScFormulaCell** ppSharedTop );
     134             : };
     135             : 
     136             : }
     137             : 
     138             : #endif
     139             : 
     140             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11