LCOV - code coverage report
Current view: top level - sc/inc - rangenam.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 14 15 93.3 %
Date: 2012-08-25 Functions: 13 14 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef SC_RANGENAM_HXX
      30                 :            : #define SC_RANGENAM_HXX
      31                 :            : 
      32                 :            : #include "global.hxx" // -> enum UpdateRefMode
      33                 :            : #include "address.hxx"
      34                 :            : #include "formula/grammar.hxx"
      35                 :            : #include "scdllapi.h"
      36                 :            : 
      37                 :            : #include <map>
      38                 :            : #include <vector>
      39                 :            : #include <boost/ptr_container/ptr_set.hpp>
      40                 :            : #include <boost/ptr_container/ptr_map.hpp>
      41                 :            : 
      42                 :            : //------------------------------------------------------------------------
      43                 :            : 
      44                 :            : class ScDocument;
      45                 :            : 
      46                 :            : namespace rtl {
      47                 :            :     class OUStringBuffer;
      48                 :            : }
      49                 :            : 
      50                 :            : 
      51                 :            : //------------------------------------------------------------------------
      52                 :            : 
      53                 :            : typedef sal_uInt16 RangeType;
      54                 :            : 
      55                 :            : #define RT_NAME             ((RangeType)0x0000)
      56                 :            : #define RT_DATABASE         ((RangeType)0x0001)
      57                 :            : #define RT_CRITERIA         ((RangeType)0x0002)
      58                 :            : #define RT_PRINTAREA        ((RangeType)0x0004)
      59                 :            : #define RT_COLHEADER        ((RangeType)0x0008)
      60                 :            : #define RT_ROWHEADER        ((RangeType)0x0010)
      61                 :            : #define RT_ABSAREA          ((RangeType)0x0020)
      62                 :            : #define RT_REFAREA          ((RangeType)0x0040)
      63                 :            : #define RT_ABSPOS           ((RangeType)0x0080)
      64                 :            : #define RT_SHARED           ((RangeType)0x0100)
      65                 :            : #define RT_SHAREDMOD        ((RangeType)0x0200)
      66                 :            : 
      67                 :            : //------------------------------------------------------------------------
      68                 :            : 
      69                 :            : class ScTokenArray;
      70                 :            : 
      71                 :            : class ScRangeData
      72                 :            : {
      73                 :            : private:
      74                 :            :     rtl::OUString   aName;
      75                 :            :     rtl::OUString   aUpperName;     // #i62977# for faster searching (aName is never modified after ctor)
      76                 :            :     ScTokenArray*   pCode;
      77                 :            :     ScAddress       aPos;
      78                 :            :     RangeType       eType;
      79                 :            :     ScDocument*     pDoc;
      80                 :            :     formula::FormulaGrammar::Grammar    eTempGrammar;   // needed for unresolved XML compiles
      81                 :            :     sal_uInt16      nIndex;
      82                 :            :     bool            bModified;          // is set/cleared by UpdateReference
      83                 :            : 
      84                 :            :     // max row and column to use for wrapping of references.  If -1 use the
      85                 :            :     // application's default.
      86                 :            :     SCROW           mnMaxRow;
      87                 :            :     SCCOL           mnMaxCol;
      88                 :            : 
      89                 :            :     void CompileRangeData( const String& rSymbol, bool bSetError );
      90                 :            : 
      91                 :            : public:
      92                 :            :     typedef ::std::map<sal_uInt16, sal_uInt16> IndexMap;
      93                 :            : 
      94                 :            :     SC_DLLPUBLIC                ScRangeData( ScDocument* pDoc,
      95                 :            :                                  const rtl::OUString& rName,
      96                 :            :                                  const String& rSymbol,
      97                 :            :                                  const ScAddress& rAdr = ScAddress(),
      98                 :            :                                  RangeType nType = RT_NAME,
      99                 :            :                                  const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
     100                 :            :     SC_DLLPUBLIC                ScRangeData( ScDocument* pDoc,
     101                 :            :                                  const rtl::OUString& rName,
     102                 :            :                                  const ScTokenArray& rArr,
     103                 :            :                                  const ScAddress& rAdr = ScAddress(),
     104                 :            :                                  RangeType nType = RT_NAME );
     105                 :            :     SC_DLLPUBLIC                ScRangeData( ScDocument* pDoc,
     106                 :            :                                  const rtl::OUString& rName,
     107                 :            :                                  const ScAddress& rTarget );
     108                 :            :                                 // rTarget is ABSPOS jump label
     109                 :            :                     ScRangeData(const ScRangeData& rScRangeData, ScDocument* pDocument = NULL);
     110                 :            : 
     111                 :            :     SC_DLLPUBLIC ~ScRangeData();
     112                 :            : 
     113                 :            :     bool            operator== (const ScRangeData& rData) const;
     114                 :            : 
     115                 :         33 :     void            GetName( rtl::OUString& rName ) const  { rName = aName; }
     116                 :        536 :     const rtl::OUString&   GetName( void ) const           { return aName; }
     117                 :        361 :     const rtl::OUString&   GetUpperName( void ) const      { return aUpperName; }
     118                 :         30 :     ScAddress       GetPos() const                  { return aPos; }
     119                 :            :     // The index has to be unique. If index=0 a new index value is assigned.
     120                 :        259 :     void            SetIndex( sal_uInt16 nInd )         { nIndex = nInd; }
     121                 :       1425 :     sal_uInt16    GetIndex() const                { return nIndex; }
     122                 :         58 :     ScTokenArray*   GetCode()                       { return pCode; }
     123                 :        218 :     const ScTokenArray* GetCode() const             { return pCode; }
     124                 :            :     SC_DLLPUBLIC sal_uInt16 GetErrCode() const;
     125                 :            :     bool            HasReferences() const;
     126                 :            :     void            SetDocument( ScDocument* pDocument){ pDoc = pDocument; }
     127                 :            :     ScDocument*     GetDocument() const             { return pDoc; }
     128                 :          3 :     void            SetType( RangeType nType )      { eType = nType; }
     129                 :          0 :     void            AddType( RangeType nType )      { eType = eType|nType; }
     130                 :         25 :     RangeType       GetType() const                 { return eType; }
     131                 :            :     bool            HasType( RangeType nType ) const;
     132                 :            :     sal_uInt32      GetUnoType() const;
     133                 :            :     SC_DLLPUBLIC void GetSymbol( String& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
     134                 :            :     SC_DLLPUBLIC void GetSymbol( rtl::OUString& rSymbol, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
     135                 :            :     SC_DLLPUBLIC void GetSymbol( rtl::OUString& rSymbol, const ScAddress& rPos, const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT ) const;
     136                 :            :     void            UpdateSymbol( rtl::OUStringBuffer& rBuffer, const ScAddress&,
     137                 :            :                                     const formula::FormulaGrammar::Grammar eGrammar = formula::FormulaGrammar::GRAM_DEFAULT );
     138                 :            :     void            UpdateReference( UpdateRefMode eUpdateRefMode,
     139                 :            :                              const ScRange& r,
     140                 :            :                              SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bLocal = false );
     141                 :         14 :     bool            IsModified() const              { return bModified; }
     142                 :            : 
     143                 :            :     SC_DLLPUBLIC void           GuessPosition();
     144                 :            : 
     145                 :            :     void            UpdateTranspose( const ScRange& rSource, const ScAddress& rDest );
     146                 :            :     void            UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY );
     147                 :            : 
     148                 :            :     SC_DLLPUBLIC bool           IsReference( ScRange& rRef ) const;
     149                 :            :     bool                        IsReference( ScRange& rRef, const ScAddress& rPos ) const;
     150                 :            :     SC_DLLPUBLIC bool           IsValidReference( ScRange& rRef ) const;
     151                 :            :     bool                        IsRangeAtBlock( const ScRange& ) const;
     152                 :            : 
     153                 :            :     void            UpdateTabRef(SCTAB nOldTable, sal_uInt16 nFlag, SCTAB nNewTable, SCTAB nNewSheets);
     154                 :            : 
     155                 :            :     void            ValidateTabRefs();
     156                 :            : 
     157                 :            :     static void     MakeValidName( String& rName );
     158                 :            :     SC_DLLPUBLIC static bool        IsNameValid( const String& rName, ScDocument* pDoc );
     159                 :            : 
     160                 :            :     SC_DLLPUBLIC void SetMaxRow(SCROW nRow);
     161                 :            :     SCROW GetMaxRow() const;
     162                 :            :     SC_DLLPUBLIC void SetMaxCol(SCCOL nCol);
     163                 :            :     SCCOL GetMaxCol() const;
     164                 :            : 
     165                 :            :     void            CompileUnresolvedXML();
     166                 :            : };
     167                 :            : 
     168                 :        512 : inline bool ScRangeData::HasType( RangeType nType ) const
     169                 :            : {
     170                 :        512 :     return ( ( eType & nType ) == nType );
     171                 :            : }
     172                 :            : 
     173                 :            : extern "C" int SAL_CALL ScRangeData_QsortNameCompare( const void*, const void* );
     174                 :            : 
     175                 :            : bool operator< (const ScRangeData& left, const ScRangeData& right);
     176                 :            : 
     177                 :        760 : class ScRangeName
     178                 :            : {
     179                 :            : private:
     180                 :            :     typedef std::vector<ScRangeData*> IndexDataType;
     181                 :            :     typedef ::boost::ptr_map<rtl::OUString, ScRangeData> DataType;
     182                 :            :     DataType maData;
     183                 :            :     IndexDataType maIndexToData;
     184                 :            : 
     185                 :            : public:
     186                 :            :     /// Map that manages stored ScRangeName instances.
     187                 :            :     typedef ::boost::ptr_map<SCTAB, ScRangeName>  TabNameMap;
     188                 :            :     /// Map that stores non-managed pointers to ScRangeName instances.
     189                 :            :     typedef ::std::map<SCTAB, const ScRangeName*> TabNameCopyMap;
     190                 :            : 
     191                 :            :     typedef DataType::const_iterator const_iterator;
     192                 :            :     typedef DataType::iterator iterator;
     193                 :            : 
     194                 :            :     ScRangeName();
     195                 :            :     SC_DLLPUBLIC ScRangeName(const ScRangeName& r);
     196                 :            : 
     197                 :            :     SC_DLLPUBLIC const ScRangeData* findByRange(const ScRange& rRange) const;
     198                 :            :     SC_DLLPUBLIC ScRangeData* findByUpperName(const rtl::OUString& rName);
     199                 :            :     SC_DLLPUBLIC const ScRangeData* findByUpperName(const rtl::OUString& rName) const;
     200                 :            :     SC_DLLPUBLIC ScRangeData* findByIndex(sal_uInt16 i) const;
     201                 :            :     void UpdateReference(UpdateRefMode eUpdateRefMode, const ScRange& rRange,
     202                 :            :                          SCsCOL nDx, SCsROW nDy, SCsTAB nDz, bool bLocal = false);
     203                 :            :     void UpdateTabRef(SCTAB nTable, sal_uInt16 nFlag, SCTAB nNewTable = 0, SCTAB nNewSheets = 1);
     204                 :            :     void UpdateTranspose(const ScRange& rSource, const ScAddress& rDest);
     205                 :            :     void UpdateGrow(const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY);
     206                 :            : 
     207                 :            :     /** Compile those names that couldn't be resolved during loading and
     208                 :            :         inserting because they may have referred a name that was inserted later.
     209                 :            :      */
     210                 :            :     void CompileUnresolvedXML();
     211                 :            : 
     212                 :            :     SC_DLLPUBLIC const_iterator begin() const;
     213                 :            :     SC_DLLPUBLIC const_iterator end() const;
     214                 :            :     SC_DLLPUBLIC iterator begin();
     215                 :            :     SC_DLLPUBLIC iterator end();
     216                 :            :     SC_DLLPUBLIC size_t size() const;
     217                 :            :     bool empty() const;
     218                 :            : 
     219                 :            :     /** Insert object into set.
     220                 :            :         @ATTENTION: The underlying ::boost::ptr_set_adapter::insert(p) takes
     221                 :            :         ownership of p and if it can't insert it deletes the object! So, if
     222                 :            :         this insert here returns false the object where p pointed to is gone!
     223                 :            :      */
     224                 :            :     SC_DLLPUBLIC bool insert(ScRangeData* p);
     225                 :            : 
     226                 :            :     void erase(const ScRangeData& r);
     227                 :            :     void erase(const rtl::OUString& rName);
     228                 :            : 
     229                 :            :     /**
     230                 :            :      * Erase by iterator position.  Note that this method doesn't check for
     231                 :            :      * iterator's validity.  The caller must make sure that the iterator is
     232                 :            :      * valid.
     233                 :            :      */
     234                 :            :     void erase(const iterator& itr);
     235                 :            :     void clear();
     236                 :            :     bool operator== (const ScRangeName& r) const;
     237                 :            : };
     238                 :            : 
     239                 :            : #endif
     240                 :            : 
     241                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10