LCOV - code coverage report
Current view: top level - sc/source/filter/inc - namebuff.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 24 42 57.1 %
Date: 2015-06-13 12:38:46 Functions: 13 22 59.1 %
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 INCLUDED_SC_SOURCE_FILTER_INC_NAMEBUFF_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_NAMEBUFF_HXX
      22             : 
      23             : #include <rtl/ustring.hxx>
      24             : #include <osl/diagnose.h>
      25             : #include "compiler.hxx"
      26             : #include "root.hxx"
      27             : #include "xiroot.hxx"
      28             : 
      29             : #include "rangenam.hxx"
      30             : #include "formulacell.hxx"
      31             : 
      32             : #include <list>
      33             : #include <unordered_map>
      34             : 
      35             : class ScTokenArray;
      36             : class NameBuffer;
      37             : 
      38         129 : class StringHashEntry
      39             : {
      40             : private:
      41             :     friend class NameBuffer;
      42             :     OUString          aString;
      43             :     sal_uInt32        nHash;
      44             : 
      45             :     static sal_uInt32   MakeHashCode( const OUString& );
      46             : public:
      47             :     inline          StringHashEntry( const OUString& );
      48             :     inline          StringHashEntry();
      49             :     inline void     operator =( const sal_Char* );
      50             :     inline void     operator =( const OUString& );
      51             :     inline void     operator =( const StringHashEntry& );
      52             :     inline bool     operator ==( const StringHashEntry& ) const;
      53             : };
      54             : 
      55             : inline StringHashEntry::StringHashEntry()
      56             : {
      57             : }
      58             : 
      59         129 : inline StringHashEntry::StringHashEntry( const OUString& r ) : aString( r )
      60             : {
      61         129 :     nHash = MakeHashCode( r );
      62         129 : }
      63             : 
      64             : inline void StringHashEntry::operator =( const sal_Char* p )
      65             : {
      66             :     aString = OUString(p, strlen(p), RTL_TEXTENCODING_ASCII_US);
      67             :     nHash = MakeHashCode( aString );
      68             : }
      69             : 
      70             : inline void StringHashEntry::operator =( const OUString& r )
      71             : {
      72             :     aString = r;
      73             :     nHash = MakeHashCode( r );
      74             : }
      75             : 
      76             : inline void StringHashEntry::operator =( const StringHashEntry& r )
      77             : {
      78             :     nHash = r.nHash;
      79             :     aString = r.aString;
      80             : }
      81             : 
      82           0 : inline bool StringHashEntry::operator ==( const StringHashEntry& r ) const
      83             : {
      84           0 :     return ( nHash == r.nHash && aString ==  r.aString );
      85             : }
      86             : 
      87             : class NameBuffer : public ExcRoot
      88             : {
      89             : private:
      90             :     sal_uInt16                  nBase;      // Index-Base
      91             :     std::vector<StringHashEntry*> maHashes;
      92             : 
      93             : public:
      94             : 
      95             :     inline                  NameBuffer( RootData* );
      96             :     inline                  NameBuffer( RootData*, sal_uInt16 nNewBase );
      97             : 
      98             :     virtual                 ~NameBuffer();
      99             :     inline const OUString*  Get( sal_uInt16 nIndex ) const;
     100             :     inline sal_uInt16       GetLastIndex() const;
     101             :     inline void             SetBase( sal_uInt16 nNewBase = 0 );
     102             :     void                    operator <<( const OUString& rNewString );
     103             : };
     104             : 
     105          84 : inline NameBuffer::NameBuffer( RootData* p ) : ExcRoot( p )
     106             : {
     107          84 :     nBase = 0;
     108          84 : }
     109             : 
     110         201 : inline NameBuffer::NameBuffer( RootData* p, sal_uInt16 nNewBase ) : ExcRoot( p )
     111             : {
     112         201 :     nBase = nNewBase;
     113         201 : }
     114             : 
     115             : inline const OUString* NameBuffer::Get ( sal_uInt16 n ) const
     116             : {
     117             :     if( n < nBase || n >= maHashes.size() )
     118             :         return NULL;
     119             : 
     120             :     return &(maHashes[n]->aString);
     121             : }
     122             : 
     123             : inline sal_uInt16 NameBuffer::GetLastIndex () const
     124             : {
     125             :     int size = maHashes.size() + nBase;
     126             : 
     127             :     OSL_ENSURE( size <= 0xFFFF, "*NameBuffer::GetLastIndex(): I'm sick and tired!" );
     128             : 
     129             :     return static_cast<sal_uInt16>( size );
     130             : }
     131             : 
     132          84 : inline void NameBuffer::SetBase( sal_uInt16 nNewBase )
     133             : {
     134          84 :     nBase = nNewBase;
     135          84 : }
     136             : 
     137             : /**
     138             :  * Store and manage shared formula tokens.
     139             :  */
     140             : class SharedFormulaBuffer : public ExcRoot
     141             : {
     142             :     typedef std::unordered_map<ScAddress, ScTokenArray*, ScAddressHashFunctor> TokenArraysType;
     143             :     TokenArraysType maTokenArrays;
     144             : 
     145             : public:
     146             :     SharedFormulaBuffer( RootData* pRD );
     147             :     virtual ~SharedFormulaBuffer();
     148             :     void Clear();
     149             :     void Store( const ScAddress& rPos, const ScTokenArray& rArray );
     150             :     const ScTokenArray* Find( const ScAddress& rRefPos ) const;
     151             : };
     152             : 
     153             : class RangeNameBufferWK3
     154             : {
     155             : private:
     156           0 :     struct Entry
     157             :     {
     158             :         StringHashEntry     aStrHashEntry;
     159             :         ScComplexRefData    aScComplexRefDataRel;
     160             :         OUString            aScAbsName;
     161             :         sal_uInt16          nAbsInd;        // == 0 -> no Abs-Name yet!
     162             :         sal_uInt16          nRelInd;
     163             :         bool                bSingleRef;
     164           0 :                             Entry( const OUString& rName, const OUString& rScName, const ScComplexRefData& rCRD )
     165             :                                 : aStrHashEntry( rName )
     166             :                                 , aScComplexRefDataRel( rCRD )
     167             :                                 , aScAbsName( rScName )
     168             :                                 , nAbsInd(0)
     169             :                                 , nRelInd(0)
     170           0 :                                 , bSingleRef(false)
     171             :                             {
     172           0 :                                 aScAbsName = "_ABS";
     173           0 :                             }
     174             :     };
     175             : 
     176             :     LOTUS_ROOT*        m_pLotRoot;
     177             :     ScTokenArray*      pScTokenArray;
     178             :     sal_uInt16         nIntCount;
     179             :     std::vector<Entry> maEntries;
     180             : 
     181             : public:
     182             :     RangeNameBufferWK3(LOTUS_ROOT* pLotRoot);
     183             :     virtual                 ~RangeNameBufferWK3();
     184             :     void                    Add( const OUString& rName, const ScComplexRefData& rCRD );
     185             :     inline void             Add( const OUString& rName, const ScRange& aScRange );
     186             :     bool                    FindRel( const OUString& rRef, sal_uInt16& rIndex );
     187             :     bool                    FindAbs( const OUString& rRef, sal_uInt16& rIndex );
     188             : };
     189             : 
     190           0 : inline void RangeNameBufferWK3::Add( const OUString& rName, const ScRange& aScRange )
     191             : {
     192             :     ScComplexRefData        aCRD;
     193             :     ScSingleRefData*        pSRD;
     194             : 
     195           0 :     pSRD = &aCRD.Ref1;
     196           0 :     pSRD->InitAddress(aScRange.aStart);
     197           0 :     pSRD->SetFlag3D(true);
     198             : 
     199           0 :     pSRD = &aCRD.Ref2;
     200           0 :     pSRD->InitAddress(aScRange.aEnd);
     201           0 :     pSRD->SetFlag3D(true);
     202             : 
     203           0 :     Add( rName, aCRD );
     204           0 : }
     205             : 
     206          84 : class ExtSheetBuffer : public ExcRoot
     207             : {
     208             : private:
     209          14 :     struct Cont
     210             :         {
     211             :         OUString      aFile;
     212             :         OUString      aTab;
     213             :         sal_uInt16    nTabNum;    // 0xFFFF -> not set yet
     214             :                                 // 0xFFFE -> tried to set, but failed
     215             :                                 // 0xFFFD -> should be in the same workbook, but not found
     216             :         bool          bSWB;
     217             :         bool          bLink;
     218             :                     Cont( const OUString& rFilePathAndName, const OUString& rTabName ) :
     219             :                         aFile( rFilePathAndName ),
     220             :                         aTab( rTabName )
     221             :                     {
     222             :                         nTabNum = 0xFFFF;   // -> table not created yet
     223             :                         bSWB = bLink = false;
     224             :                     }
     225           4 :                     Cont( const OUString& rFilePathAndName, const OUString& rTabName,
     226             :                         const bool bSameWB ) :
     227             :                         aFile( rFilePathAndName ),
     228           4 :                         aTab( rTabName )
     229             :                     {
     230           4 :                         nTabNum = 0xFFFF;   // -> table not created yet
     231           4 :                         bSWB = bSameWB;
     232           4 :                         bLink = false;
     233           4 :                     }
     234             :         };
     235             : 
     236             :     std::vector<Cont> maEntries;
     237             : 
     238             : public:
     239             :     inline          ExtSheetBuffer( RootData* );
     240             : 
     241             :     sal_Int16       Add( const OUString& rFilePathAndName,
     242             :                         const OUString& rTabName, const bool bSameWorkbook = false );
     243             : 
     244             :     bool            GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
     245             :     bool            IsLink( const sal_uInt16 nExcSheetIndex ) const;
     246             :     bool            GetLink( const sal_uInt16 nExcSheetIndex, OUString &rAppl, OUString &rDoc ) const;
     247             : 
     248             :     void            Reset();
     249             : };
     250             : 
     251          84 : inline ExtSheetBuffer::ExtSheetBuffer( RootData* p ) : ExcRoot( p )
     252             : {
     253          84 : }
     254             : 
     255           0 : struct ExtName
     256             : {
     257             :     OUString          aName;
     258             :     sal_uInt32        nStorageId;
     259             :     sal_uInt16        nFlags;
     260             : 
     261           0 :     inline          ExtName( const OUString& r, sal_uInt16 n ) : aName( r ), nStorageId( 0 ), nFlags( n ) {}
     262             : 
     263             :     bool            IsDDE() const;
     264             :     bool            IsOLE() const;
     265             : };
     266             : 
     267         168 : class ExtNameBuff : protected XclImpRoot
     268             : {
     269             : public:
     270             :     explicit        ExtNameBuff( const XclImpRoot& rRoot );
     271             : 
     272             :     void            AddDDE( const OUString& rName, sal_Int16 nRefIdx );
     273             :     void            AddOLE( const OUString& rName, sal_Int16 nRefIdx, sal_uInt32 nStorageId );
     274             :     void            AddName( const OUString& rName, sal_Int16 nRefIdx );
     275             : 
     276             :     const ExtName*  GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
     277             : 
     278             :     void            Reset();
     279             : 
     280             : private:
     281             :     typedef ::std::vector< ExtName >            ExtNameVec;
     282             :     typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
     283             : 
     284             :     ExtNameMap      maExtNames;
     285             : };
     286             : 
     287             : #endif
     288             : 
     289             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11