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