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_TOKSTACK_HXX
21 #define INCLUDED_SC_SOURCE_FILTER_INC_TOKSTACK_HXX
24 #include "compiler.hxx"
25 #include "tokenarray.hxx"
26 #include <osl/diagnose.h>
32 class SharedStringPool
;
36 typedef OpCode DefTokenId
;
37 // in PRODUCT version: ambiguity between OpCode (being sal_uInt16) and UINT16
38 // Unfortunately a typedef is just a dumb alias and not a real type ...
39 //typedef sal_uInt16 TokenId;
44 TokenId() : nId( 0 ) {}
45 TokenId( sal_uInt16 n
) : nId( n
) {}
46 TokenId( const TokenId
& r
) : nId( r
.nId
) {}
47 inline TokenId
& operator =( const TokenId
& r
) { nId
= r
.nId
; return *this; }
48 inline TokenId
& operator =( sal_uInt16 n
) { nId
= n
; return *this; }
49 inline operator sal_uInt16
&() { return nId
; }
50 inline operator const sal_uInt16
&() const { return nId
; }
51 inline bool operator <( sal_uInt16 n
) const { return nId
< n
; }
52 inline bool operator >( sal_uInt16 n
) const { return nId
> n
; }
53 inline bool operator <=( sal_uInt16 n
) const { return nId
<= n
; }
54 inline bool operator >=( sal_uInt16 n
) const { return nId
>= n
; }
55 inline bool operator ==( sal_uInt16 n
) const { return nId
== n
; }
56 inline bool operator !=( sal_uInt16 n
) const { return nId
!= n
; }
59 struct ScComplexRefData
;
68 T_RefC
, // Cell Reference
69 T_RefA
, // Area Reference
71 T_Ext
, // something unknown with function name
72 T_Nlf
, // token for natural language formula
73 T_Matrix
, // token for inline arrays
74 T_ExtName
, // token for external names
77 T_Error
// for check in case of error
82 // !ATTENTION!: external Id-Basis is 1, internal 0!
83 // return Id = 0 -> Error
85 svl::SharedStringPool
& mrStringPool
;
87 OUString
** ppP_Str
; // Pool for Strings
88 sal_uInt16 nP_Str
; // ...with size
89 sal_uInt16 nP_StrAkt
; // ...and Write-Mark
91 double* pP_Dbl
; // Pool for Doubles
95 sal_uInt16
* pP_Err
; // Pool for error codes
99 ScSingleRefData
** ppP_RefTr
; // Pool for References
101 sal_uInt16 nP_RefTrAkt
;
103 sal_uInt16
* pP_Id
; // Pool for Id-sets
106 sal_uInt16 nP_IdLast
; // last set-start
112 EXTCONT( const DefTokenId e
, const OUString
& r
) :
113 eId( e
), aText( r
){}
117 sal_uInt16 nP_ExtAkt
;
121 ScSingleRefData aRef
;
122 NLFCONT( const ScSingleRefData
& r
) : aRef( r
) {}
126 sal_uInt16 nP_NlfAkt
;
128 ScMatrix
** ppP_Matrix
; // Pool for Matrices
129 sal_uInt16 nP_Matrix
;
130 sal_uInt16 nP_MatrixAkt
;
132 /** for storage of named ranges */
138 ::std::vector
<RangeName
> maRangeNames
;
140 /** for storage of external names */
146 ::std::vector
<ExtName
> maExtNames
;
148 /** for storage of external cell references */
153 ScSingleRefData maRef
;
155 ::std::vector
<ExtCellRef
> maExtCellRefs
;
157 /** for storage of external area references */
162 ScComplexRefData maRef
;
164 ::std::vector
<ExtAreaRef
> maExtAreaRefs
;
166 sal_uInt16
* pElement
; // Array with Indices for elements
167 E_TYPE
* pType
; // ...with Type-Info
168 sal_uInt16
* pSize
; // ...with size (Anz. sal_uInt16)
170 sal_uInt16 nElementAkt
;
172 static const sal_uInt16 nScTokenOff
;// Offset for SC-Token
174 sal_uInt16 m_nRek
; // recursion counter
176 ScTokenArray
* pScToken
; // Token array
180 /* TODO: in case we had FormulaTokenArray::AddError() */
184 bool GrowTripel( sal_uInt16 nByMin
= 1 );
190 bool GetElement( const sal_uInt16 nId
);
191 bool GetElementRek( const sal_uInt16 nId
);
193 TokenPool( svl::SharedStringPool
& rSPool
);
195 inline TokenPool
& operator <<( const TokenId
& rId
);
196 inline TokenPool
& operator <<( const DefTokenId eId
);
197 inline TokenPool
& operator <<( TokenStack
& rStack
);
198 void operator >>( TokenId
& rId
);
199 inline void operator >>( TokenStack
& rStack
);
200 inline const TokenId
Store();
201 const TokenId
Store( const double& rDouble
);
203 // only for Range-Names
204 const TokenId
Store( const sal_uInt16 nIndex
);
205 inline const TokenId
Store( const sal_Int16 nWert
);
206 const TokenId
Store( const OUString
& rString
);
207 const TokenId
Store( const ScSingleRefData
& rTr
);
208 const TokenId
Store( const ScComplexRefData
& rTr
);
210 const TokenId
Store( const DefTokenId eId
, const OUString
& rName
);
211 // 4 externals (e.g. AddIns, Macros...)
212 const TokenId
StoreNlf( const ScSingleRefData
& rTr
);
213 const TokenId
StoreMatrix();
214 const TokenId
StoreName( sal_uInt16 nIndex
, bool bGlobal
);
215 const TokenId
StoreExtName( sal_uInt16 nFileId
, const OUString
& rName
);
216 const TokenId
StoreExtRef( sal_uInt16 nFileId
, const OUString
& rTabName
, const ScSingleRefData
& rRef
);
217 const TokenId
StoreExtRef( sal_uInt16 nFileId
, const OUString
& rTabName
, const ScComplexRefData
& rRef
);
219 inline const TokenId
LastId() const;
220 inline const ScTokenArray
* operator []( const TokenId
& rId
);
222 inline E_TYPE
GetType( const TokenId
& rId
) const;
223 bool IsSingleOp( const TokenId
& rId
, const DefTokenId eId
) const;
224 const OUString
* GetExternal( const TokenId
& rId
) const;
225 ScMatrix
* GetMatrix( unsigned int n
) const;
229 // Stack for Token-Ids: reserve Id=0 for error; e.g. Get() returns 0 on error
233 TokenId
* pStack
; // Stack as Array
234 sal_uInt16 nPos
; // Write-mark
235 sal_uInt16 nSize
; // first Index outside of stack
237 TokenStack( sal_uInt16 nNewSize
= 1024 );
239 inline TokenStack
& operator <<( const TokenId
& rNewId
);
240 inline void operator >>( TokenId
&rId
);
244 inline bool HasMoreTokens() const { return nPos
> 0; }
245 inline const TokenId
Get();
248 inline const TokenId
TokenStack::Get()
250 OSL_ENSURE( nPos
> 0,
251 "*TokenStack::Get(): is empty, is empty, ..." );
260 nRet
= pStack
[ nPos
];
266 inline TokenStack
&TokenStack::operator <<( const TokenId
& rNewId
)
268 OSL_ENSURE( nPos
< nSize
, "*TokenStack::<<(): Stack overflow" );
271 pStack
[ nPos
] = rNewId
;
278 inline void TokenStack::operator >>( TokenId
& rId
)
280 OSL_ENSURE( nPos
> 0,
281 "*TokenStack::>>(): is empty, is empty, ..." );
285 rId
= pStack
[ nPos
];
289 inline void TokenStack::Reset()
294 inline TokenPool
& TokenPool::operator <<( const TokenId
& rId
)
296 // POST: rId's are stored consecutively in Pool under a new Id;
297 // finalize with >> or Store()
298 // rId -> ( sal_uInt16 ) rId - 1;
299 OSL_ENSURE( ( sal_uInt16
) rId
< nScTokenOff
,
300 "-TokenPool::operator <<: TokenId in DefToken-Range!" );
302 if( nP_IdAkt
>= nP_Id
)
306 pP_Id
[ nP_IdAkt
] = ( ( sal_uInt16
) rId
) - 1;
312 inline TokenPool
& TokenPool::operator <<( const DefTokenId eId
)
314 OSL_ENSURE( ( sal_uInt32
) eId
+ nScTokenOff
< 0xFFFF,
315 "-TokenPool::operator<<: enmum too large!" );
317 if( nP_IdAkt
>= nP_Id
)
321 pP_Id
[ nP_IdAkt
] = ( ( sal_uInt16
) eId
) + nScTokenOff
;
327 inline TokenPool
& TokenPool::operator <<( TokenStack
& rStack
)
329 if( nP_IdAkt
>= nP_Id
)
333 pP_Id
[ nP_IdAkt
] = ( ( sal_uInt16
) rStack
.Get() ) - 1;
339 inline void TokenPool::operator >>( TokenStack
& rStack
)
346 inline const TokenId
TokenPool::Store()
353 inline const TokenId
TokenPool::Store( const sal_Int16 nWert
)
355 return Store( ( double ) nWert
);
358 inline const TokenId
TokenPool::LastId() const
360 return static_cast<TokenId
>(nElementAkt
); // correct, as Ausgabe with Offset 1!
363 const inline ScTokenArray
* TokenPool::operator []( const TokenId
& rId
)
365 pScToken
->ClearScTokenArray();
368 {//...only if rId > 0!
372 GetElement( ( sal_uInt16
) rId
- 1 );
378 inline E_TYPE
TokenPool::GetType( const TokenId
& rId
) const
382 sal_uInt16 nId
= (sal_uInt16
) rId
- 1;
384 if( nId
< nElementAkt
)
385 nRet
= pType
[ nId
] ;
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */