LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/inc - rangenam.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 14 15 93.3 %
Date: 2013-07-09 Functions: 13 14 92.9 %
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             : 
      20             : #ifndef SC_RANGENAM_HXX
      21             : #define SC_RANGENAM_HXX
      22             : 
      23             : #include "global.hxx" // -> enum UpdateRefMode
      24             : #include "address.hxx"
      25             : #include "formula/grammar.hxx"
      26             : #include "scdllapi.h"
      27             : 
      28             : #include <map>
      29             : #include <vector>
      30             : #include <boost/ptr_container/ptr_set.hpp>
      31             : #include <boost/ptr_container/ptr_map.hpp>
      32             : 
      33             : //------------------------------------------------------------------------
      34             : 
      35             : class ScDocument;
      36             : 
      37             : 
      38             : 
      39             : //------------------------------------------------------------------------
      40             : 
      41             : typedef sal_uInt16 RangeType;
      42             : 
      43             : #define RT_NAME             ((RangeType)0x0000)
      44             : #define RT_DATABASE         ((RangeType)0x0001)
      45             : #define RT_CRITERIA         ((RangeType)0x0002)
      46             : #define RT_PRINTAREA        ((RangeType)0x0004)
      47             : #define RT_COLHEADER        ((RangeType)0x0008)
      48             : #define RT_ROWHEADER        ((RangeType)0x0010)
      49             : #define RT_ABSAREA          ((RangeType)0x0020)
      50             : #define RT_REFAREA          ((RangeType)0x0040)
      51             : #define RT_ABSPOS           ((RangeType)0x0080)
      52             : #define RT_SHARED           ((RangeType)0x0100)
      53             : #define RT_SHAREDMOD        ((RangeType)0x0200)
      54             : 
      55             : //------------------------------------------------------------------------
      56             : 
      57             : class ScTokenArray;
      58             : 
      59             : class ScRangeData
      60             : {
      61             : private:
      62             :     OUString   aName;
      63             :     OUString   aUpperName;     // #i62977# for faster searching (aName is never modified after ctor)
      64             :     ScTokenArray*   pCode;
      65             :     ScAddress       aPos;
      66             :     RangeType       eType;
      67             :     ScDocument*     pDoc;
      68             :     formula::FormulaGrammar::Grammar    eTempGrammar;   // needed for unresolved XML compiles
      69             :     sal_uInt16      nIndex;
      70             :     bool            bModified;          // is set/cleared by UpdateReference
      71             : 
      72             :     // max row and column to use for wrapping of references.  If -1 use the
      73             :     // application's default.
      74             :     SCROW           mnMaxRow;
      75             :     SCCOL           mnMaxCol;
      76             : 
      77             :     void CompileRangeData( const String& rSymbol, bool bSetError );
      78             :     void InitCode();
      79             : public:
      80             :     typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
      81             : 
      82             :     SC_DLLPUBLIC                ScRangeData( ScDocument* pDoc,
      83             :                                  const OUString& rName,
      84             :                                  const String& rSymbol,
      85             :                                  const ScAddress& rAdr = ScAddress(),
      86             :                                  RangeType nType = RT_NAME,
      87             :                                  const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
      88             :     SC_DLLPUBLIC                ScRangeData( ScDocument* pDoc,
      89             :                                  const OUString& rName,
      90             :                                  const ScTokenArray& rArr,
      91             :                                  const ScAddress& rAdr = ScAddress(),
      92             :                                  RangeType nType = RT_NAME );
      93             :     SC_DLLPUBLIC                ScRangeData( ScDocument* pDoc,
      94             :                                  const OUString& rName,
      95             :                                  const ScAddress& rTarget );
      96             :                                 // rTarget is ABSPOS jump label
      97             :                     ScRangeData(const ScRangeData& rScRangeData, ScDocument* pDocument = NULL);
      98             : 
      99             :     SC_DLLPUBLIC ~ScRangeData();
     100             : 
     101             :     bool            operator== (const ScRangeData& rData) const;
     102             : 
     103          18 :     void            GetName( OUString& rName ) const  { rName = aName; }
     104         396 :     const OUString&   GetName( void ) const           { return aName; }
     105         243 :     const OUString&   GetUpperName( void ) const      { return aUpperName; }
     106          16 :     ScAddress       GetPos() const                  { return aPos; }
     107             :     // The index has to be unique. If index=0 a new index value is assigned.
     108         194 :     void            SetIndex( sal_uInt16 nInd )         { nIndex = nInd; }
     109         891 :     sal_uInt16    GetIndex() const                { return nIndex; }
     110          20 :     ScTokenArray*   GetCode()                       { return pCode; }
     111             :     SC_DLLPUBLIC void   SetCode( ScTokenArray& );
     112         182 :     const ScTokenArray* GetCode() const             { return pCode; }
     113             :     SC_DLLPUBLIC sal_uInt16 GetErrCode() const;
     114             :     bool            HasReferences() const;
     115             :     void            SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
     116             :     ScDocument*     GetDocument() const             { return pDoc; }
     117           1 :     void            SetType( RangeType nType )      { eType = nType; }
     118           0 :     void            AddType( RangeType nType )      { eType = eType|nType; }
     119          11 :     RangeType       GetType() const                 { return eType; }
     120             :     bool            HasType( RangeType nType ) const;
     121             :     sal_uInt32      GetUnoType() const;
     122             :     SC_DLLPUBLIC void GetSymbol( String& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
     123             :     SC_DLLPUBLIC void GetSymbol( OUString& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
     124             :     SC_DLLPUBLIC void GetSymbol( OUString& rSymbol, const ScAddress& rPos, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
     125             :     void            UpdateSymbol( OUStringBuffer& rBuffer, const ScAddress&,
     126             :                                     const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
     127             :     void            UpdateReference( UpdateRefMode eUpdateRefMode,
     128             :                              const ScRange& r,
     129             :                              SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bLocal = false );
     130           6 :     bool            IsModified() const              { return bModified; }
     131             : 
     132             :     SC_DLLPUBLIC void           GuessPosition();
     133             : 
     134             :     void            UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
     135             :     void            UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
     136             : 
     137             :     SC_DLLPUBLIC bool           IsReference( ScRange& rRef ) const;
     138             :     bool                        IsReference( ScRange& rRef, const ScAddress& rPos ) const;
     139             :     SC_DLLPUBLIC bool           IsValidReference( ScRange& rRef ) const;
     140             :     bool                        IsRangeAtBlock( const ScRange& ) const;
     141             : 
     142             :     void            UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets);
     143             : 
     144             :     void            ValidateTabRefs();
     145             : 
     146             :     static void     MakeValidName( String& rName );
     147             :     SC_DLLPUBLIC static bool        IsNameValid( const String& rName, ScDocument* pDoc );
     148             : 
     149             :     SC_DLLPUBLIC void SetMaxRow(SCROW nRow);
     150             :     SCROW GetMaxRow() const;
     151             :     SC_DLLPUBLIC void SetMaxCol(SCCOL nCol);
     152             :     SCCOL GetMaxCol() const;
     153             : 
     154             :     void            CompileUnresolvedXML();
     155             : };
     156             : 
     157         668 : inline bool ScRangeData::HasType( RangeType nType ) const
     158             : {
     159         668 :     return ( ( eType & nType ) == nType );
     160             : }
     161             : 
     162             : extern "C" int SAL_CALL ScRangeData_QsortNameCompare( const void*, const void* );
     163             : 
     164             : bool operator< (const ScRangeData& left, const ScRangeData& right);
     165             : 
     166         731 : class ScRangeName
     167             : {
     168             : private:
     169             :     typedef std::vector<ScRangeData*> IndexDataType;
     170             :     typedef ::boost::ptr_map<OUString, ScRangeData> DataType;
     171             :     DataType maData;
     172             :     IndexDataType maIndexToData;
     173             : 
     174             : public:
     175             :     /// Map that manages stored ScRangeName instances.
     176             :     typedef ::boost::ptr_map<SCTAB, ScRangeName>  TabNameMap;
     177             :     /// Map that stores non-managed pointers to ScRangeName instances.
     178             :     typedef ::std::map<SCTAB, const ScRangeName*> TabNameCopyMap;
     179             : 
     180             :     typedef DataType::const_iterator const_iterator;
     181             :     typedef DataType::iterator iterator;
     182             : 
     183             :     ScRangeName();
     184             :     SC_DLLPUBLIC ScRangeName(const ScRangeName& r);
     185             : 
     186             :     SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const;
     187             :     SC_DLLPUBLIC ScRangeData* findByUpperName(const OUString& rName);
     188             :     SC_DLLPUBLIC const ScRangeData* findByUpperName(const OUString& rName) const;
     189             :     SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const;
     190             :     void UpdateReference(UpdateRefMode eUpdateRefMode, const ScRange& rRange,
     191             :                          SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bLocal = false);
     192             :     void UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0, SCTAB nNewSheets = 1);
     193             :     void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
     194             :     void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
     195             : 
     196             :     /** Compile those names that couldn't be resolved during loading and
     197             :         inserting because they may have referred a name that was inserted later.
     198             :      */
     199             :     void CompileUnresolvedXML();
     200             : 
     201             :     SC_DLLPUBLIC const_iterator begin() const;
     202             :     SC_DLLPUBLIC const_iterator end() const;
     203             :     SC_DLLPUBLIC iterator begin();
     204             :     SC_DLLPUBLIC iterator end();
     205             :     SC_DLLPUBLIC size_t size() const;
     206             :     bool empty() const;
     207             : 
     208             :     /** Insert object into set.
     209             :         @ATTENTION: The underlying ::boost::ptr_set_adapter::insert(p) takes
     210             :         ownership of p and if it can't insert it deletes the object! So, if
     211             :         this insert here returns false the object where p pointed to is gone!
     212             :      */
     213             :     SC_DLLPUBLIC bool insert(ScRangeData* p);
     214             : 
     215             :     void erase(const ScRangeData& r);
     216             :     void erase(const OUString& rName);
     217             : 
     218             :     /**
     219             :      * Erase by iterator position.  Note that this method doesn't check for
     220             :      * iterator's validity.  The caller must make sure that the iterator is
     221             :      * valid.
     222             :      */
     223             :     void erase(const iterator& itr);
     224             :     void clear();
     225             :     bool operator== (const ScRangeName& r) const;
     226             : };
     227             : 
     228             : #endif
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10