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

Generated by: LCOV version 1.10