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 _SBXVAR_HXX 25 #define _SBXVAR_HXX 26 27 #include <rtl/ustring.hxx> 28 #include <tools/string.hxx> 29 #include <com/sun/star/bridge/oleautomation/Decimal.hpp> 30 #include <basic/sbxcore.hxx> 31 32 #ifndef __SBX_64 33 #define __SBX_64 34 35 struct SbxINT64 36 { 37 sal_Int32 nHigh; sal_uInt32 nLow; 38 39 #if FALSE 40 SbxINT64() : nHigh( 0 ), nLow( 0 ) {} 41 SbxINT64( sal_uInt8 n ) : nHigh( 0 ), nLow( n ) {} 42 SbxINT64( sal_uInt16 n ) : nHigh( 0 ), nLow( n ) {} 43 SbxINT64( sal_uInt32 n ) : nHigh( 0 ), nLow( n ) {} 44 SbxINT64( unsigned int n ) : nHigh( 0 ), nLow( n ) {} 45 SbxINT64( sal_Int8 n ) : nHigh( n < 0 ? -1 : 0 ), nLow( n ) {} 46 SbxINT64( sal_Int16 n ) : nHigh( n < 0 ? -1 : 0 ), nLow( n ) {} 47 SbxINT64( sal_Int32 n ) : nHigh( n < 0 ? -1 : 0 ), nLow( n ) {} 48 SbxINT64( int n ) : nHigh( n < 0 ? -1 : 0 ), nLow( n ) {} 49 SbxINT64( SbxINT64 &r ) : nHigh( r.nHigh ), nLow( r.nLow ) {} 50 51 SbxINT64( BigInt &r ); 52 SbxINT64( double n ); 53 #endif 54 void CHS() 55 { 56 nLow ^= (sal_uInt32)-1; 57 nHigh ^= -1; 58 nLow++; 59 if( !nLow ) 60 nHigh++; 61 } 62 63 // blc/os2i do not like operator = 64 void Set(double n) 65 { 66 if( n >= 0 ) 67 { 68 nHigh = (sal_Int32)(n / (double)4294967296.0); 69 nLow = (sal_uInt32)(n - ((double)nHigh * (double)4294967296.0) + 0.5); 70 } 71 else { 72 nHigh = (sal_Int32)(-n / (double)4294967296.0); 73 nLow = (sal_uInt32)(-n - ((double)nHigh * (double)4294967296.0) + 0.5); 74 CHS(); 75 } 76 } 77 void Set(sal_Int32 n) { nHigh = n < 0 ? -1 : 0; nLow = n; } 78 79 void SetMax() { nHigh = 0x7FFFFFFF; nLow = 0xFFFFFFFF; } 80 void SetMin() { nHigh = 0x80000000; nLow = 0x00000000; } 81 void SetNull() { nHigh = 0x00000000; nLow = 0x00000000; } 82 83 int operator ! () const { return !nHigh && !nLow; } 84 85 SbxINT64 &operator -= ( const SbxINT64 &r ); 86 SbxINT64 &operator += ( const SbxINT64 &r ); 87 SbxINT64 &operator /= ( const SbxINT64 &r ); 88 SbxINT64 &operator %= ( const SbxINT64 &r ); 89 SbxINT64 &operator *= ( const SbxINT64 &r ); 90 SbxINT64 &operator &= ( const SbxINT64 &r ); 91 SbxINT64 &operator |= ( const SbxINT64 &r ); 92 SbxINT64 &operator ^= ( const SbxINT64 &r ); 93 94 friend SbxINT64 operator - ( const SbxINT64 &l, const SbxINT64 &r ); 95 friend SbxINT64 operator + ( const SbxINT64 &l, const SbxINT64 &r ); 96 friend SbxINT64 operator / ( const SbxINT64 &l, const SbxINT64 &r ); 97 friend SbxINT64 operator % ( const SbxINT64 &l, const SbxINT64 &r ); 98 friend SbxINT64 operator * ( const SbxINT64 &l, const SbxINT64 &r ); 99 friend SbxINT64 operator & ( const SbxINT64 &l, const SbxINT64 &r ); 100 friend SbxINT64 operator | ( const SbxINT64 &l, const SbxINT64 &r ); 101 friend SbxINT64 operator ^ ( const SbxINT64 &l, const SbxINT64 &r ); 102 103 friend SbxINT64 operator - ( const SbxINT64 &r ); 104 friend SbxINT64 operator ~ ( const SbxINT64 &r ); 105 106 static double GetMin() { return ((double)0x7FFFFFFF*(double)4294967296.0 107 + (double)0xFFFFFFFF) 108 / CURRENCY_FACTOR; } 109 static double GetMax() { return ((double)0x80000000*(double)4294967296.0 110 + (double)0xFFFFFFFF) 111 / CURRENCY_FACTOR; } 112 }; 113 114 struct SbxUINT64 115 { 116 sal_uInt32 nHigh; sal_uInt32 nLow; 117 void Set(double n) 118 { 119 nHigh = (sal_uInt32)(n / (double)4294967296.0); 120 nLow = (sal_uInt32)(n - ((double)nHigh * (double)4294967296.0)); 121 } 122 123 void Set(sal_uInt32 n) { nHigh = 0; nLow = n; } 124 125 void SetMax() { nHigh = 0xFFFFFFFF; nLow = 0xFFFFFFFF; } 126 void SetMin() { nHigh = 0x00000000; nLow = 0x00000000; } 127 void SetNull() { nHigh = 0x00000000; nLow = 0x00000000; } 128 129 int operator ! () const { return !nHigh && !nLow; } 130 131 SbxUINT64 &operator -= ( const SbxUINT64 &r ); 132 SbxUINT64 &operator += ( const SbxUINT64 &r ); 133 SbxUINT64 &operator /= ( const SbxUINT64 &r ); 134 SbxUINT64 &operator %= ( const SbxUINT64 &r ); 135 SbxUINT64 &operator *= ( const SbxUINT64 &r ); 136 SbxUINT64 &operator &= ( const SbxUINT64 &r ); 137 SbxUINT64 &operator |= ( const SbxUINT64 &r ); 138 SbxUINT64 &operator ^= ( const SbxUINT64 &r ); 139 140 friend SbxUINT64 operator - ( const SbxUINT64 &l, const SbxUINT64 &r ); 141 friend SbxUINT64 operator + ( const SbxUINT64 &l, const SbxUINT64 &r ); 142 friend SbxUINT64 operator / ( const SbxUINT64 &l, const SbxUINT64 &r ); 143 friend SbxUINT64 operator % ( const SbxUINT64 &l, const SbxUINT64 &r ); 144 friend SbxUINT64 operator * ( const SbxUINT64 &l, const SbxUINT64 &r ); 145 friend SbxUINT64 operator & ( const SbxUINT64 &l, const SbxUINT64 &r ); 146 friend SbxUINT64 operator | ( const SbxUINT64 &l, const SbxUINT64 &r ); 147 friend SbxUINT64 operator ^ ( const SbxUINT64 &l, const SbxUINT64 &r ); 148 149 friend SbxUINT64 operator ~ ( const SbxUINT64 &r ); 150 }; 151 152 #endif 153 154 #ifndef __SBX_SBXVALUES_HXX 155 #define __SBX_SBXVALUES_HXX 156 157 class BigInt; 158 class SbxDecimal; 159 160 struct SbxValues 161 { 162 union { 163 sal_Unicode nChar; 164 sal_uInt8 nByte; 165 sal_Int16 nInteger; 166 sal_Int32 nLong; 167 sal_uInt16 nUShort; 168 sal_uInt32 nULong; 169 float nSingle; 170 double nDouble; 171 SbxINT64 nLong64; 172 SbxUINT64 nULong64; 173 sal_Int64 nInt64; 174 sal_uInt64 uInt64; 175 int nInt; 176 unsigned int nUInt; 177 ::rtl::OUString* pOUString; 178 SbxDecimal* pDecimal; 179 180 SbxBase* pObj; 181 sal_Unicode* pChar; 182 sal_uInt8* pByte; 183 sal_Int16* pInteger; 184 sal_Int32* pLong; 185 sal_uInt16* pUShort; 186 sal_uInt32* pULong; 187 float* pSingle; 188 double* pDouble; 189 SbxINT64* pLong64; 190 SbxUINT64* pULong64; 191 sal_Int64* pnInt64; 192 sal_uInt64* puInt64; 193 int* pInt; 194 unsigned int* pUInt; 195 void* pData; 196 }; 197 SbxDataType eType; 198 199 SbxValues(): pData( NULL ), eType(SbxEMPTY) {} 200 SbxValues( SbxDataType e ): eType(e) {} 201 SbxValues( char _nChar ): nChar( _nChar ), eType(SbxCHAR) {} 202 SbxValues( sal_uInt8 _nByte ): nByte( _nByte ), eType(SbxBYTE) {} 203 SbxValues( short _nInteger ): nInteger( _nInteger ), eType(SbxINTEGER ) {} 204 SbxValues( long _nLong ): nLong( _nLong ), eType(SbxLONG) {} 205 SbxValues( sal_uInt16 _nUShort ): nUShort( _nUShort ), eType(SbxUSHORT) {} 206 SbxValues( sal_uIntPtr _nULong ): nULong( _nULong ), eType(SbxULONG) {} 207 SbxValues( float _nSingle ): nSingle( _nSingle ), eType(SbxSINGLE) {} 208 SbxValues( double _nDouble ): nDouble( _nDouble ), eType(SbxDOUBLE) {} 209 SbxValues( int _nInt ): nInt( _nInt ), eType(SbxINT) {} 210 SbxValues( unsigned int _nUInt ): nUInt( _nUInt ), eType(SbxUINT) {} 211 SbxValues( const ::rtl::OUString* _pString ): pOUString( (::rtl::OUString*)_pString ), eType(SbxSTRING) {} 212 SbxValues( SbxBase* _pObj ): pObj( _pObj ), eType(SbxOBJECT) {} 213 SbxValues( sal_Unicode* _pChar ): pChar( _pChar ), eType(SbxLPSTR) {} 214 SbxValues( void* _pData ): pData( _pData ), eType(SbxPOINTER) {} 215 SbxValues( const BigInt &rBig ); 216 }; 217 218 #endif 219 220 #ifndef __SBX_SBXVALUE 221 #define __SBX_SBXVALUE 222 223 struct SbxValues; 224 225 class SbxValueImpl; 226 227 class SbxValue : public SbxBase 228 { 229 SbxValueImpl* mpSbxValueImplImpl; // Impl data 230 231 // #55226 Transport additional infos 232 SbxValue* TheRealValue( sal_Bool bObjInObjError ) const; 233 SbxValue* TheRealValue() const; 234 protected: 235 SbxValues aData; // Data 236 ::rtl::OUString aPic; // Picture-String 237 String aToolString; // tool string copy 238 239 virtual void Broadcast( sal_uIntPtr ); // Broadcast-Call 240 virtual ~SbxValue(); 241 virtual sal_Bool LoadData( SvStream&, sal_uInt16 ); 242 virtual sal_Bool StoreData( SvStream& ) const; 243 public: 244 SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_VALUE,1); 245 TYPEINFO(); 246 SbxValue(); 247 SbxValue( SbxDataType, void* = NULL ); 248 SbxValue( const SbxValue& ); 249 SbxValue& operator=( const SbxValue& ); 250 virtual void Clear(); 251 virtual sal_Bool IsFixed() const; 252 253 sal_Bool IsInteger() const { return sal_Bool( GetType() == SbxINTEGER ); } 254 sal_Bool IsLong() const { return sal_Bool( GetType() == SbxLONG ); } 255 sal_Bool IsSingle() const { return sal_Bool( GetType() == SbxSINGLE ); } 256 sal_Bool IsDouble() const { return sal_Bool( GetType() == SbxDOUBLE ); } 257 sal_Bool IsString() const { return sal_Bool( GetType() == SbxSTRING ); } 258 sal_Bool IsDate() const { return sal_Bool( GetType() == SbxDATE ); } 259 sal_Bool IsCurrency()const { return sal_Bool( GetType() == SbxCURRENCY ); } 260 sal_Bool IsObject() const { return sal_Bool( GetType() == SbxOBJECT ); } 261 sal_Bool IsDataObject()const{return sal_Bool( GetType() == SbxDATAOBJECT);} 262 sal_Bool IsBool() const { return sal_Bool( GetType() == SbxBOOL ); } 263 sal_Bool IsErr() const { return sal_Bool( GetType() == SbxERROR ); } 264 sal_Bool IsEmpty() const { return sal_Bool( GetType() == SbxEMPTY ); } 265 sal_Bool IsNull() const { return sal_Bool( GetType() == SbxNULL ); } 266 sal_Bool IsChar() const { return sal_Bool( GetType() == SbxCHAR ); } 267 sal_Bool IsByte() const { return sal_Bool( GetType() == SbxBYTE ); } 268 sal_Bool IsUShort() const { return sal_Bool( GetType() == SbxUSHORT ); } 269 sal_Bool IsULong() const { return sal_Bool( GetType() == SbxULONG ); } 270 sal_Bool IsInt() const { return sal_Bool( GetType() == SbxINT ); } 271 sal_Bool IsUInt() const { return sal_Bool( GetType() == SbxUINT ); } 272 sal_Bool IspChar() const { return sal_Bool( GetType() == SbxLPSTR ); } 273 sal_Bool IsNumeric() const; 274 sal_Bool IsNumericRTL() const; // #41692 Interface for Basic 275 sal_Bool ImpIsNumeric( sal_Bool bOnlyIntntl ) const; // Implementation 276 277 virtual SbxClassType GetClass() const; 278 virtual SbxDataType GetType() const; 279 SbxDataType GetFullType() const; 280 sal_Bool SetType( SbxDataType ); 281 282 virtual sal_Bool Get( SbxValues& ) const; 283 sal_Bool GetNoBroadcast( SbxValues& ); 284 const SbxValues& GetValues_Impl() const { return aData; } 285 virtual sal_Bool Put( const SbxValues& ); 286 287 inline SbxValues * data() { return &aData; } 288 289 SbxINT64 GetCurrency() const; 290 SbxINT64 GetLong64() const; 291 SbxUINT64 GetULong64() const; 292 sal_Int64 GetInt64() const; 293 sal_uInt64 GetUInt64() const; 294 sal_Int16 GetInteger() const; 295 sal_Int32 GetLong() const; 296 float GetSingle() const; 297 double GetDouble() const; 298 double GetDate() const; 299 sal_Bool GetBool() const; 300 sal_uInt16 GetErr() const; 301 const String& GetString() const; 302 const String& GetCoreString() const; 303 ::rtl::OUString GetOUString() const; 304 SbxDecimal* GetDecimal() const; 305 SbxBase* GetObject() const; 306 sal_Bool HasObject() const; 307 void* GetData() const; 308 sal_Unicode GetChar() const; 309 sal_uInt8 GetByte() const; 310 sal_uInt16 GetUShort() const; 311 sal_uInt32 GetULong() const; 312 int GetInt() const; 313 314 sal_Bool PutCurrency( const SbxINT64& ); 315 sal_Bool PutLong64( const SbxINT64& ); 316 sal_Bool PutULong64( const SbxUINT64& ); 317 sal_Bool PutInt64( sal_Int64 ); 318 sal_Bool PutUInt64( sal_uInt64 ); 319 sal_Bool PutInteger( sal_Int16 ); 320 sal_Bool PutLong( sal_Int32 ); 321 sal_Bool PutSingle( float ); 322 sal_Bool PutDouble( double ); 323 sal_Bool PutDate( double ); 324 sal_Bool PutBool( sal_Bool ); 325 sal_Bool PutErr( sal_uInt16 ); 326 sal_Bool PutStringExt( const ::rtl::OUString& ); // with extended analysis (International, "sal_True"/"sal_False") 327 sal_Bool PutString( const ::rtl::OUString& ); 328 sal_Bool PutString( const sal_Unicode* ); // Type = SbxSTRING 329 sal_Bool PutpChar( const sal_Unicode* ); // Type = SbxLPSTR 330 sal_Bool PutDecimal( SbxDecimal* pDecimal ); 331 sal_Bool PutObject( SbxBase* ); 332 sal_Bool PutData( void* ); 333 sal_Bool PutChar( sal_Unicode ); 334 sal_Bool PutByte( sal_uInt8 ); 335 sal_Bool PutUShort( sal_uInt16 ); 336 sal_Bool PutULong( sal_uInt32 ); 337 sal_Bool PutInt( int ); 338 sal_Bool PutEmpty(); 339 sal_Bool PutNull(); 340 341 // Special decimal methods 342 sal_Bool PutDecimal( com::sun::star::bridge::oleautomation::Decimal& rAutomationDec ); 343 sal_Bool fillAutomationDecimal( com::sun::star::bridge::oleautomation::Decimal& rAutomationDec ); 344 345 virtual sal_Bool Convert( SbxDataType ); 346 virtual sal_Bool Compute( SbxOperator, const SbxValue& ); 347 virtual sal_Bool Compare( SbxOperator, const SbxValue& ) const; 348 sal_Bool Scan( const String&, sal_uInt16* = NULL ); 349 void Format( String&, const String* = NULL ) const; 350 351 // Interface for CDbl in Basic 352 static SbxError ScanNumIntnl( const String& rSrc, double& nVal, sal_Bool bSingle=sal_False ); 353 354 // The following operators are definied for easier handling. 355 // Error conditions (overflow, conversions) are not 356 // taken into consideration. 357 358 inline int operator ==( const SbxValue& ) const; 359 inline int operator !=( const SbxValue& ) const; 360 inline int operator <( const SbxValue& ) const; 361 inline int operator >( const SbxValue& ) const; 362 inline int operator <=( const SbxValue& ) const; 363 inline int operator >=( const SbxValue& ) const; 364 365 inline SbxValue& operator *=( const SbxValue& ); 366 inline SbxValue& operator /=( const SbxValue& ); 367 inline SbxValue& operator %=( const SbxValue& ); 368 inline SbxValue& operator +=( const SbxValue& ); 369 inline SbxValue& operator -=( const SbxValue& ); 370 inline SbxValue& operator &=( const SbxValue& ); 371 inline SbxValue& operator |=( const SbxValue& ); 372 inline SbxValue& operator ^=( const SbxValue& ); 373 }; 374 375 inline int SbxValue::operator==( const SbxValue& r ) const 376 { return Compare( SbxEQ, r ); } 377 378 inline int SbxValue::operator!=( const SbxValue& r ) const 379 { return Compare( SbxNE, r ); } 380 381 inline int SbxValue::operator<( const SbxValue& r ) const 382 { return Compare( SbxLT, r ); } 383 384 inline int SbxValue::operator>( const SbxValue& r ) const 385 { return Compare( SbxGT, r ); } 386 387 inline int SbxValue::operator<=( const SbxValue& r ) const 388 { return Compare( SbxLE, r ); } 389 390 inline int SbxValue::operator>=( const SbxValue& r ) const 391 { return Compare( SbxGE, r ); } 392 393 inline SbxValue& SbxValue::operator*=( const SbxValue& r ) 394 { Compute( SbxMUL, r ); return *this; } 395 396 inline SbxValue& SbxValue::operator/=( const SbxValue& r ) 397 { Compute( SbxDIV, r ); return *this; } 398 399 inline SbxValue& SbxValue::operator%=( const SbxValue& r ) 400 { Compute( SbxMOD, r ); return *this; } 401 402 inline SbxValue& SbxValue::operator+=( const SbxValue& r ) 403 { Compute( SbxPLUS, r ); return *this; } 404 405 inline SbxValue& SbxValue::operator-=( const SbxValue& r ) 406 { Compute( SbxMINUS, r ); return *this; } 407 408 inline SbxValue& SbxValue::operator&=( const SbxValue& r ) 409 { Compute( SbxAND, r ); return *this; } 410 411 inline SbxValue& SbxValue::operator|=( const SbxValue& r ) 412 { Compute( SbxOR, r ); return *this; } 413 414 inline SbxValue& SbxValue::operator^=( const SbxValue& r ) 415 { Compute( SbxXOR, r ); return *this; } 416 417 #endif 418 419 #ifndef __SBX_SBXVARIABLE_HXX 420 #define __SBX_SBXVARIABLE_HXX 421 422 class SbxArray; 423 class SbxInfo; 424 425 #ifndef SBX_ARRAY_DECL_DEFINED 426 #define SBX_ARRAY_DECL_DEFINED 427 SV_DECL_REF(SbxArray) 428 #endif 429 430 #ifndef SBX_INFO_DECL_DEFINED 431 #define SBX_INFO_DECL_DEFINED 432 SV_DECL_REF(SbxInfo) 433 #endif 434 435 class SfxBroadcaster; 436 437 class SbxVariableImpl; 438 class StarBASIC; 439 440 class SbxVariable : public SbxValue 441 { 442 friend class SbMethod; 443 444 SbxVariableImpl* mpSbxVariableImpl; // Impl data 445 SfxBroadcaster* pCst; // Broadcaster, if needed 446 String maName; // Name, if available 447 SbxArrayRef mpPar; // Parameter-Array, if set 448 sal_uInt16 nHash; // Hash-ID for search 449 450 SbxVariableImpl* getImpl( void ); 451 452 protected: 453 SbxInfoRef pInfo; // Probably called information 454 sal_uIntPtr nUserData; // User data for Call() 455 SbxObject* pParent; // Currently attached object 456 virtual ~SbxVariable(); 457 virtual sal_Bool LoadData( SvStream&, sal_uInt16 ); 458 virtual sal_Bool StoreData( SvStream& ) const; 459 public: 460 SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_VARIABLE,2); 461 TYPEINFO(); 462 SbxVariable(); 463 SbxVariable( SbxDataType, void* = NULL ); 464 SbxVariable( const SbxVariable& ); 465 SbxVariable& operator=( const SbxVariable& ); 466 467 void Dump( SvStream&, sal_Bool bDumpAll=sal_False ); 468 469 virtual void SetName( const String& ); 470 virtual const String& GetName( SbxNameType = SbxNAME_NONE ) const; 471 sal_uInt16 GetHashCode() const { return nHash; } 472 473 virtual void SetModified( sal_Bool ); 474 475 sal_uIntPtr GetUserData() const { return nUserData; } 476 void SetUserData( sal_uIntPtr n ) { nUserData = n; } 477 478 virtual SbxDataType GetType() const; 479 virtual SbxClassType GetClass() const; 480 481 // Parameter-Interface 482 virtual SbxInfo* GetInfo(); 483 void SetInfo( SbxInfo* p ); 484 void SetParameters( SbxArray* p ); 485 SbxArray* GetParameters() const { return mpPar; } 486 487 // Sfx-Broadcasting-Support: 488 // Due to data reduction and better DLL-hierarchie currently via casting 489 SfxBroadcaster& GetBroadcaster(); 490 sal_Bool IsBroadcaster() const { return sal_Bool( pCst != NULL ); } 491 virtual void Broadcast( sal_uIntPtr nHintId ); 492 493 inline const SbxObject* GetParent() const { return pParent; } 494 inline SbxObject* GetParent() { return pParent; } 495 virtual void SetParent( SbxObject* ); 496 497 const String& GetDeclareClassName( void ); 498 void SetDeclareClassName( const String& ); 499 void SetComListener( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xComListener, 500 StarBASIC* pParentBasic ); 501 void ClearComListener( void ); 502 503 static sal_uInt16 MakeHashCode( const String& rName ); 504 }; 505 506 #ifndef SBX_VARIABLE_DECL_DEFINED 507 #define SBX_VARIABLE_DECL_DEFINED 508 SV_DECL_REF(SbxVariable) 509 #endif 510 511 #endif 512 513 #endif // _SBXVAR_HXX 514