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

Generated by: LCOV version 1.10