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;
139 sal_Int16
GetInteger() const;
140 sal_Int32
GetLong() const;
141 sal_Int64
GetInt64() const;
142 sal_uInt64
GetUInt64() const;
144 sal_Int64
GetCurrency() const;
145 SbxDecimal
* GetDecimal() const;
147 float GetSingle() const;
148 double GetDouble() const;
149 double GetDate() const;
151 bool GetBool() const;
152 const OUString
& GetCoreString() const;
153 OUString
GetOUString() const;
155 SbxBase
* GetObject() const;
156 sal_uInt8
GetByte() const;
157 sal_uInt16
GetUShort() const;
158 sal_uInt32
GetULong() const;
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 inline bool SbxValue::operator<=( const SbxValue
& r
) const
208 { return Compare( SbxLE
, r
); }
210 inline bool SbxValue::operator>=( const SbxValue
& r
) const
211 { return Compare( SbxGE
, r
); }
213 inline SbxValue
& SbxValue::operator*=( const SbxValue
& r
)
214 { Compute( SbxMUL
, r
); return *this; }
216 inline SbxValue
& SbxValue::operator/=( const SbxValue
& r
)
217 { Compute( SbxDIV
, r
); return *this; }
219 inline SbxValue
& SbxValue::operator+=( const SbxValue
& r
)
220 { Compute( SbxPLUS
, r
); return *this; }
222 inline SbxValue
& SbxValue::operator-=( const SbxValue
& r
)
223 { Compute( SbxMINUS
, r
); return *this; }
228 typedef tools::SvRef
<SbxArray
> SbxArrayRef
;
230 typedef tools::SvRef
<SbxInfo
> SbxInfoRef
;
232 class SfxBroadcaster
;
234 class SbxVariableImpl
;
237 class BASIC_DLLPUBLIC SbxVariable
: public SbxValue
239 friend class SbMethod
;
241 std::unique_ptr
<SbxVariableImpl
> mpImpl
; // Impl data
242 std::unique_ptr
<SfxBroadcaster
> mpBroadcaster
; // Broadcaster, if needed
243 OUString maName
; // Name, if available
244 SbxArrayRef mpPar
; // Parameter-Array, if set
245 sal_uInt16 nHash
; // Hash-ID for search
247 BASIC_DLLPRIVATE SbxVariableImpl
* getImpl();
250 SbxInfoRef pInfo
; // Probably called information
251 sal_uInt32 nUserData
; // User data for Call()
252 SbxObject
* pParent
; // Currently attached object
253 virtual ~SbxVariable() override
;
254 virtual bool LoadData( SvStream
&, sal_uInt16
) override
;
255 virtual bool StoreData( SvStream
& ) const override
;
257 SBX_DECL_PERSIST_NODATA(SBXID_VARIABLE
,2);
259 SbxVariable( SbxDataType
);
260 SbxVariable( const SbxVariable
& );
261 SbxVariable
& operator=( const SbxVariable
& );
263 void Dump( SvStream
&, bool bDumpAll
);
265 void SetName( const OUString
& );
266 const OUString
& GetName( SbxNameType
= SbxNameType::NONE
) const;
267 sal_uInt16
GetHashCode() const { return nHash
; }
269 virtual void SetModified( bool ) override
;
271 sal_uInt32
GetUserData() const { return nUserData
; }
272 void SetUserData( sal_uInt32 n
) { nUserData
= n
; }
274 virtual SbxDataType
GetType() const override
;
275 virtual SbxClassType
GetClass() const;
277 // Parameter-Interface
278 virtual SbxInfo
* GetInfo();
279 void SetInfo( SbxInfo
* p
);
280 void SetParameters( SbxArray
* p
);
281 SbxArray
* GetParameters() const;
283 // Sfx-Broadcasting-Support:
284 // Due to data reduction and better DLL-hierarchy currently via casting
285 SfxBroadcaster
& GetBroadcaster();
286 bool IsBroadcaster() const { return mpBroadcaster
!= nullptr; }
287 virtual void Broadcast( SfxHintId nHintId
) override
;
289 const SbxObject
* GetParent() const { return pParent
; }
290 SbxObject
* GetParent() { return pParent
;}
291 virtual void SetParent( SbxObject
* );
293 const OUString
& GetDeclareClassName();
294 void SetDeclareClassName( const OUString
& );
295 void SetComListener( const css::uno::Reference
< css::uno::XInterface
>& xComListener
,
296 StarBASIC
* pParentBasic
);
297 void ClearComListener();
299 static sal_uInt16
MakeHashCode( const OUString
& rName
);
302 typedef tools::SvRef
<SbxObject
> SbxObjectRef
;
303 typedef tools::SvRef
<SbxVariable
> SbxVariableRef
;
305 //tdf#59222 SbxEnsureParentVariable is a SbxVariable which keeps a reference to
306 //its parent, ensuring it always exists while this SbxVariable exists
307 class SbxEnsureParentVariable final
: public SbxVariable
309 SbxObjectRef xParent
;
311 SbxEnsureParentVariable(const SbxVariable
& r
);
312 virtual void SetParent(SbxObject
* p
) override
;
315 #endif // INCLUDED_BASIC_SBXVAR_HXX
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */