LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/inc - namebuff.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 17 55 30.9 %
Date: 2012-12-27 Functions: 9 21 42.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_NAMEBUFF_HXX
      21             : #define SC_NAMEBUFF_HXX
      22             : 
      23             : #include <tools/string.hxx>
      24             : #include "compiler.hxx"
      25             : #include "root.hxx"
      26             : #include "xiroot.hxx"
      27             : 
      28             : #include "rangenam.hxx"
      29             : #include <boost/unordered_map.hpp>
      30             : #include <list>
      31             : 
      32             : class ScTokenArray;
      33             : class NameBuffer;
      34             : 
      35             : 
      36             : 
      37             : 
      38           1 : class StringHashEntry
      39             : {
      40             : private:
      41             :     friend class NameBuffer;
      42             :     String          aString;
      43             :     sal_uInt32          nHash;
      44             : 
      45             :     static sal_uInt32   MakeHashCode( const String& );
      46             : public:
      47             :     inline          StringHashEntry( const String& );
      48             :     inline          StringHashEntry( void );
      49             :     inline void     operator =( const sal_Char* );
      50             :     inline void     operator =( const String& );
      51             :     inline void     operator =( const StringHashEntry& );
      52             :     inline sal_Bool     operator ==( const StringHashEntry& ) const;
      53             : };
      54             : 
      55             : 
      56             : inline StringHashEntry::StringHashEntry( void )
      57             : {
      58             : }
      59             : 
      60             : 
      61           1 : inline StringHashEntry::StringHashEntry( const String& r ) : aString( r )
      62             : {
      63           1 :     nHash = MakeHashCode( r );
      64           1 : }
      65             : 
      66             : 
      67             : inline void StringHashEntry::operator =( const sal_Char* p )
      68             : {
      69             :     aString.AssignAscii( p );
      70             :     nHash = MakeHashCode( aString );
      71             : }
      72             : 
      73             : 
      74             : inline void StringHashEntry::operator =( const String& r )
      75             : {
      76             :     aString = r;
      77             :     nHash = MakeHashCode( r );
      78             : }
      79             : 
      80             : 
      81             : inline void StringHashEntry::operator =( const StringHashEntry& r )
      82             : {
      83             :     nHash = r.nHash;
      84             :     aString = r.aString;
      85             : }
      86             : 
      87             : 
      88           0 : inline sal_Bool StringHashEntry::operator ==( const StringHashEntry& r ) const
      89             : {
      90           0 :     return ( nHash == r.nHash && aString ==  r.aString );
      91             : }
      92             : 
      93             : 
      94             : 
      95             : class NameBuffer : public ExcRoot
      96             : {
      97             : private:
      98             :     sal_uInt16                  nBase;      // Index-Basis
      99             :     std::vector<StringHashEntry*> maHashes;
     100             : 
     101             : public:
     102             : 
     103             :     inline                  NameBuffer( RootData* );
     104             :     inline                  NameBuffer( RootData*, sal_uInt16 nNewBase );
     105             : 
     106             :     virtual                 ~NameBuffer();
     107             :     inline const String*    Get( sal_uInt16 nIndex ) const;
     108             :     inline sal_uInt16       GetLastIndex() const;
     109             :     inline void             SetBase( sal_uInt16 nNewBase = 0 );
     110             :     void                    operator <<( const String& rNewString );
     111             : };
     112             : 
     113          20 : inline NameBuffer::NameBuffer( RootData* p ) : ExcRoot( p )
     114             : {
     115          20 :     nBase = 0;
     116          20 : }
     117             : 
     118             : 
     119           2 : inline NameBuffer::NameBuffer( RootData* p, sal_uInt16 nNewBase ) : ExcRoot( p )
     120             : {
     121           2 :     nBase = nNewBase;
     122           2 : }
     123             : 
     124             : 
     125             : inline const String* NameBuffer::Get ( sal_uInt16 n ) const
     126             : {
     127             :     if( n < nBase || n >= maHashes.size() )
     128             :         return NULL;
     129             : 
     130             :     return &(maHashes[n]->aString);
     131             : }
     132             : 
     133             : 
     134             : inline sal_uInt16 NameBuffer::GetLastIndex () const
     135             : {
     136             :     int size = maHashes.size() + nBase;
     137             : 
     138             :     OSL_ENSURE( size <= 0xFFFF, "*NameBuffer::GetLastIndex(): Ich hab' die Nase voll!" );
     139             : 
     140             :     return static_cast<sal_uInt16>( size );
     141             : }
     142             : 
     143             : 
     144          20 : inline void NameBuffer::SetBase( sal_uInt16 nNewBase )
     145             : {
     146          20 :     nBase = nNewBase;
     147          20 : }
     148             : 
     149             : 
     150             : 
     151             : 
     152             : class ShrfmlaBuffer : public ExcRoot
     153             : {
     154             :     struct ScAddressHashFunc : public std::unary_function< const ScAddress &, size_t >
     155             :     {
     156             :         size_t operator() (const ScAddress &addr) const;
     157             :     };
     158             :     typedef boost::unordered_map <ScAddress, sal_uInt16, ScAddressHashFunc> ShrfmlaHash;
     159             :     typedef std::list <ScRange>                                  ShrfmlaList;
     160             : 
     161             :     ShrfmlaHash  index_hash;
     162             :     ShrfmlaList  index_list;
     163             :     size_t                  mnCurrIdx;
     164             : 
     165             : public:
     166             :                             ShrfmlaBuffer( RootData* pRD );
     167             :     virtual                 ~ShrfmlaBuffer();
     168             :     void                    Clear();
     169             :     void                    Store( const ScRange& rRange, const ScTokenArray& );
     170             :     sal_uInt16                  Find (const ScAddress & rAddress ) const;
     171             : 
     172             :     static String           CreateName( const ScRange& );
     173             :     };
     174             : 
     175             : 
     176             : 
     177             : 
     178             : class RangeNameBufferWK3
     179             : {
     180             : private:
     181           0 :     struct Entry
     182             :         {
     183             :         StringHashEntry     aStrHashEntry;
     184             :         ScComplexRefData        aScComplexRefDataRel;
     185             :         String              aScAbsName;
     186             :         sal_uInt16              nAbsInd;        // == 0 -> noch keine Abs-Name!
     187             :         sal_uInt16              nRelInd;
     188             :         sal_Bool                bSingleRef;
     189           0 :                             Entry( const String& rName, const String& rScName, const ScComplexRefData& rCRD ) :
     190             :                                 aStrHashEntry( rName ),
     191             :                                 aScComplexRefDataRel( rCRD ),
     192           0 :                                 aScAbsName( rScName )
     193             :                             {
     194           0 :                                 nAbsInd = 0;
     195           0 :                                 aScAbsName.AppendAscii( RTL_CONSTASCII_STRINGPARAM( "_ABS" ) );
     196           0 :                             }
     197             :         };
     198             : 
     199             :     ScTokenArray*           pScTokenArray;
     200             :     sal_uInt16                  nIntCount;
     201             :     std::vector<Entry> maEntries;
     202             : 
     203             : public:
     204             :                             RangeNameBufferWK3( void );
     205             :     virtual                 ~RangeNameBufferWK3();
     206             :     void                    Add( const String& rName, const ScComplexRefData& rCRD );
     207             :     inline void             Add( const String& rName, const ScRange& aScRange );
     208             :     sal_Bool                    FindRel( const String& rRef, sal_uInt16& rIndex );
     209             :     sal_Bool                    FindAbs( const String& rRef, sal_uInt16& rIndex );
     210             : };
     211             : 
     212             : 
     213           0 : inline void RangeNameBufferWK3::Add( const String& rName, const ScRange& aScRange )
     214             : {
     215             :     ScComplexRefData        aCRD;
     216             :     ScSingleRefData*        pSRD;
     217             :     const ScAddress*    pScAddr;
     218             : 
     219           0 :     pSRD = &aCRD.Ref1;
     220           0 :     pScAddr = &aScRange.aStart;
     221           0 :     pSRD->SetFlag3D( sal_True );
     222           0 :     pSRD->nCol = pScAddr->Col();
     223           0 :     pSRD->nRow = pScAddr->Row();
     224           0 :     pSRD->nTab = pScAddr->Tab();
     225             : 
     226             :     // zunaechst ALLE Refs nur absolut
     227           0 :     pSRD->SetColRel( false );
     228           0 :     pSRD->SetRowRel( false );
     229           0 :     pSRD->SetTabRel( false );
     230             : 
     231           0 :     pSRD = &aCRD.Ref2;
     232           0 :     pScAddr = &aScRange.aEnd;
     233           0 :     pSRD->SetFlag3D( sal_True );
     234           0 :     pSRD->nCol = pScAddr->Col();
     235           0 :     pSRD->nRow = pScAddr->Row();
     236           0 :     pSRD->nTab = pScAddr->Tab();
     237             : 
     238             :     // zunaechst ALLE Refs nur absolut
     239           0 :     pSRD->SetColRel( false );
     240           0 :     pSRD->SetRowRel( false );
     241           0 :     pSRD->SetTabRel( false );
     242             : 
     243           0 :     Add( rName, aCRD );
     244           0 : }
     245             : 
     246             : 
     247             : 
     248             : 
     249          20 : class ExtSheetBuffer : public ExcRoot
     250             : {
     251             : private:
     252           0 :     struct Cont
     253             :         {
     254             :         String      aFile;
     255             :         String      aTab;
     256             :         sal_uInt16      nTabNum;    // 0xFFFF -> noch nicht angelegt
     257             :                                 // 0xFFFE -> versucht anzulegen, ging aber schief
     258             :                                 // 0xFFFD -> soll im selben Workbook sein, findet's aber nicht
     259             :         sal_Bool        bSWB;
     260             :         sal_Bool        bLink;
     261             :                     Cont( const String& rFilePathAndName, const String& rTabName ) :
     262             :                         aFile( rFilePathAndName ),
     263             :                         aTab( rTabName )
     264             :                     {
     265             :                         nTabNum = 0xFFFF;   // -> Tabelle noch nicht erzeugt
     266             :                         bSWB = bLink = false;
     267             :                     }
     268           0 :                     Cont( const String& rFilePathAndName, const String& rTabName,
     269             :                         const sal_Bool bSameWB ) :
     270             :                         aFile( rFilePathAndName ),
     271           0 :                         aTab( rTabName )
     272             :                     {
     273           0 :                         nTabNum = 0xFFFF;   // -> Tabelle noch nicht erzeugt
     274           0 :                         bSWB = bSameWB;
     275           0 :                         bLink = false;
     276           0 :                     }
     277             :         };
     278             : 
     279             :     std::vector<Cont> maEntries;
     280             : 
     281             : public:
     282             :     inline          ExtSheetBuffer( RootData* );
     283             : 
     284             :     sal_Int16       Add( const String& rFilePathAndName,
     285             :                         const String& rTabName, const sal_Bool bSameWorkbook = false );
     286             : 
     287             :     sal_Bool            GetScTabIndex( sal_uInt16 nExcSheetIndex, sal_uInt16& rIn_LastTab_Out_ScIndex );
     288             :     sal_Bool            IsLink( const sal_uInt16 nExcSheetIndex ) const;
     289             :     sal_Bool            GetLink( const sal_uInt16 nExcSheetIndex, String &rAppl, String &rDoc ) const;
     290             : 
     291             :     void            Reset( void );
     292             : };
     293             : 
     294             : 
     295          20 : inline ExtSheetBuffer::ExtSheetBuffer( RootData* p ) : ExcRoot( p )
     296             : {
     297          20 : }
     298             : 
     299             : 
     300             : 
     301             : 
     302           0 : struct ExtName
     303             : {
     304             :     String          aName;
     305             :     sal_uInt32          nStorageId;
     306             :     sal_uInt16          nFlags;
     307             : 
     308           0 :     inline          ExtName( const String& r, sal_uInt16 n ) : aName( r ), nStorageId( 0 ), nFlags( n ) {}
     309             : 
     310             :     sal_Bool            IsDDE( void ) const;
     311             :     sal_Bool            IsOLE( void ) const;
     312             : };
     313             : 
     314             : 
     315             : 
     316             : 
     317          40 : class ExtNameBuff : protected XclImpRoot
     318             : {
     319             : public:
     320             :     explicit        ExtNameBuff( const XclImpRoot& rRoot );
     321             : 
     322             :     void            AddDDE( const String& rName, sal_Int16 nRefIdx );
     323             :     void            AddOLE( const String& rName, sal_Int16 nRefIdx, sal_uInt32 nStorageId );
     324             :     void            AddName( const String& rName, sal_Int16 nRefIdx );
     325             : 
     326             :     const ExtName*  GetNameByIndex( sal_Int16 nRefIdx, sal_uInt16 nNameIdx ) const;
     327             : 
     328             :     void            Reset();
     329             : 
     330             : private:
     331             :     typedef ::std::vector< ExtName >            ExtNameVec;
     332             :     typedef ::std::map< sal_Int16, ExtNameVec > ExtNameMap;
     333             : 
     334             :     ExtNameMap      maExtNames;
     335             : };
     336             : 
     337             : 
     338             : #endif
     339             : 
     340             : 
     341             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10