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 <basic/sbxcore.hxx>
25 #include <basic/basicdllapi.h>
32 namespace com::sun::star::bridge::oleautomation
{ struct Decimal
; }
33 namespace com::sun::star::uno
{ class XInterface
; }
34 namespace com::sun::star::uno
{ template <typename
> class Reference
; }
77 SbxValues(): pData( nullptr ), eType(SbxEMPTY
) {}
78 SbxValues( SbxDataType e
): eType(e
) {}
79 SbxValues( double _nDouble
): nDouble( _nDouble
), eType(SbxDOUBLE
) {}
81 void clear(SbxDataType type
) {
82 // A hacky way of zeroing the union value corresponding to the given type (even though the
83 // relevant zero value need not be represented by all-zero bits, in general) without evoking
84 // GCC 8 -Wclass-memaccess or loplugin:classmemaccess, and without having to turn the
85 // anonymous union into a non-anonymous one:
86 auto const p
= static_cast<void *>(this);
87 std::memset(p
, 0, offsetof(SbxValues
, eType
));
92 class BASIC_DLLPUBLIC SbxValue
: public SbxBase
94 // #55226 Transport additional infos
95 BASIC_DLLPRIVATE SbxValue
* TheRealValue( bool bObjInObjError
) const;
97 SbxValues aData
; // Data
98 OUString aPic
; // Picture-String
99 OUString aToolString
; // tool string copy
101 virtual void Broadcast( SfxHintId
); // Broadcast-Call
102 virtual ~SbxValue() override
;
103 virtual bool LoadData( SvStream
&, sal_uInt16
) override
;
104 virtual bool StoreData( SvStream
& ) const override
;
106 SBX_DECL_PERSIST_NODATA(SBXID_VALUE
,1);
108 SbxValue( SbxDataType
);
109 SbxValue( const SbxValue
& );
110 SbxValue
& operator=( const SbxValue
& );
111 virtual void Clear() override
;
112 virtual bool IsFixed() const override
;
114 bool IsInteger() const { return GetType() == SbxINTEGER
; }
115 bool IsLong() const { return GetType() == SbxLONG
; }
116 bool IsDouble() const { return GetType() == SbxDOUBLE
; }
117 bool IsString() const { return GetType() == SbxSTRING
; }
118 bool IsCurrency() const { return GetType() == SbxCURRENCY
; }
119 bool IsObject() const { return GetType() == SbxOBJECT
; }
120 bool IsBool() const { return GetType() == SbxBOOL
; }
121 bool IsErr() const { return GetType() == SbxERROR
; }
122 bool IsEmpty() const { return GetType() == SbxEMPTY
; }
123 bool IsNull() const { return GetType() == SbxNULL
; }
124 bool IsNumeric() const;
125 bool IsNumericRTL() const; // #41692 Interface for Basic
126 bool ImpIsNumeric( bool bOnlyIntntl
) const; // Implementation
128 virtual SbxDataType
GetType() const override
;
129 SbxDataType
GetFullType() const { return aData
.eType
;}
130 bool SetType( SbxDataType
);
132 bool Get( SbxValues
& ) const;
133 const SbxValues
& GetValues_Impl() const { return aData
; }
134 bool Put( const SbxValues
& );
136 SbxValues
* data() { return &aData
; }
138 sal_Unicode
GetChar() const { return Get(SbxCHAR
).nChar
; }
139 sal_Int16
GetInteger() const { return Get(SbxINTEGER
).nInteger
; }
140 sal_Int32
GetLong() const { return Get(SbxLONG
).nLong
; }
141 sal_Int64
GetInt64() const { return Get(SbxSALINT64
).nInt64
; }
142 sal_uInt64
GetUInt64() const { return Get(SbxSALUINT64
).uInt64
; }
144 sal_Int64
GetCurrency() const { return Get(SbxCURRENCY
).nInt64
; }
145 SbxDecimal
* GetDecimal() const { return Get(SbxDECIMAL
).pDecimal
; }
147 float GetSingle() const { return Get(SbxSINGLE
).nSingle
; }
148 double GetDouble() const { return Get(SbxDOUBLE
).nDouble
; }
149 double GetDate() const { return Get(SbxDATE
).nDouble
; }
151 bool GetBool() const { return Get(SbxBOOL
).nUShort
!= 0; }
152 const OUString
& GetCoreString() const;
153 OUString
GetOUString() const;
155 SbxBase
* GetObject() const { return Get(SbxOBJECT
).pObj
; }
156 sal_uInt8
GetByte() const { return Get(SbxBYTE
).nByte
; }
157 sal_uInt16
GetUShort() const { return Get(SbxUSHORT
).nUShort
; }
158 sal_uInt32
GetULong() const { return Get(SbxULONG
).nULong
; }
160 bool PutInteger( sal_Int16
);
161 bool PutLong( sal_Int32
);
162 bool PutSingle( float );
163 bool PutDouble( double );
164 void PutDate( double );
165 bool PutBool( bool );
166 void PutErr( sal_uInt16
);
167 void PutStringExt( const OUString
& ); // with extended analysis (International, "sal_True"/"sal_False")
168 bool PutInt64( sal_Int64
);
169 bool PutUInt64( sal_uInt64
);
170 bool PutString( const OUString
& );
171 bool PutChar( sal_Unicode
);
172 bool PutByte( sal_uInt8
);
173 bool PutUShort( sal_uInt16
);
174 bool PutULong( sal_uInt32
);
179 void PutDecimal( css::bridge::oleautomation::Decimal
const & rAutomationDec
);
180 bool PutDecimal( SbxDecimal
* pDecimal
); // This function is needed for Windows build, don't remove
181 void fillAutomationDecimal( css::bridge::oleautomation::Decimal
& rAutomationDec
) const;
182 bool PutCurrency( sal_Int64
);
183 // Interface for CDbl in Basic
184 static ErrCode
ScanNumIntnl( const OUString
& rSrc
, double& nVal
, bool bSingle
= false );
186 bool PutObject( SbxBase
* );
188 bool Convert( SbxDataType
);
189 bool Compute( SbxOperator
, const SbxValue
& );
190 bool Compare( SbxOperator
, const SbxValue
& ) const;
191 bool Scan( const OUString
&, sal_uInt16
* );
192 void Format( OUString
&, const OUString
* = nullptr ) const;
194 // The following operators are defined for easier handling.
195 // TODO: Ensure error conditions (overflow, conversions)
196 // are taken into consideration in Compute and Compare
198 inline bool operator <=( const SbxValue
& ) const;
199 inline bool operator >=( const SbxValue
& ) const;
201 inline SbxValue
& operator *=( const SbxValue
& );
202 inline SbxValue
& operator /=( const SbxValue
& );
203 inline SbxValue
& operator +=( const SbxValue
& );
204 inline SbxValue
& operator -=( const SbxValue
& );
207 SbxValues
Get(SbxDataType t
) const;
210 inline bool SbxValue::operator<=( const SbxValue
& r
) const
211 { return Compare( SbxLE
, r
); }
213 inline bool SbxValue::operator>=( const SbxValue
& r
) const
214 { return Compare( SbxGE
, r
); }
216 inline SbxValue
& SbxValue::operator*=( const SbxValue
& r
)
217 { Compute( SbxMUL
, r
); return *this; }
219 inline SbxValue
& SbxValue::operator/=( const SbxValue
& r
)
220 { Compute( SbxDIV
, r
); return *this; }
222 inline SbxValue
& SbxValue::operator+=( const SbxValue
& r
)
223 { Compute( SbxPLUS
, r
); return *this; }
225 inline SbxValue
& SbxValue::operator-=( const SbxValue
& r
)
226 { Compute( SbxMINUS
, r
); return *this; }
231 typedef tools::SvRef
<SbxArray
> SbxArrayRef
;
233 typedef tools::SvRef
<SbxInfo
> SbxInfoRef
;
235 class SfxBroadcaster
;
237 class SbxVariableImpl
;
240 class BASIC_DLLPUBLIC SbxVariable
: public SbxValue
242 friend class SbMethod
;
244 std::unique_ptr
<SbxVariableImpl
> mpImpl
; // Impl data
245 std::unique_ptr
<SfxBroadcaster
> mpBroadcaster
; // Broadcaster, if needed
246 OUString maName
; // Name, if available
247 SbxArrayRef mpPar
; // Parameter-Array, if set
248 sal_uInt16 nHash
; // Hash-ID for search
250 BASIC_DLLPRIVATE SbxVariableImpl
* getImpl();
253 SbxInfoRef pInfo
; // Probably called information
254 sal_uInt32 nUserData
; // User data for Call()
255 SbxObject
* pParent
; // Currently attached object
256 virtual ~SbxVariable() override
;
257 virtual bool LoadData( SvStream
&, sal_uInt16
) override
;
258 virtual bool StoreData( SvStream
& ) const override
;
260 SBX_DECL_PERSIST_NODATA(SBXID_VARIABLE
,2);
262 SbxVariable( SbxDataType
);
263 SbxVariable( const SbxVariable
& );
264 SbxVariable
& operator=( const SbxVariable
& );
266 void Dump( SvStream
&, bool bDumpAll
);
268 void SetName( const OUString
& );
269 const OUString
& GetName( SbxNameType
= SbxNameType::NONE
) const;
270 sal_uInt16
GetHashCode() const { return nHash
; }
272 virtual void SetModified( bool ) override
;
274 sal_uInt32
GetUserData() const { return nUserData
; }
275 void SetUserData( sal_uInt32 n
) { nUserData
= n
; }
277 virtual SbxDataType
GetType() const override
;
278 virtual SbxClassType
GetClass() const;
280 // Parameter-Interface
281 virtual SbxInfo
* GetInfo();
282 void SetInfo( SbxInfo
* p
);
283 void SetParameters( SbxArray
* p
);
284 SbxArray
* GetParameters() const;
286 // Sfx-Broadcasting-Support:
287 // Due to data reduction and better DLL-hierarchy currently via casting
288 SfxBroadcaster
& GetBroadcaster();
289 bool IsBroadcaster() const { return mpBroadcaster
!= nullptr; }
290 virtual void Broadcast( SfxHintId nHintId
) override
;
292 const SbxObject
* GetParent() const { return pParent
; }
293 SbxObject
* GetParent() { return pParent
;}
294 virtual void SetParent( SbxObject
* );
296 const OUString
& GetDeclareClassName();
297 void SetDeclareClassName( const OUString
& );
298 void SetComListener( const css::uno::Reference
< css::uno::XInterface
>& xComListener
,
299 StarBASIC
* pParentBasic
);
300 void ClearComListener();
302 static sal_uInt16
MakeHashCode( const OUString
& rName
);
305 typedef tools::SvRef
<SbxObject
> SbxObjectRef
;
306 typedef tools::SvRef
<SbxVariable
> SbxVariableRef
;
308 //tdf#59222 SbxEnsureParentVariable is a SbxVariable which keeps a reference to
309 //its parent, ensuring it always exists while this SbxVariable exists
310 class SbxEnsureParentVariable final
: public SbxVariable
312 SbxObjectRef xParent
;
314 SbxEnsureParentVariable(const SbxVariable
& r
);
315 virtual void SetParent(SbxObject
* p
) override
;
318 #endif // INCLUDED_BASIC_SBXVAR_HXX
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */