xref: /trunk/main/sc/source/filter/inc/formel.hxx (revision a396abfd)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_FORMEL_HXX
25 #define SC_FORMEL_HXX
26 
27 #include <tools/solar.h>
28 #include <tools/list.hxx>
29 #include <tools/string.hxx>
30 #include "tokstack.hxx"
31 #include "root.hxx"
32 #include <global.hxx>
33 #include <compiler.hxx>
34 
35 
36 // ----- forwards --------------------------------------------------------
37 
38 class XclImpStream;
39 class ScTokenArray;
40 class ScFormulaCell;
41 struct ScSingleRefData;
42 struct ScComplexRefData;
43 
44 
45 
46 
47 //------------------------------------------------------------------------
48 
49 enum ConvErr
50 {
51 	ConvOK = 0,
52 	ConvErrNi,		// nicht implemntierter/unbekannter Opcode aufgetreten
53 	ConvErrNoMem,	// Fehler beim Speicheranfordern
54 	ConvErrExternal,// Add-Ins aus Excel werden nicht umgesetzt
55 	ConvErrCount	// Nicht alle Bytes der Formel 'erwischt'
56 };
57 
58 
59 enum FORMULA_TYPE
60 {
61 	FT_CellFormula,
62 	FT_RangeName,
63 	FT_SharedFormula,
64 	FT_Conditional
65 };
66 
67 
68 
69 
70 //--------------------------------------------------------- class ScRangeList -
71 
72 class _ScRangeList : protected List
73 {
74 private:
75 protected:
76 public:
77 	virtual					~_ScRangeList();
78 	inline void				Append( const ScRange& rRange );
79 	inline void				Append( ScRange* pRange );
80 	inline void				Append( const ScSingleRefData& rSRD );
81 	inline void				Append( const ScComplexRefData& rCRD );
82 
83     using                   List::Count;
84 	inline sal_Bool				HasRanges( void ) const;
85 
86 	inline const ScRange*	First( void );
87 	inline const ScRange*	Next( void );
88 };
89 
90 
Append(const ScRange & r)91 inline void _ScRangeList::Append( const ScRange& r )
92 {
93 	List::Insert( new ScRange( r ), LIST_APPEND );
94 }
95 
96 
Append(ScRange * p)97 inline void _ScRangeList::Append( ScRange* p )
98 {
99 	List::Insert( p, LIST_APPEND );
100 }
101 
102 
HasRanges(void) const103 inline sal_Bool _ScRangeList::HasRanges( void ) const
104 {
105 	return Count() > 0;
106 }
107 
108 
First(void)109 inline const ScRange* _ScRangeList::First( void )
110 {
111 	return ( const ScRange* ) List::First();
112 }
113 
114 
Next(void)115 inline const ScRange* _ScRangeList::Next( void )
116 {
117 	return ( const ScRange* ) List::Next();
118 }
119 
120 
Append(const ScSingleRefData & r)121 inline void _ScRangeList::Append( const ScSingleRefData& r )
122 {
123 	List::Insert( new ScRange( r.nCol, r.nRow, r.nTab ), LIST_APPEND );
124 }
125 
126 
Append(const ScComplexRefData & r)127 inline void _ScRangeList::Append( const ScComplexRefData& r )
128 {
129 	List::Insert(	new ScRange(	r.Ref1.nCol, r.Ref1.nRow, r.Ref1.nTab,
130 									r.Ref2.nCol, r.Ref2.nRow, r.Ref2.nTab ),
131 					LIST_APPEND );
132 }
133 
134 
135 
136 
137 //----------------------------------------------------- class ScRangeListTabs -
138 
139 class _ScRangeListTabs
140 {
141 private:
142 protected:
143 	sal_Bool						bHasRanges;
144 	_ScRangeList**				ppTabLists;
145 	_ScRangeList*				pAct;
146 	sal_uInt16						nAct;
147 public:
148 								_ScRangeListTabs( void );
149 	virtual						~_ScRangeListTabs();
150 
151 	void						Append( ScSingleRefData aSRD, const sal_Bool bLimit = sal_True );
152 	void						Append( ScComplexRefData aCRD, const sal_Bool bLimit = sal_True );
153 
154 	inline sal_Bool					HasRanges( void ) const;
155 
156 	const ScRange*				First( const sal_uInt16 nTab = 0 );
157 	const ScRange*				Next( void );
158 //		const ScRange*				NextContinue( void );
159 	inline const _ScRangeList*	GetActList( void ) const;
160 };
161 
162 
HasRanges(void) const163 inline sal_Bool _ScRangeListTabs::HasRanges( void ) const
164 {
165 	return bHasRanges;
166 }
167 
168 
GetActList(void) const169 inline const _ScRangeList* _ScRangeListTabs::GetActList( void ) const
170 {
171 	return pAct;
172 }
173 
174 
175 
176 
177 class ConverterBase
178 {
179 protected:
180 	TokenPool			aPool;			// User Token + Predefined Token
181 	TokenStack			aStack;
182     ScAddress           aEingPos;
183     ConvErr             eStatus;
184 	sal_Char*			pBuffer;		// Universal-Puffer
185 	sal_uInt16				nBufferSize;	// ...und seine Groesse
186 
187 						ConverterBase( sal_uInt16 nNewBuffer );
188 	virtual				~ConverterBase();
189 
190 	void				Reset();
191 
192 public:
GetEingabeCol(void) const193 	inline SCCOL		GetEingabeCol( void ) const	{ return aEingPos.Col(); }
GetEingabeRow(void) const194 	inline SCROW		GetEingabeRow( void ) const	{ return aEingPos.Row(); }
GetEingabeTab(void) const195 	inline SCTAB		GetEingabeTab( void ) const	{ return aEingPos.Tab(); }
GetEingPos(void) const196 	inline ScAddress	GetEingPos( void ) const	{ return aEingPos; }
197 };
198 
199 
200 
201 class ExcelConverterBase : public ConverterBase
202 {
203 protected:
204                         ExcelConverterBase( sal_uInt16 nNewBuffer );
205 	virtual				~ExcelConverterBase();
206 
207 public:
208 	void	 			Reset();
209     void                Reset( const ScAddress& rEingPos );
210 
211     virtual ConvErr     Convert( const ScTokenArray*& rpErg, XclImpStream& rStrm, sal_Size nFormulaLen,
212                                  bool bAllowArrays, const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
213     virtual ConvErr     Convert( _ScRangeListTabs&, XclImpStream& rStrm, sal_Size nFormulaLen,
214 									const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
215 };
216 
217 
218 
219 class LotusConverterBase : public ConverterBase
220 {
221 protected:
222 	SvStream&			aIn;
223 	sal_Int32				nBytesLeft;
224 
225 	inline void			Ignore( const long nSeekRel );
226 	inline void			Read( sal_Char& nByte );
227 	inline void			Read( sal_uInt8& nByte );
228 	inline void			Read( sal_uInt16& nUINT16 );
229 	inline void			Read( sal_Int16& nINT16 );
230 	inline void			Read( double& fDouble );
231         inline void                     Read( sal_uInt32& nUINT32 );
232 
233 						LotusConverterBase( SvStream& rStr, sal_uInt16 nNewBuffer );
234 	virtual				~LotusConverterBase();
235 
236 public:
237 //UNUSED2008-05  void                Reset( sal_Int32 nLen );
238 //UNUSED2008-05  void                Reset( sal_Int32 nLen, const ScAddress& rEingPos );
239     void                Reset( const ScAddress& rEingPos );
240 
241 	virtual ConvErr		Convert( const ScTokenArray*& rpErg, sal_Int32& nRest,
242 									const FORMULA_TYPE eFT = FT_CellFormula ) = 0;
243 
244 protected:
245     using               ConverterBase::Reset;
246 };
247 
248 
Ignore(const long nSeekRel)249 inline void LotusConverterBase::Ignore( const long nSeekRel )
250 {
251 	aIn.SeekRel( nSeekRel );
252 	nBytesLeft -= nSeekRel;
253 }
254 
Read(sal_Char & nByte)255 inline void LotusConverterBase::Read( sal_Char& nByte )
256 {
257 	aIn >> nByte;
258 	nBytesLeft--;
259 }
260 
Read(sal_uInt8 & nByte)261 inline void LotusConverterBase::Read( sal_uInt8& nByte )
262 {
263 	aIn >> nByte;
264 	nBytesLeft--;
265 }
266 
Read(sal_uInt16 & nUINT16)267 inline void LotusConverterBase::Read( sal_uInt16& nUINT16 )
268 {
269 	aIn >> nUINT16;
270 	nBytesLeft -= 2;
271 }
272 
Read(sal_Int16 & nINT16)273 inline void LotusConverterBase::Read( sal_Int16& nINT16 )
274 {
275 	aIn >> nINT16;
276 	nBytesLeft -= 2;
277 }
278 
Read(double & fDouble)279 inline void LotusConverterBase::Read( double& fDouble )
280 {
281 	aIn >> fDouble;
282 	nBytesLeft -= 8;
283 }
284 
Read(sal_uInt32 & nUINT32)285 inline void LotusConverterBase::Read( sal_uInt32& nUINT32 )
286 {
287 	aIn >> nUINT32;
288 	nBytesLeft -= 4;
289 }
290 
291 #endif
292 
293 
294