bump product version to 4.1.6.2
[LibreOffice.git] / include / basic / sbxvar.hxx
bloba81836f125f6844a9f87d960dc45739a29e8ba4b
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 SBXVAR_HXX
21 #define SBXVAR_HXX
23 #include <rtl/ustring.hxx>
24 #include <com/sun/star/bridge/oleautomation/Decimal.hpp>
25 #include <basic/sbxcore.hxx>
26 #include "basicdllapi.h"
29 class SbxDecimal;
31 struct SbxValues
33 union {
34 sal_uInt8 nByte;
35 sal_uInt16 nUShort;
36 sal_Unicode nChar;
37 sal_Int16 nInteger;
38 sal_uInt32 nULong;
39 sal_Int32 nLong;
40 unsigned int nUInt;
41 int nInt;
42 sal_uInt64 uInt64;
43 sal_Int64 nInt64;
45 float nSingle;
46 double nDouble;
48 OUString* pOUString;
49 SbxDecimal* pDecimal;
51 SbxBase* pObj;
53 sal_uInt8* pByte;
54 sal_uInt16* pUShort;
55 sal_Unicode* pChar;
56 sal_Int16* pInteger;
57 sal_uInt32* pULong;
58 sal_Int32* pLong;
59 unsigned int* pUInt;
60 int* pInt;
61 sal_uInt64* puInt64;
62 sal_Int64* pnInt64;
64 float* pSingle;
65 double* pDouble;
67 void* pData;
69 SbxDataType eType;
71 SbxValues(): pData( NULL ), eType(SbxEMPTY) {}
72 SbxValues( SbxDataType e ): eType(e) {}
73 SbxValues( char _nChar ): nChar( _nChar ), eType(SbxCHAR) {}
74 SbxValues( sal_uInt8 _nByte ): nByte( _nByte ), eType(SbxBYTE) {}
75 SbxValues( short _nInteger ): nInteger( _nInteger ), eType(SbxINTEGER ) {}
76 SbxValues( long _nLong ): nLong( _nLong ), eType(SbxLONG) {}
77 SbxValues( sal_uInt16 _nUShort ): nUShort( _nUShort ), eType(SbxUSHORT) {}
78 SbxValues( sal_uIntPtr _nULong ): nULong( _nULong ), eType(SbxULONG) {}
79 SbxValues( int _nInt ): nInt( _nInt ), eType(SbxINT) {}
80 SbxValues( unsigned int _nUInt ): nUInt( _nUInt ), eType(SbxUINT) {}
81 SbxValues( float _nSingle ): nSingle( _nSingle ), eType(SbxSINGLE) {}
82 SbxValues( double _nDouble ): nDouble( _nDouble ), eType(SbxDOUBLE) {}
83 SbxValues( const OUString* _pString ): pOUString( (OUString*)_pString ), eType(SbxSTRING) {}
84 SbxValues( SbxBase* _pObj ): pObj( _pObj ), eType(SbxOBJECT) {}
85 SbxValues( sal_Unicode* _pChar ): pChar( _pChar ), eType(SbxLPSTR) {}
86 SbxValues( void* _pData ): pData( _pData ), eType(SbxPOINTER) {}
90 class BASIC_DLLPUBLIC SbxValue : public SbxBase
92 // #55226 Transport additional infos
93 BASIC_DLLPRIVATE SbxValue* TheRealValue( sal_Bool bObjInObjError ) const;
94 BASIC_DLLPRIVATE SbxValue* TheRealValue() const;
95 protected:
96 SbxValues aData; // Data
97 OUString aPic; // Picture-String
98 OUString aToolString; // tool string copy
100 virtual void Broadcast( sal_uIntPtr ); // Broadcast-Call
101 virtual ~SbxValue();
102 virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
103 virtual sal_Bool StoreData( SvStream& ) const;
104 public:
105 SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_VALUE,1);
106 TYPEINFO();
107 SbxValue();
108 SbxValue( SbxDataType, void* = NULL );
109 SbxValue( const SbxValue& );
110 SbxValue& operator=( const SbxValue& );
111 virtual void Clear();
112 virtual sal_Bool IsFixed() const;
114 sal_Bool IsInteger() const { return sal_Bool( GetType() == SbxINTEGER ); }
115 sal_Bool IsLong() const { return sal_Bool( GetType() == SbxLONG ); }
116 sal_Bool IsSingle() const { return sal_Bool( GetType() == SbxSINGLE ); }
117 sal_Bool IsDouble() const { return sal_Bool( GetType() == SbxDOUBLE ); }
118 sal_Bool IsString() const { return sal_Bool( GetType() == SbxSTRING ); }
119 sal_Bool IsDate() const { return sal_Bool( GetType() == SbxDATE ); }
120 sal_Bool IsCurrency()const { return sal_Bool( GetType() == SbxCURRENCY ); }
121 sal_Bool IsObject() const { return sal_Bool( GetType() == SbxOBJECT ); }
122 sal_Bool IsDataObject()const{return sal_Bool( GetType() == SbxDATAOBJECT);}
123 sal_Bool IsBool() const { return sal_Bool( GetType() == SbxBOOL ); }
124 sal_Bool IsErr() const { return sal_Bool( GetType() == SbxERROR ); }
125 sal_Bool IsEmpty() const { return sal_Bool( GetType() == SbxEMPTY ); }
126 sal_Bool IsNull() const { return sal_Bool( GetType() == SbxNULL ); }
127 sal_Bool IsChar() const { return sal_Bool( GetType() == SbxCHAR ); }
128 sal_Bool IsByte() const { return sal_Bool( GetType() == SbxBYTE ); }
129 sal_Bool IsUShort() const { return sal_Bool( GetType() == SbxUSHORT ); }
130 sal_Bool IsULong() const { return sal_Bool( GetType() == SbxULONG ); }
131 sal_Bool IsInt() const { return sal_Bool( GetType() == SbxINT ); }
132 sal_Bool IsUInt() const { return sal_Bool( GetType() == SbxUINT ); }
133 sal_Bool IspChar() const { return sal_Bool( GetType() == SbxLPSTR ); }
134 sal_Bool IsNumeric() const;
135 sal_Bool IsNumericRTL() const; // #41692 Interface for Basic
136 sal_Bool ImpIsNumeric( bool bOnlyIntntl ) const; // Implementation
138 virtual SbxClassType GetClass() const;
139 virtual SbxDataType GetType() const;
140 SbxDataType GetFullType() const;
141 sal_Bool SetType( SbxDataType );
143 virtual sal_Bool Get( SbxValues& ) const;
144 const SbxValues& GetValues_Impl() const { return aData; }
145 virtual sal_Bool Put( const SbxValues& );
147 inline SbxValues * data() { return &aData; }
149 sal_Unicode GetChar() const;
150 sal_Int16 GetInteger() const;
151 sal_Int32 GetLong() const;
152 sal_Int64 GetInt64() const;
153 sal_uInt64 GetUInt64() const;
155 sal_Int64 GetCurrency() const;
156 SbxDecimal* GetDecimal() const;
158 float GetSingle() const;
159 double GetDouble() const;
160 double GetDate() const;
162 sal_Bool GetBool() const;
163 const OUString& GetCoreString() const;
164 OUString GetOUString() const;
166 SbxBase* GetObject() const;
167 sal_uInt8 GetByte() const;
168 sal_uInt16 GetUShort() const;
169 sal_uInt32 GetULong() const;
171 sal_Bool PutInteger( sal_Int16 );
172 sal_Bool PutLong( sal_Int32 );
173 sal_Bool PutSingle( float );
174 sal_Bool PutDouble( double );
175 sal_Bool PutDate( double );
176 sal_Bool PutBool( sal_Bool );
177 sal_Bool PutErr( sal_uInt16 );
178 sal_Bool PutStringExt( const OUString& ); // with extended analysis (International, "sal_True"/"sal_False")
179 sal_Bool PutInt64( sal_Int64 );
180 sal_Bool PutUInt64( sal_uInt64 );
181 sal_Bool PutString( const OUString& );
182 sal_Bool PutChar( sal_Unicode );
183 sal_Bool PutByte( sal_uInt8 );
184 sal_Bool PutUShort( sal_uInt16 );
185 sal_Bool PutULong( sal_uInt32 );
186 sal_Bool PutEmpty();
187 sal_Bool PutNull();
189 // Special methods
190 sal_Bool PutDecimal( com::sun::star::bridge::oleautomation::Decimal& rAutomationDec );
191 sal_Bool PutDecimal( SbxDecimal* pDecimal ); // This function is needed for Windows build, don't remove
192 sal_Bool fillAutomationDecimal( com::sun::star::bridge::oleautomation::Decimal& rAutomationDec ) const;
193 sal_Bool PutCurrency( const sal_Int64& );
194 // Interface for CDbl in Basic
195 static SbxError ScanNumIntnl( const OUString& rSrc, double& nVal, bool bSingle = false );
197 sal_Bool PutObject( SbxBase* );
199 virtual sal_Bool Convert( SbxDataType );
200 virtual sal_Bool Compute( SbxOperator, const SbxValue& );
201 virtual sal_Bool Compare( SbxOperator, const SbxValue& ) const;
202 sal_Bool Scan( const OUString&, sal_uInt16* = NULL );
203 void Format( OUString&, const OUString* = NULL ) const;
205 // The following operators are definied for easier handling.
206 // TODO: Ensure error conditions (overflow, conversions)
207 // are taken into consideration in Compute and Compare
209 inline int operator ==( const SbxValue& ) const;
210 inline int operator !=( const SbxValue& ) const;
211 inline int operator <( const SbxValue& ) const;
212 inline int operator >( const SbxValue& ) const;
213 inline int operator <=( const SbxValue& ) const;
214 inline int operator >=( const SbxValue& ) const;
216 inline SbxValue& operator *=( const SbxValue& );
217 inline SbxValue& operator /=( const SbxValue& );
218 inline SbxValue& operator %=( const SbxValue& );
219 inline SbxValue& operator +=( const SbxValue& );
220 inline SbxValue& operator -=( const SbxValue& );
221 inline SbxValue& operator &=( const SbxValue& );
222 inline SbxValue& operator |=( const SbxValue& );
223 inline SbxValue& operator ^=( const SbxValue& );
226 inline int SbxValue::operator==( const SbxValue& r ) const
227 { return Compare( SbxEQ, r ); }
229 inline int SbxValue::operator!=( const SbxValue& r ) const
230 { return Compare( SbxNE, r ); }
232 inline int SbxValue::operator<( const SbxValue& r ) const
233 { return Compare( SbxLT, r ); }
235 inline int SbxValue::operator>( const SbxValue& r ) const
236 { return Compare( SbxGT, r ); }
238 inline int SbxValue::operator<=( const SbxValue& r ) const
239 { return Compare( SbxLE, r ); }
241 inline int SbxValue::operator>=( const SbxValue& r ) const
242 { return Compare( SbxGE, r ); }
244 inline SbxValue& SbxValue::operator*=( const SbxValue& r )
245 { Compute( SbxMUL, r ); return *this; }
247 inline SbxValue& SbxValue::operator/=( const SbxValue& r )
248 { Compute( SbxDIV, r ); return *this; }
250 inline SbxValue& SbxValue::operator%=( const SbxValue& r )
251 { Compute( SbxMOD, r ); return *this; }
253 inline SbxValue& SbxValue::operator+=( const SbxValue& r )
254 { Compute( SbxPLUS, r ); return *this; }
256 inline SbxValue& SbxValue::operator-=( const SbxValue& r )
257 { Compute( SbxMINUS, r ); return *this; }
259 inline SbxValue& SbxValue::operator&=( const SbxValue& r )
260 { Compute( SbxAND, r ); return *this; }
262 inline SbxValue& SbxValue::operator|=( const SbxValue& r )
263 { Compute( SbxOR, r ); return *this; }
265 inline SbxValue& SbxValue::operator^=( const SbxValue& r )
266 { Compute( SbxXOR, r ); return *this; }
268 class SbxArray;
269 class SbxInfo;
271 #ifndef SBX_ARRAY_DECL_DEFINED
272 #define SBX_ARRAY_DECL_DEFINED
273 SV_DECL_REF(SbxArray)
274 #endif
276 #ifndef SBX_INFO_DECL_DEFINED
277 #define SBX_INFO_DECL_DEFINED
278 SV_DECL_REF(SbxInfo)
279 #endif
281 class SfxBroadcaster;
283 class SbxVariableImpl;
284 class StarBASIC;
286 class BASIC_DLLPUBLIC SbxVariable : public SbxValue
288 friend class SbMethod;
290 SbxVariableImpl* mpSbxVariableImpl; // Impl data
291 SfxBroadcaster* pCst; // Broadcaster, if needed
292 OUString maName; // Name, if available
293 SbxArrayRef mpPar; // Parameter-Array, if set
294 sal_uInt16 nHash; // Hash-ID for search
296 BASIC_DLLPRIVATE SbxVariableImpl* getImpl( void );
298 protected:
299 SbxInfoRef pInfo; // Probably called information
300 sal_uIntPtr nUserData; // User data for Call()
301 SbxObject* pParent; // Currently attached object
302 virtual ~SbxVariable();
303 virtual sal_Bool LoadData( SvStream&, sal_uInt16 );
304 virtual sal_Bool StoreData( SvStream& ) const;
305 public:
306 SBX_DECL_PERSIST_NODATA(SBXCR_SBX,SBXID_VARIABLE,2);
307 TYPEINFO();
308 SbxVariable();
309 SbxVariable( SbxDataType, void* = NULL );
310 SbxVariable( const SbxVariable& );
311 SbxVariable& operator=( const SbxVariable& );
313 void Dump( SvStream&, sal_Bool bDumpAll=sal_False );
315 virtual void SetName( const OUString& );
316 virtual const OUString& GetName( SbxNameType = SbxNAME_NONE ) const;
317 sal_uInt16 GetHashCode() const { return nHash; }
319 virtual void SetModified( sal_Bool );
321 sal_uIntPtr GetUserData() const { return nUserData; }
322 void SetUserData( sal_uIntPtr n ) { nUserData = n; }
324 virtual SbxDataType GetType() const;
325 virtual SbxClassType GetClass() const;
327 // Parameter-Interface
328 virtual SbxInfo* GetInfo();
329 void SetInfo( SbxInfo* p );
330 void SetParameters( SbxArray* p );
331 SbxArray* GetParameters() const;
333 // Sfx-Broadcasting-Support:
334 // Due to data reduction and better DLL-hierarchie currently via casting
335 SfxBroadcaster& GetBroadcaster();
336 sal_Bool IsBroadcaster() const { return sal_Bool( pCst != NULL ); }
337 virtual void Broadcast( sal_uIntPtr nHintId );
339 inline const SbxObject* GetParent() const { return pParent; }
340 SbxObject* GetParent();
341 virtual void SetParent( SbxObject* );
343 const OUString& GetDeclareClassName( void );
344 void SetDeclareClassName( const OUString& );
345 void SetComListener( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xComListener,
346 StarBASIC* pParentBasic );
347 void ClearComListener( void );
349 static sal_uInt16 MakeHashCode( const OUString& rName );
352 SV_DECL_REF(SbxVariable)
354 #endif // SBXVAR_HXX
356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */