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

Generated by: LCOV version 1.10