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: svdosmev.hxx,v $
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 ************************************************************************/
35 #include <tools/bigint.hxx>
38 #ifndef _SV_FIELD_HXX //autogen
39 #include <vcl/field.hxx>
46 ////////////////////////////////////////////////////////////////////////////////////////////////////
49 class SdrObjSmartData
;
50 class ImpSdrExprTokenList
;
51 class ImpSdrExprToken
;
53 class SdrSmartGeometricList
;
54 class SdrSmartGeometric
;
55 class SdrSmartGeometricLine
;
56 class SdrSmartDraftLineList
;
57 class SdrSmartDraftLine
;
58 class SdrSmartGluePointList
;
59 class SdrSmartGluePoint
;
60 class SdrSmartDragPointList
;
61 class SdrSmartDragPoint
;
66 SDREXPRERR_NONE
, // kein Fehler
67 SDREXPRERR_DIVZERO
, // Division durch 0
68 SDREXPRERR_CIRCREF
, // Zirkulare Referenz
69 SDREXPRERR_VALUEEXPECTED
, // Wert erwartet
70 SDREXPRERR_VAREXPECTED
, // Feld oder Speichervariable erwartet
71 SDREXPRERR_VALUETOOBIG
, // Zahlenwert zu gross
72 SDREXPRERR_UNEXPECTEDCHAR
, // unerwartetes Zeichen
73 SDREXPRERR_UNEXPECTEDEOLN
, // unerwartetes Zeilenende
74 SDREXPRERR_UNKNOWNIDENT
, // Unbekannte Funktion oder Variable
75 SDREXPRERR_BRKOPEXPECTED
, // ( erwartet Die 6 Klammern
76 SDREXPRERR_BRKCLEXPECTED
, // ) erwartet muessen genau
77 SDREXPRERR_SQBRKOPEXPECTED
, // [ erwartet in dieser
78 SDREXPRERR_SQBRKCLEXPECTED
, // ] erwartet Reihenfolge und
79 SDREXPRERR_SPBRKOPEXPECTED
, // { erwartet Zusammenhaengend
80 SDREXPRERR_SPBRKCLEXPECTED
, // } erwartet stehen bleiben!
81 SDREXPRERR_PARAMEXPECTED
, // ; und Parameter erwartet
82 SDREXPRERR_ELSEEXPECTED
, // : erwartet
83 SDREXPRERR_MEMBEREXPECTED
, // . oder Member erwartet
84 SDREXPRERR_FALSEMEMBER
, // Falscher Klassen-Member
85 SDREXPRERR_BASEMUSTBEINT
, // Nur ganzzahlige Basen erlaubt
86 SDREXPRERR_BASEMUSTBEPOS
, // Nur positive Basen erlaubt
87 SDREXPRERR_DUPLICATEBASE
, // Nur eine Basis je Wert erlaubt
88 SDREXPRERR_BASECLEXPECTED
, // ] erwartet wegen Zahlenbasis
89 SDREXPRERR_INVALIDFUNCARG
, // Ungültiges Funktionsargument
90 SDREXPRERR_INVALIDDIGIT
, // Unerlaubte Ziffer
91 SDREXPRERR_COMPLEXVALUE
, // x^y: negative Basis, gebrochener Exponent oder Wurzel(-val)
92 SDREXPRERR_DOUBLEDECPOINT
// Zu viele Dezimalpunkte
95 enum SdrExprValueKind
{
96 SDREXPRVALUE_SIMPLE
, // Normale Zahl
97 SDREXPRVALUE_COMPLEX
, // Komplexe Zahl
98 SDREXPRVALUE_UNITS
, // eine Entfernung
99 SDREXPRVALUE_ANGLE
, // ein Winkel in 1/100deg
100 // ab hier nur temporaere Typen fuer Evaluate
101 SDREXPRVALUE_POINT
, // ein Punkt (Units)
102 SDREXPRVALUE_DATE
, // ein Datum
103 SDREXPRVALUE_TIME
, // eine Uhrzeit
104 SDREXPRVALUE_DATETIME
// ein Datum (Y) mit Uhrzeit (X)
107 // todo: FieldPointer fuer Zuweisungen
109 friend class ImpSdrSmartObjEvaluator
;
112 BigInt nX
,nY
; //,nX2,nY2;
113 double fX
,fY
; //,fX2,fY2;
115 FASTBOOL bFloat
; // Switch zwischen BigInt und Float (fuer alle 4 Werte)
120 FASTBOOL bIsField
; // RTTI-Sparversion
121 FASTBOOL bIsFieldPtr
; // Ist Zeiger auf ein Feld oder 2 Felder (X/Y)
122 SdrExprValueKind eKind
;
127 virtual void Undirty(const SdrObject
* pObj
);
129 FASTBOOL
HasUnit() const { return nUnitPower
!=0; }
130 FASTBOOL
IsSameUnit(const SdrExprValue
& rVal
) const;
132 SdrExprValue() { CTor(); }
133 SdrExprValue(double fVal
) { CTor(); SetValue(fVal
); }
134 SdrExprValue(long nVal
) { CTor(); SetValue(nVal
); }
135 SdrExprValue(const BigInt
& nVal
) { CTor(); SetValue(nVal
); }
136 SdrExprValue(double fVal
, FieldUnit eU
) { CTor(); SetUnits(fVal
,eU
); }
137 SdrExprValue(long nVal
, FieldUnit eU
) { CTor(); SetUnits(nVal
,eU
); }
138 SdrExprValue(const BigInt
& n
, FieldUnit eU
) { CTor(); SetUnits(n
,eU
); }
139 SdrExprValue(double fVal
, MapUnit eU
) { CTor(); SetUnits(fVal
,eU
); }
140 SdrExprValue(long nVal
, MapUnit eU
) { CTor(); SetUnits(nVal
,eU
); }
141 SdrExprValue(const BigInt
& n
, MapUnit eU
) { CTor(); SetUnits(n
,eU
); }
142 SdrExprValue(const Point
& P
, MapUnit eU
) { CTor(); SetUnits(P
,eU
); }
143 SdrExprValue(FASTBOOL bVal
) { CTor(); SetBool(bVal
); }
144 SdrExprValue(const Time
& rTime
) { CTor(); SetTime(rTime
); }
145 SdrExprValue(const Date
& rDate
) { CTor(); SetDate(rDate
); }
146 SdrExprValue(const DateTime
& rDateTime
) { CTor(); SetDateTime(rDateTime
); }
147 virtual ~SdrExprValue();
149 const SdrExprValue
& ForceUndirty(const SdrObject
* pObj
) const { if (bDirty
) ((SdrExprValue
*)this)->Undirty(pObj
); return *this; }
150 void SetDirty() { bDirty
=TRUE
; }
151 FASTBOOL
IsDirty() const { return bDirty
; }
152 FASTBOOL
IsField() const { return bIsField
; }
153 FASTBOOL
IsFieldPtr() const { return bIsFieldPtr
; }
155 FASTBOOL
IsLocked(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return bLocked
; }
156 ULONG
GetMSecsUsed(const SdrObject
* pO
) const{ ForceUndirty(pO
); return nMSecsUsed
; }
157 FASTBOOL
HasValue(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return bHasValue
; }
158 SdrExprValueKind
GetExprKind(const SdrObject
* pObj
) const{ForceUndirty(pObj
); return eKind
; }
159 FASTBOOL
IsLong(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return !bFloat
/*&& !nX.IsLong()*/; }
160 FASTBOOL
IsBigInt(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return !bFloat
/*&& nX.IsLong()*/; }
161 FASTBOOL
IsFloat(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return bFloat
; }
162 double GetFloat(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return fX
; }
163 const BigInt
& GetBigInt(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return nX
; }
164 long GetLong(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return long(nX
); }
165 FASTBOOL
GetBool(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return !nX
.IsZero(); }
166 MapUnit
GetCoreMap(const SdrObject
* pObj
) const{ ForceUndirty(pObj
); return eCoreMap
; }
167 FieldUnit
GetUIMap(const SdrObject
* pObj
) const { ForceUndirty(pObj
); return eUIMap
; }
168 FASTBOOL
QuickIsLocked() const { return bLocked
; }
169 ULONG
QuickGetMSecsUsed() const { return nMSecsUsed
; }
170 FASTBOOL
QuickHasValue() const { return bHasValue
; }
171 SdrExprValueKind
QuickGetExprKind() const { return eKind
; }
172 FASTBOOL
QuickIsLong() const { return !bFloat
/*&& !nX.IsLong()*/; }
173 FASTBOOL
QuickIsBigInt() const { return !bFloat
/*&& nX.IsLong()*/; }
174 FASTBOOL
QuickIsFloat() const { return bFloat
; }
175 double QuickGetFloat() const { return fX
; }
176 const BigInt
& QuickGetBigInt() const { return nX
; }
177 long QuickGetLong() const { return long(nX
); }
178 FASTBOOL
QuickGetBool() const { return !nX
.IsZero(); }
179 MapUnit
QuickGetCoreMap() const { return eCoreMap
; }
180 FieldUnit
QuickGetUIMap() const { return eUIMap
; }
182 long QuickGetUnits(const BigInt
& rVal
, MapUnit eU
) const;
183 long QuickGetUnits(double nVal
, MapUnit eU
) const;
184 double QuickGetFloatNoUnits(const BigInt
& rVal
) const;
185 double QuickGetFloatNoUnits(double nVal
) const;
187 long GetUnits(MapUnit eU
, const SdrObject
* pObj
) const { ForceUndirty(pObj
); return QuickGetUnits(eU
); }
188 long QuickGetUnits(MapUnit eU
) const;
189 long QuickGetLongNoUnits() const { return (long)QuickGetFloatNoUnits(); }
190 double QuickGetFloatNoUnits() const;
192 Time
QuickGetTime() const;
193 Date
QuickGetDate() const;
194 DateTime
QuickGetDateTime() const;
196 FASTBOOL
QuickIsDate() const { return eKind
==SDREXPRVALUE_DATE
; }
197 FASTBOOL
QuickIsTime() const { return eKind
==SDREXPRVALUE_TIME
; }
198 FASTBOOL
QuickIsDateTime() const { return eKind
==SDREXPRVALUE_DATETIME
; }
199 FASTBOOL
QuickIsDateOrTime() const { return eKind
==SDREXPRVALUE_DATE
|| eKind
==SDREXPRVALUE_TIME
|| eKind
==SDREXPRVALUE_DATETIME
; }
200 BigInt
QuickGetDateTimeMSecs() const;
202 void SetExprKind(SdrExprValueKind eNew
) { eKind
=eNew
; }
206 void SetValue(double fVal
);
207 void SetValue(long nVal
);
208 void SetValue(const BigInt
& nVal
);
210 void SetUnits(double fVal
, FieldUnit eU
);
211 void SetUnits(long nVal
, FieldUnit eU
);
212 void SetUnits(const BigInt
& n
, FieldUnit eU
);
214 void SetUnits(double fVal
, MapUnit eU
);
215 void SetUnits(long nVal
, MapUnit eU
);
216 void SetUnits(const BigInt
& n
, MapUnit eU
);
217 void SetUnits(const Point
& P
, MapUnit eU
);
219 void SetBool(FASTBOOL bVal
);
220 void SetTime(const Time
& rTime
);
221 void SetDate(const Date
& rDate
);
222 void SetDateTime(const DateTime
& rDateTime
);
224 /* const SdrObject* GetObject () const { return (const SdrObject* )pPointer; }
225 const SdrObjList* GetObjList () const { return (const SdrObjList* )pPointer; }
226 const SdrSmartGeometricList* GetGeometricList() const { return (const SdrSmartGeometricList*)pPointer; }
227 const SdrSmartGeometric* GetGeometricArea() const { return (const SdrSmartGeometric* )pPointer; }
228 const SdrSmartGeometricLine* GetGeometricLine() const { return (const SdrSmartGeometricLine*)pPointer; }
229 const SdrSmartDraftLineList* GetDraftArea () const { return (const SdrSmartDraftLineList*)pPointer; }
230 const SdrSmartDraftLine* GetDraftLine () const { return (const SdrSmartDraftLine* )pPointer; }
231 const SdrSmartGluePointList* GetGlueArea () const { return (const SdrSmartGluePointList*)pPointer; }
232 const SdrSmartGluePoint* GetGlueLine () const { return (const SdrSmartGluePoint* )pPointer; }
233 const SdrSmartDragPointList* GetDragArea () const { return (const SdrSmartDragPointList*)pPointer; }
234 const SdrSmartDragPoint* GetDragLine () const { return (const SdrSmartDragPoint* )pPointer; }
235 void SetObject (const SdrObject* pObj ) { pPointer=pObj; eKind=SDREXPRVALUE_OBJECT; }
236 void SetObjList (const SdrObjList* pObjList ) { pPointer=pObjList; eKind=SDREXPRVALUE_OBJLIST; }
237 void SetGeometricList(const SdrSmartGeometricList* pGeos ) { pPointer=pGeos; eKind=SDREXPRVALUE_GEOMETRICS; }
238 void SetGeometricArea(const SdrSmartGeometric* pGeo ) { pPointer=pGeo; eKind=SDREXPRVALUE_GEOMETRIC; }
239 void SetGeometricLine(const SdrSmartGeometricLine* pGeoLine ) { pPointer=pGeoLine; eKind=SDREXPRVALUE_GEOLINE; }
240 void SetDraftArea (const SdrSmartDraftLineList* pDraftArea) { pPointer=pDraftArea; eKind=SDREXPRVALUE_DRAFTAREA; }
241 void SetDraftLine (const SdrSmartDraftLine* pDraftLine) { pPointer=pDraftLine; eKind=SDREXPRVALUE_DRAFTAREALINE; }
242 void SetGlueArea (const SdrSmartGluePointList* pGlueArea ) { pPointer=pGlueArea; eKind=SDREXPRVALUE_GLUEAREA; }
243 void SetGlueLine (const SdrSmartGluePoint* pGlueLine ) { pPointer=pGlueLine; eKind=SDREXPRVALUE_GLUEAREALINE; }
244 void SetDragArea (const SdrSmartDragPointList* pDragArea ) { pPointer=pDragArea; eKind=SDREXPRVALUE_DRAGAREA; }
245 void SetDragLine (const SdrSmartDragPoint* pDragLine ) { pPointer=pDragLine; eKind=SDREXPRVALUE_DRAGAREALINE; }*/
247 void operator+=(const SdrExprValue
& rVal
);
248 void operator-=(const SdrExprValue
& rVal
);
249 void operator*=(const SdrExprValue
& rVal
);
250 void operator/=(const SdrExprValue
& rVal
);
251 void operator%=(const SdrExprValue
& rVal
);
252 FASTBOOL
operator==(const SdrExprValue
& rVal
) const;
253 FASTBOOL
operator!=(const SdrExprValue
& rVal
) const { return !operator==(rVal
); }
254 FASTBOOL
operator==(double fVal
) const;
255 FASTBOOL
operator!=(double fVal
) const { return !operator==(fVal
); }
256 FASTBOOL
operator==(long nVal
) const;
257 FASTBOOL
operator!=(long nVal
) const { return !operator==(nVal
); }
258 FASTBOOL
operator==(const BigInt
& nVal
) const;
259 FASTBOOL
operator!=(const BigInt
& nVal
) const { return !operator==(nVal
); }
260 FASTBOOL
operator> (const SdrExprValue
& rVal
) const;
261 FASTBOOL
operator>=(const SdrExprValue
& rVal
) const;
262 FASTBOOL
operator< (const SdrExprValue
& rVal
) const { return !operator>=(rVal
); }
263 FASTBOOL
operator<=(const SdrExprValue
& rVal
) const { return !operator>(rVal
); }
264 FASTBOOL
operator> (double fVal
) const;
265 FASTBOOL
operator>=(double fVal
) const;
266 FASTBOOL
operator< (double fVal
) const { return !operator>=(fVal
); }
267 FASTBOOL
operator<=(double fVal
) const { return !operator>(fVal
); }
268 FASTBOOL
operator> (long nVal
) const;
269 FASTBOOL
operator>=(long nVal
) const;
270 FASTBOOL
operator< (long nVal
) const { return !operator>=(nVal
); }
271 FASTBOOL
operator<=(long nVal
) const { return !operator>(nVal
); }
272 FASTBOOL
operator> (const BigInt
& nVal
) const;
273 FASTBOOL
operator>=(const BigInt
& nVal
) const;
274 FASTBOOL
operator< (const BigInt
& nVal
) const { return !operator>=(nVal
); }
275 FASTBOOL
operator<=(const BigInt
& nVal
) const { return !operator>(nVal
); }
278 /*class ImpSdrSmartObjEvaluator0 {
280 const SdrObject* pObj;
281 const SdrObjSmartData* pSmart;
282 SdrExprErrKind eError;
286 SdrExprValue aResult;
287 //FASTBOOL bHasValue;
298 void Error(USHORT nEPos, SdrExprErrKind eECode);
299 FASTBOOL CharsLeft() const { return nPos<aStr.Len(); }
309 ImpSdrSmartObjEvaluator0(const SdrObject* pObj_);
310 void SetMetric(FASTBOOL bOn) { bMetric=bOn; bMetricX=FALSE; bMetricY=FALSE; }
311 void SetMetricX(FASTBOOL bOn) { bMetric=bOn; bMetricX=TRUE; bMetricY=FALSE; }
312 void SetMetricY(FASTBOOL bOn) { bMetric=bOn; bMetricX=FALSE; bMetricY=TRUE; }
313 FASTBOOL Evaluate(const String& rStr);
314 // double GetFloatValue() const { return aResult.fValue; }
315 // long GetIntValue() const { return aResult.nValue; }
316 // long GetUnitValue() const { return aResult.nUnitValue; }
317 FASTBOOL HasValue() const { return aResult.HasValue(pObj); }
318 FASTBOOL IsLocked() const { return aResult.IsLocked(pObj); }
319 FASTBOOL IsError() const { return eError!=SDREXPRERR_NONE; }
320 SdrExprErrKind GetError() const { return eError; }
321 USHORT GetErrorPos() const { return nErrPos; }
322 const SdrExprValue& GetResult() const { return aResult; }
325 class ImpSdrSmartObjEvaluator
{
326 friend class ImpZwischenergebnis
;
327 const ImpSdrExprTokenList
* pTokenList
;
328 const SdrObject
* pObj
;
329 const SdrObjSmartData
* pSmart
;
330 const ImpSdrExprToken
* pAktTok
;
331 const SdrExprValue
* pTargetField
; // Zur Bestimmung der AktLine, ..., anhand pObj
332 SdrExprErrKind eError
;
336 SdrExprValue aResult
;
342 // Feldlokation in Geo,Draft,Vars,Glue oder Drag
343 FASTBOOL bFieldLocationSearched
;
344 FASTBOOL bFieldLocationFound
;
345 USHORT nFieldArea
; // eigentlich enum ...
346 ULONG nGeoFieldAreaNum
;
349 ULONG nMSecsUsed
; // Falls nur Date, dann =86400000 (ms/Tag)
352 void SetMSecsUsed(ULONG n
);
353 void SearchFieldLocation();
354 void ForceFieldLocation() const { if (!bFieldLocationSearched
) ((ImpSdrSmartObjEvaluator
*)this)->SearchFieldLocation(); }
355 void Error(ULONG nEPos
, SdrExprErrKind eECode
);
356 FASTBOOL
TokensLeft() const { return nPos
<nAnz
; }
357 const ImpSdrExprToken
* NextToken();
358 FASTBOOL
BracketOpen();
359 FASTBOOL
BracketClose(USHORT eOpen
);
360 FASTBOOL
NextArg(SdrExprValue
*& pArg
, FASTBOOL bSkip
);
361 void FuncRound(FASTBOOL bSkip
, double nRet
, SdrExprValue
* pRet
, SdrExprValue
*& pArg
);
362 void FuncRandom(FASTBOOL bSkip
, FASTBOOL bBracket
, double nRet
, SdrExprValue
* pRet
, SdrExprValue
*& pArg
);
363 SdrExprValue
* Memb(FASTBOOL bSkip
);
364 SdrExprValue
* Func(FASTBOOL bSkip
);
365 SdrExprValue
* Wert(FASTBOOL bSkip
);
366 SdrExprValue
* Fakt(FASTBOOL bSkip
);
367 SdrExprValue
* Term(FASTBOOL bSkip
);
368 SdrExprValue
* Expr2(FASTBOOL bSkip
);
369 SdrExprValue
* CompTerm(FASTBOOL bSkip
);
370 SdrExprValue
* BoolFakt(FASTBOOL bSkip
);
371 SdrExprValue
* BoolXTerm(FASTBOOL bSkip
);
372 SdrExprValue
* BoolTerm(FASTBOOL bSkip
);
373 SdrExprValue
* Condition(FASTBOOL bSkip
);
374 SdrExprValue
* Expr(FASTBOOL bSkip
);
376 ImpSdrSmartObjEvaluator(const SdrObject
* pObj_
);
377 void SetMetric(FASTBOOL bOn
) { bMetric
=bOn
; bMetricX
=FALSE
; bMetricY
=FALSE
; }
378 void SetMetricX(FASTBOOL bOn
) { bMetric
=bOn
; bMetricX
=TRUE
; bMetricY
=FALSE
; }
379 void SetMetricY(FASTBOOL bOn
) { bMetric
=bOn
; bMetricX
=FALSE
; bMetricY
=TRUE
; }
380 FASTBOOL
Evaluate(const ImpSdrExprTokenList
* pTokenList_
, const SdrExprValue
* pTargetField_
);
381 FASTBOOL
HasValue() const { return aResult
.HasValue(pObj
); }
382 FASTBOOL
IsLocked() const { return aResult
.IsLocked(pObj
); }
383 FASTBOOL
IsError() const { return eError
!=SDREXPRERR_NONE
; }
384 SdrExprErrKind
GetError() const { return eError
; }
385 static XubString
GetErrorStr(SdrExprErrKind eErr
);
386 XubString
GetErrorStr() const { return GetErrorStr(eError
); }
387 ULONG
GetErrorPos() const { return nErrPos
; }
388 const SdrExprValue
& GetResult() const { return aResult
; }
389 MapUnit
GetCoreMap() const { return eCoreMap
; }
390 const SdrObject
* GetObject() const { return pObj
; }
391 const SdrObjSmartData
* GetSmartData() const { return pSmart
; }
392 ULONG
GetMSecsUsed() const { return nMSecsUsed
; }
395 ////////////////////////////////////////////////////////////////////////////////////////////////////
397 }//end of namespace binfilter
398 #endif //_SVDOSMEV_HXX