1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_FILTER_INC_NAMEBUFF_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_NAMEBUFF_HXX
23 #include <rtl/ustring.hxx>
24 #include <osl/diagnose.h>
25 #include "compiler.hxx"
29 #include "rangenam.hxx"
30 #include "formulacell.hxx"
33 #include <unordered_map>
41 friend class NameBuffer
;
45 static sal_uInt32
MakeHashCode( const OUString
& );
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;
55 inline StringHashEntry::StringHashEntry()
59 inline StringHashEntry::StringHashEntry( const OUString
& r
) : aString( r
)
61 nHash
= MakeHashCode( r
);
64 inline void StringHashEntry::operator =( const sal_Char
* p
)
66 aString
= OUString(p
, strlen(p
), RTL_TEXTENCODING_ASCII_US
);
67 nHash
= MakeHashCode( aString
);
70 inline void StringHashEntry::operator =( const OUString
& r
)
73 nHash
= MakeHashCode( r
);
76 inline void StringHashEntry::operator =( const StringHashEntry
& r
)
82 inline bool StringHashEntry::operator ==( const StringHashEntry
& r
) const
84 return ( nHash
== r
.nHash
&& aString
== r
.aString
);
87 class NameBuffer
: public ExcRoot
90 sal_uInt16 nBase
; // Index-Base
91 std::vector
<StringHashEntry
*> maHashes
;
95 inline NameBuffer( RootData
* );
96 inline NameBuffer( RootData
*, sal_uInt16 nNewBase
);
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
);
105 inline NameBuffer::NameBuffer( RootData
* p
) : ExcRoot( p
)
110 inline NameBuffer::NameBuffer( RootData
* p
, sal_uInt16 nNewBase
) : ExcRoot( p
)
115 inline const OUString
* NameBuffer::Get ( sal_uInt16 n
) const
117 if( n
< nBase
|| n
>= maHashes
.size() )
120 return &(maHashes
[n
]->aString
);
123 inline sal_uInt16
NameBuffer::GetLastIndex () const
125 int size
= maHashes
.size() + nBase
;
127 OSL_ENSURE( size
<= 0xFFFF, "*NameBuffer::GetLastIndex(): I'm sick and tired!" );
129 return static_cast<sal_uInt16
>( size
);
132 inline void NameBuffer::SetBase( sal_uInt16 nNewBase
)
138 * Store and manage shared formula tokens.
140 class SharedFormulaBuffer
: public ExcRoot
142 typedef std::unordered_map
<ScAddress
, ScTokenArray
*, ScAddressHashFunctor
> TokenArraysType
;
143 TokenArraysType maTokenArrays
;
146 SharedFormulaBuffer( RootData
* pRD
);
147 virtual ~SharedFormulaBuffer();
149 void Store( const ScAddress
& rPos
, const ScTokenArray
& rArray
);
150 const ScTokenArray
* Find( const ScAddress
& rRefPos
) const;
153 class RangeNameBufferWK3
158 StringHashEntry aStrHashEntry
;
159 ScComplexRefData aScComplexRefDataRel
;
161 sal_uInt16 nAbsInd
; // == 0 -> no Abs-Name yet!
164 Entry( const OUString
& rName
, const OUString
& rScName
, const ScComplexRefData
& rCRD
)
165 : aStrHashEntry( rName
)
166 , aScComplexRefDataRel( rCRD
)
167 , aScAbsName( rScName
)
176 LOTUS_ROOT
* m_pLotRoot
;
177 ScTokenArray
* pScTokenArray
;
178 sal_uInt16 nIntCount
;
179 std::vector
<Entry
> maEntries
;
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
);
190 inline void RangeNameBufferWK3::Add( const OUString
& rName
, const ScRange
& aScRange
)
192 ScComplexRefData aCRD
;
193 ScSingleRefData
* pSRD
;
196 pSRD
->InitAddress(aScRange
.aStart
);
197 pSRD
->SetFlag3D(true);
200 pSRD
->InitAddress(aScRange
.aEnd
);
201 pSRD
->SetFlag3D(true);
206 class ExtSheetBuffer
: public ExcRoot
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
218 Cont( const OUString
& rFilePathAndName
, const OUString
& rTabName
) :
219 aFile( rFilePathAndName
),
222 nTabNum
= 0xFFFF; // -> table not created yet
223 bSWB
= bLink
= false;
225 Cont( const OUString
& rFilePathAndName
, const OUString
& rTabName
,
226 const bool bSameWB
) :
227 aFile( rFilePathAndName
),
230 nTabNum
= 0xFFFF; // -> table not created yet
236 std::vector
<Cont
> maEntries
;
239 inline ExtSheetBuffer( RootData
* );
241 sal_Int16
Add( const OUString
& rFilePathAndName
,
242 const OUString
& rTabName
, const bool bSameWorkbook
= false );
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;
251 inline ExtSheetBuffer::ExtSheetBuffer( RootData
* p
) : ExcRoot( p
)
258 sal_uInt32 nStorageId
;
261 inline ExtName( const OUString
& r
, sal_uInt16 n
) : aName( r
), nStorageId( 0 ), nFlags( n
) {}
267 class ExtNameBuff
: protected XclImpRoot
270 explicit ExtNameBuff( const XclImpRoot
& rRoot
);
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
);
276 const ExtName
* GetNameByIndex( sal_Int16 nRefIdx
, sal_uInt16 nNameIdx
) const;
281 typedef ::std::vector
< ExtName
> ExtNameVec
;
282 typedef ::std::map
< sal_Int16
, ExtNameVec
> ExtNameMap
;
284 ExtNameMap maExtNames
;
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */