1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_BASIC_SBXVAR_HXX
21 #define INCLUDED_BASIC_SBXVAR_HXX
23 #include <rtl/ustring.hxx>
24 #include <com/sun/star/bridge/oleautomation/Decimal.hpp>
25 #include <basic/sbxcore.hxx>
26 #include <basic/basicdllapi.h>
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( const_cast<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( bool bObjInObjError
) const;
94 BASIC_DLLPRIVATE SbxValue
* TheRealValue() const;
96 SbxValues aData
; // Data
97 OUString aPic
; // Picture-String
98 OUString aToolString
; // tool string copy
100 virtual void Broadcast( sal_uIntPtr
); // Broadcast-Call
102 virtual bool LoadData( SvStream
&, sal_uInt16
) SAL_OVERRIDE
;
103 virtual bool StoreData( SvStream
& ) const SAL_OVERRIDE
;
105 SBX_DECL_PERSIST_NODATA(SBXCR_SBX
,SBXID_VALUE
,1);
108 SbxValue( SbxDataType
, void* = NULL
);
109 SbxValue( const SbxValue
& );
110 SbxValue
& operator=( const SbxValue
& );
111 virtual void Clear() SAL_OVERRIDE
;
112 virtual bool IsFixed() const SAL_OVERRIDE
;
114 bool IsInteger() const { return GetType() == SbxINTEGER
; }
115 bool IsLong() const { return GetType() == SbxLONG
; }
116 bool IsSingle() const { return GetType() == SbxSINGLE
; }
117 bool IsDouble() const { return GetType() == SbxDOUBLE
; }
118 bool IsString() const { return GetType() == SbxSTRING
; }
119 bool IsDate() const { return GetType() == SbxDATE
; }
120 bool IsCurrency() const { return GetType() == SbxCURRENCY
; }
121 bool IsObject() const { return GetType() == SbxOBJECT
; }
122 bool IsDataObject() const { return GetType() == SbxDATAOBJECT
; }
123 bool IsBool() const { return GetType() == SbxBOOL
; }
124 bool IsErr() const { return GetType() == SbxERROR
; }
125 bool IsEmpty() const { return GetType() == SbxEMPTY
; }
126 bool IsNull() const { return GetType() == SbxNULL
; }
127 bool IsChar() const { return GetType() == SbxCHAR
; }
128 bool IsByte() const { return GetType() == SbxBYTE
; }
129 bool IsUShort() const { return GetType() == SbxUSHORT
; }
130 bool IsULong() const { return GetType() == SbxULONG
; }
131 bool IsInt() const { return GetType() == SbxINT
; }
132 bool IsUInt() const { return GetType() == SbxUINT
; }
133 bool IspChar() const { return GetType() == SbxLPSTR
; }
134 bool IsNumeric() const;
135 bool IsNumericRTL() const; // #41692 Interface for Basic
136 bool ImpIsNumeric( bool bOnlyIntntl
) const; // Implementation
138 virtual SbxClassType
GetClass() const SAL_OVERRIDE
;
139 virtual SbxDataType
GetType() const SAL_OVERRIDE
;
140 SbxDataType
GetFullType() const { return aData
.eType
;}
141 bool SetType( SbxDataType
);
143 bool Get( SbxValues
& ) const;
144 const SbxValues
& GetValues_Impl() const { return aData
; }
145 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 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 bool PutInteger( sal_Int16
);
172 bool PutLong( sal_Int32
);
173 bool PutSingle( float );
174 bool PutDouble( double );
175 bool PutDate( double );
176 bool PutBool( bool );
177 bool PutErr( sal_uInt16
);
178 bool PutStringExt( const OUString
& ); // with extended analysis (International, "sal_True"/"sal_False")
179 bool PutInt64( sal_Int64
);
180 bool PutUInt64( sal_uInt64
);
181 bool PutString( const OUString
& );
182 bool PutChar( sal_Unicode
);
183 bool PutByte( sal_uInt8
);
184 bool PutUShort( sal_uInt16
);
185 bool PutULong( sal_uInt32
);
190 bool PutDecimal( com::sun::star::bridge::oleautomation::Decimal
& rAutomationDec
);
191 bool PutDecimal( SbxDecimal
* pDecimal
); // This function is needed for Windows build, don't remove
192 bool fillAutomationDecimal( com::sun::star::bridge::oleautomation::Decimal
& rAutomationDec
) const;
193 bool PutCurrency( const sal_Int64
& );
194 // Interface for CDbl in Basic
195 static SbxError
ScanNumIntnl( const OUString
& rSrc
, double& nVal
, bool bSingle
= false );
197 bool PutObject( SbxBase
* );
199 bool Convert( SbxDataType
);
200 bool Compute( SbxOperator
, const SbxValue
& );
201 bool Compare( SbxOperator
, const SbxValue
& ) const;
202 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 bool operator ==( const SbxValue
& ) const;
210 inline bool operator !=( const SbxValue
& ) const;
211 inline bool operator <( const SbxValue
& ) const;
212 inline bool operator >( const SbxValue
& ) const;
213 inline bool operator <=( const SbxValue
& ) const;
214 inline bool 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 bool SbxValue::operator==( const SbxValue
& r
) const
227 { return Compare( SbxEQ
, r
); }
229 inline bool SbxValue::operator!=( const SbxValue
& r
) const
230 { return Compare( SbxNE
, r
); }
232 inline bool SbxValue::operator<( const SbxValue
& r
) const
233 { return Compare( SbxLT
, r
); }
235 inline bool SbxValue::operator>( const SbxValue
& r
) const
236 { return Compare( SbxGT
, r
); }
238 inline bool SbxValue::operator<=( const SbxValue
& r
) const
239 { return Compare( SbxLE
, r
); }
241 inline bool 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; }
271 #ifndef SBX_ARRAY_DECL_DEFINED
272 #define SBX_ARRAY_DECL_DEFINED
273 typedef tools::SvRef
<SbxArray
> SbxArrayRef
;
276 #ifndef SBX_INFO_DECL_DEFINED
277 #define SBX_INFO_DECL_DEFINED
278 typedef tools::SvRef
<SbxInfo
> SbxInfoRef
;
281 class SfxBroadcaster
;
283 class SbxVariableImpl
;
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();
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 bool LoadData( SvStream
&, sal_uInt16
) SAL_OVERRIDE
;
304 virtual bool StoreData( SvStream
& ) const SAL_OVERRIDE
;
306 SBX_DECL_PERSIST_NODATA(SBXCR_SBX
,SBXID_VARIABLE
,2);
309 SbxVariable( SbxDataType
, void* = NULL
);
310 SbxVariable( const SbxVariable
& );
311 SbxVariable
& operator=( const SbxVariable
& );
313 void Dump( SvStream
&, bool bDumpAll
=false );
315 void SetName( const OUString
& );
316 const OUString
& GetName( SbxNameType
= SbxNAME_NONE
) const;
317 sal_uInt16
GetHashCode() const { return nHash
; }
319 virtual void SetModified( bool ) SAL_OVERRIDE
;
321 sal_uIntPtr
GetUserData() const { return nUserData
; }
322 void SetUserData( sal_uIntPtr n
) { nUserData
= n
; }
324 virtual SbxDataType
GetType() const SAL_OVERRIDE
;
325 virtual SbxClassType
GetClass() const SAL_OVERRIDE
;
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-hierarchy currently via casting
335 SfxBroadcaster
& GetBroadcaster();
336 bool IsBroadcaster() const { return pCst
!= NULL
; }
337 virtual void Broadcast( sal_uIntPtr nHintId
) SAL_OVERRIDE
;
339 inline const SbxObject
* GetParent() const { return pParent
; }
340 SbxObject
* GetParent() { return pParent
;}
341 virtual void SetParent( SbxObject
* );
343 const OUString
& GetDeclareClassName();
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();
349 static sal_uInt16
MakeHashCode( const OUString
& rName
);
352 typedef tools::SvRef
<SbxVariable
> SbxVariableRef
;
354 #endif // INCLUDED_BASIC_SBXVAR_HXX
356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */