1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tokstack.hxx,v $
10 * $Revision: 1.14.32.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef SC_TOKSTACK_HXX
32 #define SC_TOKSTACK_HXX
35 #include <tools/debug.hxx>
36 #include "compiler.hxx"
37 #include "tokenarray.hxx"
41 typedef OpCode DefTokenId
;
42 // in PRODUCT version: ambiguity between OpCode (being USHORT) and UINT16
43 // Unfortunately a typedef is just a dumb alias and not a real type ...
44 //typedef UINT16 TokenId;
49 TokenId() : nId( 0 ) {}
50 TokenId( UINT16 n
) : nId( n
) {}
51 TokenId( const TokenId
& r
) : nId( r
.nId
) {}
52 inline TokenId
& operator =( const TokenId
& r
) { nId
= r
.nId
; return *this; }
53 inline TokenId
& operator =( UINT16 n
) { nId
= n
; return *this; }
54 inline operator UINT16
&() { return nId
; }
55 inline operator const UINT16
&() const { return nId
; }
56 inline BOOL
operator <( UINT16 n
) const { return nId
< n
; }
57 inline BOOL
operator >( UINT16 n
) const { return nId
> n
; }
58 inline BOOL
operator <=( UINT16 n
) const { return nId
<= n
; }
59 inline BOOL
operator >=( UINT16 n
) const { return nId
>= n
; }
60 inline BOOL
operator ==( UINT16 n
) const { return nId
== n
; }
61 inline BOOL
operator !=( UINT16 n
) const { return nId
!= n
; }
65 //------------------------------------------------------------------------
66 struct ScComplexRefData
;
77 T_RefC
, // Cell Reference
78 T_RefA
, // Area Reference
80 T_Ext
, // irgendwas Unbekanntes mit Funktionsnamen
81 T_Nlf
, // token for natural language formula
82 T_Matrix
, // token for inline arrays
83 T_ExtName
, // token for external names
86 T_Error
// fuer Abfrage im Fehlerfall
94 // !ACHTUNG!: externe Id-Basis ist 1, interne 0!
95 // Ausgabe Id = 0 -> Fehlerfall
97 String
** ppP_Str
; // Pool fuer Strings
98 UINT16 nP_Str
; // ...mit Groesse
99 UINT16 nP_StrAkt
; // ...und Schreibmarke
101 double* pP_Dbl
; // Pool fuer Doubles
105 USHORT
* pP_Err
; // Pool for error codes
109 ScSingleRefData
** ppP_RefTr
; // Pool fuer Referenzen
113 UINT16
* pP_Id
; // Pool fuer Id-Folgen
116 UINT16 nP_IdLast
; // letzter Folgen-Beginn
122 EXTCONT( const DefTokenId e
, const String
& r
) :
123 eId( e
), aText( r
){}
131 ScSingleRefData aRef
;
132 NLFCONT( const ScSingleRefData
& r
) : aRef( r
) {}
138 ScMatrix
** ppP_Matrix
; // Pool fuer Matricies
142 /** for storage of external names */
148 ::std::vector
<ExtName
> maExtNames
;
150 /** for storage of external cell references */
155 ScSingleRefData maRef
;
157 ::std::vector
<ExtCellRef
> maExtCellRefs
;
159 /** for storage of external area references */
164 ScComplexRefData maRef
;
166 ::std::vector
<ExtAreaRef
> maExtAreaRefs
;
168 UINT16
* pElement
; // Array mit Indizes fuer Elemente
169 E_TYPE
* pType
; // ...mit Typ-Info
170 UINT16
* pSize
; // ...mit Laengenangabe (Anz. UINT16)
174 static const UINT16 nScTokenOff
;// Offset fuer SC-Token
176 UINT16 nRek
; // Rekursionszaehler
178 ScTokenArray
* pScToken
; // Tokenbastler
180 void GrowString( void );
181 void GrowDouble( void );
182 //UNUSED2009-05 void GrowError( void );
183 void GrowTripel( void );
185 void GrowElement( void );
186 void GrowExt( void );
187 void GrowNlf( void );
188 void GrowMatrix( void );
189 void GetElement( const UINT16 nId
);
190 void GetElementRek( const UINT16 nId
);
194 inline TokenPool
& operator <<( const TokenId nId
);
195 inline TokenPool
& operator <<( const DefTokenId eId
);
196 inline TokenPool
& operator <<( TokenStack
& rStack
);
197 void operator >>( TokenId
& rId
);
198 inline void operator >>( TokenStack
& rStack
);
199 inline const TokenId
Store( void );
200 const TokenId
Store( const double& rDouble
);
201 //UNUSED2008-05 const TokenId StoreError( USHORT nError );
203 // nur fuer Range-Names
204 const TokenId
Store( const UINT16 nIndex
);
205 inline const TokenId
Store( const INT16 nWert
);
206 const TokenId
Store( const String
& rString
);
207 const TokenId
Store( const ScSingleRefData
& rTr
);
208 const TokenId
Store( const ScComplexRefData
& rTr
);
210 const TokenId
Store( const DefTokenId eId
, const String
& rName
);
211 // 4 externals (e.g. AddIns, Makros...)
212 const TokenId
StoreNlf( const ScSingleRefData
& rTr
);
213 const TokenId
StoreMatrix( SCSIZE nC
, SCSIZE nR
);
214 const TokenId
StoreExtName( sal_uInt16 nFileId
, const String
& rName
);
215 const TokenId
StoreExtRef( sal_uInt16 nFileId
, const String
& rTabName
, const ScSingleRefData
& rRef
);
216 const TokenId
StoreExtRef( sal_uInt16 nFileId
, const String
& rTabName
, const ScComplexRefData
& rRef
);
218 inline const TokenId
LastId( void ) const;
219 inline const ScTokenArray
* operator []( const TokenId nId
);
221 inline E_TYPE
GetType( const TokenId
& nId
) const;
222 BOOL
IsSingleOp( const TokenId
& nId
, const DefTokenId eId
) const;
223 const String
* GetExternal( const TokenId
& nId
) const;
224 //UNUSED2008-05 const String* GetString( const TokenId& nId ) const;
225 ScMatrix
* GetMatrix( unsigned int n
) const;
232 // Stack fuer Token-Ids: Id 0 sollte reserviert bleiben als
233 // fehlerhafte Id, da z.B. Get() im Fehlerfall 0 liefert
236 TokenId
* pStack
; // Stack als Array
237 UINT16 nPos
; // Schreibmarke
238 UINT16 nSize
; // Erster Index ausserhalb des Stacks
240 TokenStack( UINT16 nNewSize
= 1024 );
242 inline TokenStack
& operator <<( const TokenId nNewId
);
243 inline void operator >>( TokenId
&rId
);
245 inline void Reset( void );
247 inline bool HasMoreTokens() const { return nPos
> 0; }
248 inline const TokenId
Get( void );
254 inline const TokenId
TokenStack::Get( void )
256 DBG_ASSERT( nPos
> 0,
257 "*TokenStack::Get(): Leer ist leer, ist leer, ist leer, ist..." );
266 nRet
= pStack
[ nPos
];
273 inline TokenStack
&TokenStack::operator <<( const TokenId nNewId
)
274 {// Element auf Stack
275 DBG_ASSERT( nPos
< nSize
, "*TokenStack::<<(): Stackueberlauf" );
278 pStack
[ nPos
] = nNewId
;
286 inline void TokenStack::operator >>( TokenId
& rId
)
287 {// Element von Stack
288 DBG_ASSERT( nPos
> 0,
289 "*TokenStack::>>(): Leer ist leer, ist leer, ist leer, ..." );
293 rId
= pStack
[ nPos
];
298 inline void TokenStack::Reset( void )
306 inline TokenPool
& TokenPool::operator <<( const TokenId nId
)
308 // POST: nId's werden hintereinander im Pool unter einer neuen Id
309 // abgelegt. Vorgang wird mit >> oder Store() abgeschlossen
310 // nId -> ( UINT16 ) nId - 1;
311 DBG_ASSERT( ( UINT16
) nId
< nScTokenOff
,
312 "-TokenPool::operator <<: TokenId im DefToken-Bereich!" );
314 if( nP_IdAkt
>= nP_Id
)
317 pP_Id
[ nP_IdAkt
] = ( ( UINT16
) nId
) - 1;
324 inline TokenPool
& TokenPool::operator <<( const DefTokenId eId
)
326 DBG_ASSERT( ( UINT32
) eId
+ nScTokenOff
< 0xFFFF,
327 "-TokenPool::operator<<: enmum zu gross!" );
329 if( nP_IdAkt
>= nP_Id
)
332 pP_Id
[ nP_IdAkt
] = ( ( UINT16
) eId
) + nScTokenOff
;
339 inline TokenPool
& TokenPool::operator <<( TokenStack
& rStack
)
341 if( nP_IdAkt
>= nP_Id
)
344 pP_Id
[ nP_IdAkt
] = ( ( UINT16
) rStack
.Get() ) - 1;
351 inline void TokenPool::operator >>( TokenStack
& rStack
)
359 inline const TokenId
TokenPool::Store( void )
367 inline const TokenId
TokenPool::Store( const INT16 nWert
)
369 return Store( ( double ) nWert
);
373 inline const TokenId
TokenPool::LastId( void ) const
375 return ( TokenId
) nElementAkt
; // stimmt, da Ausgabe mit Offset 1!
379 const inline ScTokenArray
* TokenPool::operator []( const TokenId nId
)
384 {//...nur wenn nId > 0!
388 GetElement( ( UINT16
) nId
- 1 );
395 inline E_TYPE
TokenPool::GetType( const TokenId
& rId
) const
399 UINT16 nId
= (UINT16
) rId
- 1;
401 if( nId
< nElementAkt
)
402 nRet
= pType
[ nId
] ;