fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / inc / tokstack.hxx
blobbb81bdf9338874c6cdb8a738c1931e1c7ea2c948
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
23 #include <string.h>
24 #include "compiler.hxx"
25 #include "tokenarray.hxx"
26 #include <osl/diagnose.h>
28 #include <vector>
30 namespace svl {
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;
40 struct TokenId
42 sal_uInt16 nId;
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;
60 class TokenStack;
62 enum E_TYPE
64 T_Id, // Id-Folge
65 T_Str, // String
66 T_D, // Double
67 T_Err, // Error code
68 T_RefC, // Cell Reference
69 T_RefA, // Area Reference
70 T_RN, // Range Name
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
75 T_ExtRefC,
76 T_ExtRefA,
77 T_Error // for check in case of error
80 class TokenPool
82 // !ATTENTION!: external Id-Basis is 1, internal 0!
83 // return Id = 0 -> Error
84 private:
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
92 sal_uInt16 nP_Dbl;
93 sal_uInt16 nP_DblAkt;
95 sal_uInt16* pP_Err; // Pool for error codes
96 sal_uInt16 nP_Err;
97 sal_uInt16 nP_ErrAkt;
99 ScSingleRefData** ppP_RefTr; // Pool for References
100 sal_uInt16 nP_RefTr;
101 sal_uInt16 nP_RefTrAkt;
103 sal_uInt16* pP_Id; // Pool for Id-sets
104 sal_uInt16 nP_Id;
105 sal_uInt16 nP_IdAkt;
106 sal_uInt16 nP_IdLast; // last set-start
108 struct EXTCONT
110 DefTokenId eId;
111 OUString aText;
112 EXTCONT( const DefTokenId e, const OUString& r ) :
113 eId( e ), aText( r ){}
115 EXTCONT** ppP_Ext;
116 sal_uInt16 nP_Ext;
117 sal_uInt16 nP_ExtAkt;
119 struct NLFCONT
121 ScSingleRefData aRef;
122 NLFCONT( const ScSingleRefData& r ) : aRef( r ) {}
124 NLFCONT** ppP_Nlf;
125 sal_uInt16 nP_Nlf;
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 */
133 struct RangeName
135 sal_uInt16 mnIndex;
136 bool mbGlobal;
138 ::std::vector<RangeName> maRangeNames;
140 /** for storage of external names */
141 struct ExtName
143 sal_uInt16 mnFileId;
144 OUString maName;
146 ::std::vector<ExtName> maExtNames;
148 /** for storage of external cell references */
149 struct ExtCellRef
151 sal_uInt16 mnFileId;
152 OUString maTabName;
153 ScSingleRefData maRef;
155 ::std::vector<ExtCellRef> maExtCellRefs;
157 /** for storage of external area references */
158 struct ExtAreaRef
160 sal_uInt16 mnFileId;
161 OUString maTabName;
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)
169 sal_uInt16 nElement;
170 sal_uInt16 nElementAkt;
172 static const sal_uInt16 nScTokenOff;// Offset for SC-Token
173 #ifdef DBG_UTIL
174 sal_uInt16 m_nRek; // recursion counter
175 #endif
176 ScTokenArray* pScToken; // Token array
178 bool GrowString();
179 bool GrowDouble();
180 /* TODO: in case we had FormulaTokenArray::AddError() */
181 #if 0
182 bool GrowError();
183 #endif
184 bool GrowTripel( sal_uInt16 nByMin = 1 );
185 bool GrowId();
186 bool GrowElement();
187 bool GrowExt();
188 bool GrowNlf();
189 bool GrowMatrix();
190 bool GetElement( const sal_uInt16 nId );
191 bool GetElementRek( const sal_uInt16 nId );
192 public:
193 TokenPool( svl::SharedStringPool& rSPool );
194 ~TokenPool();
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 );
221 void Reset();
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;
228 class TokenStack
229 // Stack for Token-Ids: reserve Id=0 for error; e.g. Get() returns 0 on error
232 private:
233 TokenId* pStack; // Stack as Array
234 sal_uInt16 nPos; // Write-mark
235 sal_uInt16 nSize; // first Index outside of stack
236 public:
237 TokenStack( sal_uInt16 nNewSize = 1024 );
238 ~TokenStack();
239 inline TokenStack& operator <<( const TokenId& rNewId );
240 inline void operator >>( TokenId &rId );
242 inline void Reset();
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, ..." );
253 TokenId nRet;
255 if( nPos == 0 )
256 nRet = 0;
257 else
259 nPos--;
260 nRet = pStack[ nPos ];
263 return nRet;
266 inline TokenStack &TokenStack::operator <<( const TokenId& rNewId )
267 {// Element on Stack
268 OSL_ENSURE( nPos < nSize, "*TokenStack::<<(): Stack overflow" );
269 if( nPos < nSize )
271 pStack[ nPos ] = rNewId;
272 nPos++;
275 return *this;
278 inline void TokenStack::operator >>( TokenId& rId )
279 {// Element of Stack
280 OSL_ENSURE( nPos > 0,
281 "*TokenStack::>>(): is empty, is empty, ..." );
282 if( nPos > 0 )
284 nPos--;
285 rId = pStack[ nPos ];
289 inline void TokenStack::Reset()
291 nPos = 0;
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 )
303 if (!GrowId())
304 return *this;
306 pP_Id[ nP_IdAkt ] = ( ( sal_uInt16 ) rId ) - 1;
307 nP_IdAkt++;
309 return *this;
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 )
318 if (!GrowId())
319 return *this;
321 pP_Id[ nP_IdAkt ] = ( ( sal_uInt16 ) eId ) + nScTokenOff;
322 nP_IdAkt++;
324 return *this;
327 inline TokenPool& TokenPool::operator <<( TokenStack& rStack )
329 if( nP_IdAkt >= nP_Id )
330 if (!GrowId())
331 return *this;
333 pP_Id[ nP_IdAkt ] = ( ( sal_uInt16 ) rStack.Get() ) - 1;
334 nP_IdAkt++;
336 return *this;
339 inline void TokenPool::operator >>( TokenStack& rStack )
341 TokenId nId;
342 *this >> nId;
343 rStack << nId;
346 inline const TokenId TokenPool::Store()
348 TokenId nId;
349 *this >> nId;
350 return nId;
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();
367 if( rId )
368 {//...only if rId > 0!
369 #ifdef DBG_UTIL
370 m_nRek = 0;
371 #endif
372 GetElement( ( sal_uInt16 ) rId - 1 );
375 return pScToken;
378 inline E_TYPE TokenPool::GetType( const TokenId& rId ) const
380 E_TYPE nRet;
382 sal_uInt16 nId = (sal_uInt16) rId - 1;
384 if( nId < nElementAkt )
385 nRet = pType[ nId ] ;
386 else
387 nRet = T_Error;
389 return nRet;
392 #endif
394 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */