File: | home/maarten/src/libreoffice/core/sc/source/ui/vba/vbaformatconditions.cxx |
Warning: | line 46, column 13 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 | #include <ooo/vba/excel/XRange.hpp> | |||
21 | #include <com/sun/star/sheet/XSheetConditionalEntry.hpp> | |||
22 | #include <basic/sberrors.hxx> | |||
23 | #include <comphelper/sequence.hxx> | |||
24 | #include <cppuhelper/exc_hlp.hxx> | |||
25 | #include <vector> | |||
26 | #include <unonames.hxx> | |||
27 | #include "vbaformatconditions.hxx" | |||
28 | #include "vbaformatcondition.hxx" | |||
29 | #include "vbastyles.hxx" | |||
30 | ||||
31 | using namespace ::ooo::vba; | |||
32 | using namespace ::com::sun::star; | |||
33 | ||||
34 | void SAL_CALL | |||
35 | ScVbaFormatConditions::Delete( ) | |||
36 | { | |||
37 | try | |||
38 | { | |||
39 | ScVbaStyles* pStyles = static_cast< ScVbaStyles* >( mxStyles.get() ); | |||
| ||||
40 | if ( !pStyles ) | |||
41 | DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILEDErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 89 ), OUString() ); | |||
42 | sal_Int32 nCount = mxSheetConditionalEntries->getCount(); | |||
43 | for (sal_Int32 i = nCount - 1; i >= 0; i--) | |||
44 | { | |||
45 | uno::Reference< sheet::XSheetConditionalEntry > xSheetConditionalEntry( mxSheetConditionalEntries->getByIndex(i), uno::UNO_QUERY_THROW ); | |||
46 | pStyles->Delete(xSheetConditionalEntry->getStyleName()); | |||
| ||||
47 | mxSheetConditionalEntries->removeByIndex(i); | |||
48 | } | |||
49 | notifyRange(); | |||
50 | } | |||
51 | catch (uno::Exception& ) | |||
52 | { | |||
53 | DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILEDErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 89 ), OUString()); | |||
54 | } | |||
55 | } | |||
56 | ||||
57 | uno::Type SAL_CALL | |||
58 | ScVbaFormatConditions::getElementType() | |||
59 | { | |||
60 | return cppu::UnoType<excel::XFormatCondition>::get(); | |||
61 | } | |||
62 | ||||
63 | static uno::Any xSheetConditionToFormatCondition( const uno::Reference< XHelperInterface >& xRangeParent, const uno::Reference< uno::XComponentContext >& xContext, const uno::Reference< excel::XStyles >& xStyles, const uno::Reference< excel::XFormatConditions >& xFormatConditions, const uno::Reference< beans::XPropertySet >& xRangeProps, const uno::Any& aObject ) | |||
64 | { | |||
65 | uno::Reference< sheet::XSheetConditionalEntry > xSheetConditionalEntry; | |||
66 | aObject >>= xSheetConditionalEntry; | |||
67 | ||||
68 | uno::Reference< excel::XStyle > xStyle( xStyles->Item( uno::makeAny( xSheetConditionalEntry->getStyleName() ), uno::Any() ), uno::UNO_QUERY_THROW ); | |||
69 | uno::Reference< excel::XFormatCondition > xCondition = new ScVbaFormatCondition( xRangeParent, xContext, xSheetConditionalEntry, xStyle, xFormatConditions, xRangeProps ); | |||
70 | return uno::makeAny( xCondition ); | |||
71 | } | |||
72 | ||||
73 | uno::Any | |||
74 | ScVbaFormatConditions::createCollectionObject(const uno::Any& aObject ) | |||
75 | { | |||
76 | return xSheetConditionToFormatCondition( uno::Reference< XHelperInterface >( mxRangeParent, uno::UNO_QUERY_THROW ), mxContext, mxStyles, this, mxParentRangePropertySet, aObject ); | |||
77 | } | |||
78 | ||||
79 | namespace { | |||
80 | ||||
81 | class EnumWrapper : public EnumerationHelper_BASE | |||
82 | { | |||
83 | uno::Reference<container::XIndexAccess > m_xIndexAccess; | |||
84 | uno::Reference<excel::XRange > m_xParentRange; | |||
85 | uno::Reference<uno::XComponentContext > m_xContext; | |||
86 | uno::Reference<excel::XStyles > m_xStyles; | |||
87 | uno::Reference<excel::XFormatConditions > m_xParentCollection; | |||
88 | uno::Reference<beans::XPropertySet > m_xProps; | |||
89 | ||||
90 | sal_Int32 nIndex; | |||
91 | public: | |||
92 | EnumWrapper( const uno::Reference< container::XIndexAccess >& xIndexAccess, const uno::Reference<excel::XRange >& xRange, const uno::Reference<uno::XComponentContext >& xContext, const uno::Reference<excel::XStyles >& xStyles, const uno::Reference< excel::XFormatConditions >& xCollection, const uno::Reference<beans::XPropertySet >& xProps ) : m_xIndexAccess( xIndexAccess ), m_xParentRange( xRange ), m_xContext( xContext ), m_xStyles( xStyles ), m_xParentCollection( xCollection ), m_xProps( xProps ), nIndex( 0 ) {} | |||
93 | virtual sal_Bool SAL_CALL hasMoreElements( ) override | |||
94 | { | |||
95 | return ( nIndex < m_xIndexAccess->getCount() ); | |||
96 | } | |||
97 | ||||
98 | virtual uno::Any SAL_CALL nextElement( ) override | |||
99 | { | |||
100 | try | |||
101 | { | |||
102 | if ( nIndex < m_xIndexAccess->getCount() ) | |||
103 | return xSheetConditionToFormatCondition( uno::Reference< XHelperInterface >( m_xParentRange, uno::UNO_QUERY_THROW ), m_xContext, m_xStyles, m_xParentCollection, m_xProps, m_xIndexAccess->getByIndex( nIndex++ ) ); | |||
104 | } | |||
105 | catch (const container::NoSuchElementException&) | |||
106 | { | |||
107 | throw; | |||
108 | } | |||
109 | catch (const lang::WrappedTargetException&) | |||
110 | { | |||
111 | throw; | |||
112 | } | |||
113 | catch (const uno::RuntimeException&) | |||
114 | { | |||
115 | throw; | |||
116 | } | |||
117 | catch (const uno::Exception& e) | |||
118 | { | |||
119 | css::uno::Any a(cppu::getCaughtException()); | |||
120 | throw css::lang::WrappedTargetException( | |||
121 | "wrapped Exception " + e.Message, | |||
122 | css::uno::Reference<css::uno::XInterface>(), a); | |||
123 | } | |||
124 | throw container::NoSuchElementException(); | |||
125 | } | |||
126 | }; | |||
127 | ||||
128 | } | |||
129 | ||||
130 | uno::Reference< excel::XFormatCondition > SAL_CALL | |||
131 | ScVbaFormatConditions::Add( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2 ) | |||
132 | { | |||
133 | return Add( _nType, _aOperator, _aFormula1, _aFormula2, uno::Reference< excel::XStyle >() ); | |||
134 | } | |||
135 | ||||
136 | uno::Reference< excel::XFormatCondition > | |||
137 | ScVbaFormatConditions::Add( ::sal_Int32 _nType, const uno::Any& _aOperator, const uno::Any& _aFormula1, const uno::Any& _aFormula2, const css::uno::Reference< excel::XStyle >& _xStyle ) | |||
138 | { | |||
139 | // #TODO | |||
140 | // #FIXME | |||
141 | // This method will NOT handle r1c1 formulas [*]and only assumes that | |||
142 | // the formulas are _xlA1 based ( need to hook into calc work this should | |||
143 | // address this ) | |||
144 | // [*] reason: getA1Formula method below is just a hook and just | |||
145 | // returns what it gets ( e.g. doesn't convert anything ) | |||
146 | uno::Reference< excel::XStyle > xStyle( _xStyle ); | |||
147 | uno::Reference< excel::XFormatCondition > xFormatCondition; | |||
148 | try | |||
149 | { | |||
150 | OUString sStyleName; | |||
151 | if ( !xStyle.is() ) | |||
152 | { | |||
153 | sStyleName = getStyleName(); | |||
154 | xStyle = mxStyles->Add(sStyleName, uno::Any() ); | |||
155 | } | |||
156 | else | |||
157 | { | |||
158 | sStyleName = xStyle->getName(); | |||
159 | } | |||
160 | ||||
161 | std::vector< beans::PropertyValue > aPropertyValueVector; | |||
162 | sheet::ConditionOperator aType = ScVbaFormatCondition::retrieveAPIType(_nType, uno::Reference< sheet::XSheetCondition >() ); | |||
163 | uno::Any aValue; | |||
164 | ||||
165 | if ( aType == sheet::ConditionOperator_FORMULA) | |||
166 | aValue <<= sheet::ConditionOperator_FORMULA; | |||
167 | else | |||
168 | aValue <<= ScVbaFormatCondition::retrieveAPIOperator(_aOperator); | |||
169 | ||||
170 | beans::PropertyValue aProperty( "Operator", 0, aValue, beans::PropertyState_DIRECT_VALUE ); | |||
171 | aPropertyValueVector.push_back( aProperty ); | |||
172 | ||||
173 | if ( _aFormula1.hasValue() ) | |||
174 | { | |||
175 | beans::PropertyValue aProp( "Formula1", 0, uno::makeAny( getA1Formula( _aFormula1 ) ), beans::PropertyState_DIRECT_VALUE ); | |||
176 | aPropertyValueVector.push_back( aProp ); | |||
177 | } | |||
178 | if ( _aFormula2.hasValue() ) | |||
179 | { | |||
180 | beans::PropertyValue aProp( "Formula2", 0, uno::makeAny( getA1Formula( _aFormula2 ) ), beans::PropertyState_DIRECT_VALUE ); | |||
181 | aPropertyValueVector.push_back( aProp ); | |||
182 | } | |||
183 | aProperty.Name = "StyleName"; | |||
184 | aProperty.Value <<= sStyleName; | |||
185 | ||||
186 | mxSheetConditionalEntries->addNew(comphelper::containerToSequence(aPropertyValueVector)); | |||
187 | for (sal_Int32 i = mxSheetConditionalEntries->getCount()-1; i >= 0; i--) | |||
188 | { | |||
189 | uno::Reference< sheet::XSheetConditionalEntry > xSheetConditionalEntry( mxSheetConditionalEntries->getByIndex(i), uno::UNO_QUERY_THROW ); | |||
190 | if (xSheetConditionalEntry->getStyleName() == sStyleName) | |||
191 | { | |||
192 | xFormatCondition = new ScVbaFormatCondition(uno::Reference< XHelperInterface >( mxRangeParent, uno::UNO_QUERY_THROW ), mxContext, xSheetConditionalEntry, xStyle, this, mxParentRangePropertySet); | |||
193 | notifyRange(); | |||
194 | return xFormatCondition; | |||
195 | } | |||
196 | } | |||
197 | } | |||
198 | catch (uno::Exception& ) | |||
199 | { | |||
200 | } | |||
201 | DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILEDErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 89 ), OUString() ); | |||
202 | return xFormatCondition; | |||
203 | } | |||
204 | ||||
205 | uno::Reference< container::XEnumeration > SAL_CALL | |||
206 | ScVbaFormatConditions::createEnumeration() | |||
207 | { | |||
208 | return new EnumWrapper( m_xIndexAccess, mxRangeParent, mxContext, mxStyles, this, mxParentRangePropertySet ); | |||
209 | } | |||
210 | ||||
211 | void | |||
212 | ScVbaFormatConditions::notifyRange() | |||
213 | { | |||
214 | try | |||
215 | { | |||
216 | mxParentRangePropertySet->setPropertyValue(SC_UNONAME_CONDFMT"ConditionalFormat", uno::makeAny( mxSheetConditionalEntries )); | |||
217 | } | |||
218 | catch (uno::Exception& ) | |||
219 | { | |||
220 | DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILEDErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 89 ), OUString()); | |||
221 | } | |||
222 | } | |||
223 | ||||
224 | OUString | |||
225 | ScVbaFormatConditions::getA1Formula(const css::uno::Any& _aFormula) | |||
226 | { | |||
227 | // #TODO, #FIXME hook-in proper formula conversion detection & logic | |||
228 | OUString sFormula; | |||
229 | if ( !( _aFormula >>= sFormula ) ) | |||
230 | DebugHelper::basicexception(ERRCODE_BASIC_BAD_PARAMETERErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 7), OUString() ); | |||
231 | return sFormula; | |||
232 | } | |||
233 | ||||
234 | OUString | |||
235 | ScVbaFormatConditions::getStyleName() | |||
236 | { | |||
237 | ScVbaStyles* pStyles = static_cast< ScVbaStyles* >( mxStyles.get() ); | |||
238 | if ( !pStyles ) | |||
239 | DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILEDErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 89 ), OUString() ); | |||
240 | uno::Sequence< OUString > sCellStyleNames = pStyles->getStyleNames(); | |||
241 | return ContainerUtilities::getUniqueName(sCellStyleNames, "Excel_CondFormat", "_"); | |||
242 | } | |||
243 | ||||
244 | void | |||
245 | ScVbaFormatConditions::removeFormatCondition( const OUString& _sStyleName, bool _bRemoveStyle) | |||
246 | { | |||
247 | try | |||
248 | { | |||
249 | sal_Int32 nElems = mxSheetConditionalEntries->getCount(); | |||
250 | for (sal_Int32 i = 0; i < nElems; i++) | |||
251 | { | |||
252 | uno::Reference< sheet::XSheetConditionalEntry > xSheetConditionalEntry( mxSheetConditionalEntries->getByIndex(i), uno::UNO_QUERY_THROW ); | |||
253 | if (_sStyleName == xSheetConditionalEntry->getStyleName()) | |||
254 | { | |||
255 | mxSheetConditionalEntries->removeByIndex(i); | |||
256 | if (_bRemoveStyle) | |||
257 | { | |||
258 | ScVbaStyles* pStyles = static_cast< ScVbaStyles* >( mxStyles.get() ); | |||
259 | if ( !pStyles ) | |||
260 | DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILEDErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 89 ), OUString()); | |||
261 | pStyles->Delete( _sStyleName ); | |||
262 | } | |||
263 | return; | |||
264 | } | |||
265 | } | |||
266 | } | |||
267 | catch (const uno::Exception&) | |||
268 | { | |||
269 | DebugHelper::basicexception(ERRCODE_BASIC_METHOD_FAILEDErrCode( ErrCodeArea::Sbx, ErrCodeClass::Runtime, 89 ), OUString()); | |||
270 | } | |||
271 | } | |||
272 | ||||
273 | OUString | |||
274 | ScVbaFormatConditions::getServiceImplName() | |||
275 | { | |||
276 | return "ScVbaFormatConditions"; | |||
277 | } | |||
278 | ||||
279 | uno::Sequence< OUString > | |||
280 | ScVbaFormatConditions::getServiceNames() | |||
281 | { | |||
282 | static uno::Sequence< OUString > const aServiceNames | |||
283 | { | |||
284 | "ooo.vba.excel.FormatConditions" | |||
285 | }; | |||
286 | return aServiceNames; | |||
287 | } | |||
288 | ||||
289 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H |
20 | #define INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H |
21 | |
22 | #include "sal/config.h" |
23 | |
24 | #include <cassert> |
25 | #include <cstddef> |
26 | |
27 | #if defined LIBO_INTERNAL_ONLY1 |
28 | #include <type_traits> |
29 | #endif |
30 | |
31 | #include "rtl/alloc.h" |
32 | |
33 | namespace com |
34 | { |
35 | namespace sun |
36 | { |
37 | namespace star |
38 | { |
39 | namespace uno |
40 | { |
41 | |
42 | class RuntimeException; |
43 | class XInterface; |
44 | class Type; |
45 | class Any; |
46 | |
47 | /** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface. |
48 | Deprecated, please use SAL_NO_ACQUIRE. |
49 | @deprecated |
50 | */ |
51 | enum UnoReference_NoAcquire |
52 | { |
53 | /** This enum value can be used for creating a reference granting a given interface, |
54 | i.e. transferring ownership to it. |
55 | */ |
56 | UNO_REF_NO_ACQUIRE |
57 | }; |
58 | |
59 | /** This base class serves as a base class for all template reference classes and |
60 | has been introduced due to compiler problems with templated operators ==, =!. |
61 | */ |
62 | class BaseReference |
63 | { |
64 | protected: |
65 | /** the interface pointer |
66 | */ |
67 | XInterface * _pInterface; |
68 | |
69 | /** Queries given interface for type rType. |
70 | |
71 | @param pInterface interface pointer |
72 | @param rType interface type |
73 | @return interface of demanded type (may be null) |
74 | */ |
75 | inline static XInterface * SAL_CALL iquery( XInterface * pInterface, const Type & rType ); |
76 | /** Queries given interface for type rType. |
77 | Throws a RuntimeException if the demanded interface cannot be queried. |
78 | |
79 | @param pInterface interface pointer |
80 | @param rType interface type |
81 | @return interface of demanded type |
82 | */ |
83 | inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType ); |
84 | |
85 | public: |
86 | /** Gets interface pointer. This call does not acquire the interface. |
87 | |
88 | @return UNacquired interface pointer |
89 | */ |
90 | XInterface * SAL_CALL get() const |
91 | { return _pInterface; } |
92 | |
93 | /** Checks if reference is null. |
94 | |
95 | @return true if reference acquires an interface, i.e. true if it is not null |
96 | */ |
97 | bool SAL_CALL is() const |
98 | { return (NULL__null != _pInterface); } |
99 | |
100 | #if defined LIBO_INTERNAL_ONLY1 |
101 | /** Checks if reference is null. |
102 | |
103 | @return true if reference acquires an interface, i.e. true if it is not null |
104 | */ |
105 | explicit operator bool() const |
106 | { return is(); } |
107 | #endif |
108 | |
109 | /** Equality operator: compares two interfaces |
110 | Checks if both references are null or refer to the same object. |
111 | |
112 | @param pInterface another interface |
113 | @return true if both references are null or refer to the same object, false otherwise |
114 | */ |
115 | inline bool SAL_CALL operator == ( XInterface * pInterface ) const; |
116 | /** Inequality operator: compares two interfaces |
117 | Checks if both references are null or refer to the same object. |
118 | |
119 | @param pInterface another interface |
120 | @return false if both references are null or refer to the same object, true otherwise |
121 | */ |
122 | inline bool SAL_CALL operator != ( XInterface * pInterface ) const; |
123 | |
124 | /** Equality operator: compares two interfaces |
125 | Checks if both references are null or refer to the same object. |
126 | |
127 | @param rRef another reference |
128 | @return true if both references are null or refer to the same object, false otherwise |
129 | */ |
130 | inline bool SAL_CALL operator == ( const BaseReference & rRef ) const; |
131 | /** Inequality operator: compares two interfaces |
132 | Checks if both references are null or refer to the same object. |
133 | |
134 | @param rRef another reference |
135 | @return false if both references are null or refer to the same object, true otherwise |
136 | */ |
137 | inline bool SAL_CALL operator != ( const BaseReference & rRef ) const; |
138 | |
139 | /** Needed by some STL containers. |
140 | |
141 | @param rRef another reference |
142 | @return true, if this reference is less than rRef |
143 | */ |
144 | inline bool SAL_CALL operator < ( const BaseReference & rRef ) const; |
145 | }; |
146 | |
147 | /** Enum defining UNO_QUERY for implicit interface query. |
148 | */ |
149 | enum UnoReference_Query |
150 | { |
151 | /** This enum value can be used for implicit interface query. |
152 | */ |
153 | UNO_QUERY |
154 | }; |
155 | /** Enum defining UNO_QUERY_THROW for implicit interface query. |
156 | If the demanded interface is unavailable, then a RuntimeException is thrown. |
157 | */ |
158 | enum UnoReference_QueryThrow |
159 | { |
160 | /** This enum value can be used for implicit interface query. |
161 | */ |
162 | UNO_QUERY_THROW |
163 | }; |
164 | /** Enum defining UNO_SET_THROW for throwing if attempts are made to assign a null |
165 | interface |
166 | |
167 | @since UDK 3.2.8 |
168 | */ |
169 | enum UnoReference_SetThrow |
170 | { |
171 | UNO_SET_THROW |
172 | }; |
173 | |
174 | /** Template reference class for interface type derived from BaseReference. |
175 | A special constructor given the UNO_QUERY identifier queries interfaces |
176 | for reference type. |
177 | */ |
178 | template< class interface_type > |
179 | class SAL_DLLPUBLIC_RTTI__attribute__ ((type_visibility("default"))) Reference : public BaseReference |
180 | { |
181 | /** Queries given interface for type interface_type. |
182 | |
183 | @param pInterface interface pointer |
184 | @return interface of demanded type (may be null) |
185 | */ |
186 | inline static XInterface * SAL_CALL iquery( XInterface * pInterface ); |
187 | /** Queries given interface for type interface_type. |
188 | Throws a RuntimeException if the demanded interface cannot be queried. |
189 | |
190 | @param pInterface interface pointer |
191 | @return interface of demanded type |
192 | */ |
193 | inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface ); |
194 | /** Returns the given interface if it is not <NULL/>, throws a RuntimeException otherwise. |
195 | |
196 | @param pInterface interface pointer |
197 | @return pInterface |
198 | */ |
199 | inline static interface_type * SAL_CALL iset_throw( interface_type * pInterface ); |
200 | |
201 | /** Cast from an "interface pointer" (e.g., BaseReference::_pInterface) to a |
202 | pointer to this interface_type. |
203 | |
204 | To work around ambiguities in the case of multiple-inheritance interface |
205 | types (which inherit XInterface more than once), use reinterpret_cast |
206 | (resp. a sequence of two static_casts, to avoid warnings about |
207 | reinterpret_cast used between related classes) to switch from a pointer |
208 | to XInterface to a pointer to this derived interface_type. In |
209 | principle, this is not guaranteed to work. In practice, it seems to |
210 | work on all supported platforms. |
211 | */ |
212 | static interface_type * castFromXInterface(XInterface * p) { |
213 | return static_cast< interface_type * >(static_cast< void * >(p)); |
214 | } |
215 | |
216 | /** Cast from a pointer to this interface_type to an "interface pointer" |
217 | (e.g., BaseReference::_pInterface). |
218 | |
219 | To work around ambiguities in the case of multiple-inheritance interface |
220 | types (which inherit XInterface more than once), use reinterpret_cast |
221 | (resp. a sequence of two static_casts, to avoid warnings about |
222 | reinterpret_cast used between related classes) to switch from a pointer |
223 | to this derived interface_type to a pointer to XInterface. In |
224 | principle, this is not guaranteed to work. In practice, it seems to |
225 | work on all supported platforms. |
226 | */ |
227 | static XInterface * castToXInterface(interface_type * p) { |
228 | return static_cast< XInterface * >(static_cast< void * >(p)); |
229 | } |
230 | |
231 | public: |
232 | /// @cond INTERNAL |
233 | // these are here to force memory de/allocation to sal lib. |
234 | static void * SAL_CALL operator new ( ::size_t nSize ) |
235 | { return ::rtl_allocateMemory( nSize ); } |
236 | static void SAL_CALL operator delete ( void * pMem ) |
237 | { ::rtl_freeMemory( pMem ); } |
238 | static void * SAL_CALL operator new ( ::size_t, void * pMem ) |
239 | { return pMem; } |
240 | static void SAL_CALL operator delete ( void *, void * ) |
241 | {} |
242 | /// @endcond |
243 | |
244 | /** Destructor: Releases interface if set. |
245 | */ |
246 | inline ~Reference() COVERITY_NOEXCEPT_FALSE; |
247 | |
248 | /** Default Constructor: Sets null reference. |
249 | */ |
250 | inline Reference(); |
251 | |
252 | /** Copy constructor: Copies interface reference. |
253 | |
254 | @param rRef another reference |
255 | */ |
256 | inline Reference( const Reference< interface_type > & rRef ); |
257 | |
258 | #if defined LIBO_INTERNAL_ONLY1 |
259 | /** Move constructor |
260 | |
261 | @param rRef another reference |
262 | */ |
263 | inline Reference( Reference< interface_type > && rRef ) noexcept; |
264 | |
265 | /** Up-casting conversion constructor: Copies interface reference. |
266 | |
267 | Does not work for up-casts to ambiguous bases. For the special case of |
268 | up-casting to Reference< XInterface >, see the corresponding conversion |
269 | operator. |
270 | |
271 | @param rRef another reference |
272 | */ |
273 | template< class derived_type > |
274 | inline Reference( |
275 | const Reference< derived_type > & rRef, |
276 | std::enable_if_t< |
277 | std::is_base_of_v<interface_type, derived_type> |
278 | && !std::is_same_v<interface_type, XInterface>, void *> = nullptr); |
279 | #endif |
280 | |
281 | /** Constructor: Sets given interface pointer. |
282 | |
283 | @param pInterface an interface pointer |
284 | */ |
285 | inline Reference( interface_type * pInterface ); |
286 | |
287 | /** Constructor: Sets given interface pointer without acquiring it. |
288 | |
289 | @param pInterface another reference |
290 | @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors |
291 | */ |
292 | inline Reference( interface_type * pInterface, __sal_NoAcquire dummy); |
293 | /** Constructor: Sets given interface pointer without acquiring it. |
294 | Deprecated, please use SAL_NO_ACQUIRE version. |
295 | |
296 | @deprecated |
297 | @param pInterface another reference |
298 | @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors |
299 | */ |
300 | inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) Reference( interface_type * pInterface, UnoReference_NoAcquire dummy ); |
301 | |
302 | /** Constructor: Queries given interface for reference interface type (interface_type). |
303 | |
304 | @param rRef another reference |
305 | @param dummy UNO_QUERY to force obvious distinction to other constructors |
306 | */ |
307 | inline Reference( const BaseReference & rRef, UnoReference_Query dummy ); |
308 | /** Constructor: Queries given interface for reference interface type (interface_type). |
309 | |
310 | @param pInterface an interface pointer |
311 | @param dummy UNO_QUERY to force obvious distinction to other constructors |
312 | */ |
313 | inline Reference( XInterface * pInterface, UnoReference_Query dummy); |
314 | /** Constructor: Queries given any for reference interface type (interface_type). |
315 | |
316 | @param rAny an any |
317 | @param dummy UNO_QUERY to force obvious distinction to other constructors |
318 | */ |
319 | inline Reference( const Any & rAny, UnoReference_Query dummy); |
320 | /** Constructor: Queries given interface for reference interface type (interface_type). |
321 | Throws a RuntimeException if the demanded interface cannot be queried. |
322 | |
323 | @param rRef another reference |
324 | @param dummy UNO_QUERY_THROW to force obvious distinction |
325 | to other constructors |
326 | */ |
327 | inline Reference( const BaseReference & rRef, UnoReference_QueryThrow dummy ); |
328 | #ifdef LIBO_INTERNAL_ONLY1 |
329 | /** |
330 | Prevent code from calling the QUERY_THROW constructor, when they meant to use the SET_THROW constructor. |
331 | */ |
332 | Reference( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete; |
333 | #endif |
334 | /** Constructor: Queries given interface for reference interface type (interface_type). |
335 | Throws a RuntimeException if the demanded interface cannot be queried. |
336 | |
337 | @param pInterface an interface pointer |
338 | @param dummy UNO_QUERY_THROW to force obvious distinction |
339 | to other constructors |
340 | */ |
341 | inline Reference( XInterface * pInterface, UnoReference_QueryThrow dummy ); |
342 | /** Constructor: Queries given any for reference interface type (interface_type). |
343 | Throws a RuntimeException if the demanded interface cannot be queried. |
344 | |
345 | @param rAny an any |
346 | @param dummy UNO_QUERY_THROW to force obvious distinction |
347 | to other constructors |
348 | */ |
349 | inline Reference( const Any & rAny, UnoReference_QueryThrow dummy ); |
350 | /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException |
351 | if the source interface is NULL. |
352 | |
353 | @param rRef another interface reference of the same type |
354 | @param dummy UNO_SET_THROW to distinguish from default copy constructor |
355 | |
356 | @since UDK 3.2.8 |
357 | */ |
358 | inline Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy ); |
359 | /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException |
360 | if the source interface is NULL. |
361 | |
362 | @param pInterface an interface pointer |
363 | @param dummy UNO_SET_THROW to distinguish from default assignment constructor |
364 | |
365 | @since UDK 3.2.8 |
366 | */ |
367 | inline Reference( interface_type * pInterface, UnoReference_SetThrow dummy ); |
368 | |
369 | /** Cast operator to Reference< XInterface >: Reference objects are binary compatible and |
370 | any interface must be derived from com.sun.star.uno.XInterface. |
371 | This a useful direct cast possibility. |
372 | */ |
373 | SAL_CALL operator const Reference< XInterface > & () const |
374 | { return * reinterpret_cast< const Reference< XInterface > * >( this ); } |
375 | |
376 | /** Dereference operator: Used to call interface methods. |
377 | |
378 | @return UNacquired interface pointer |
379 | */ |
380 | interface_type * SAL_CALL operator -> () const { |
381 | assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) : __assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h" , 381, __extension__ __PRETTY_FUNCTION__)); |
382 | return castFromXInterface(_pInterface); |
383 | } |
384 | |
385 | /** Indirection operator. |
386 | |
387 | @since LibreOffice 6.3 |
388 | @return UNacquired interface reference |
389 | */ |
390 | interface_type & SAL_CALL operator * () const { |
391 | assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) : __assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h" , 391, __extension__ __PRETTY_FUNCTION__)); |
392 | return *castFromXInterface(_pInterface); |
393 | } |
394 | |
395 | /** Gets interface pointer. This call does not acquire the interface. |
396 | |
397 | @return UNacquired interface pointer |
398 | */ |
399 | interface_type * SAL_CALL get() const |
400 | { return castFromXInterface(_pInterface); } |
401 | |
402 | /** Clears reference, i.e. releases interface. Reference is null after clear() call. |
403 | */ |
404 | inline void SAL_CALL clear(); |
405 | |
406 | /** Sets the given interface. An interface already set will be released. |
407 | |
408 | @param rRef another reference |
409 | @return true, if non-null interface was set |
410 | */ |
411 | inline bool SAL_CALL set( const Reference< interface_type > & rRef ); |
412 | /** Sets the given interface. An interface already set will be released. |
413 | |
414 | @param pInterface another interface |
415 | @return true, if non-null interface was set |
416 | */ |
417 | inline bool SAL_CALL set( interface_type * pInterface ); |
418 | |
419 | /** Sets interface pointer without acquiring it. An interface already set will be released. |
420 | |
421 | @param pInterface an interface pointer |
422 | @param dummy SAL_NO_ACQUIRE to force obvious distinction to set methods |
423 | @return true, if non-null interface was set |
424 | */ |
425 | inline bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire dummy); |
426 | /** Sets interface pointer without acquiring it. An interface already set will be released. |
427 | Deprecated, please use SAL_NO_ACQUIRE version. |
428 | |
429 | @deprecated |
430 | @param pInterface an interface pointer |
431 | @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to set methods |
432 | @return true, if non-null interface was set |
433 | */ |
434 | inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) bool SAL_CALL set( interface_type * pInterface, UnoReference_NoAcquire dummy); |
435 | |
436 | /** Queries given interface for reference interface type (interface_type) and sets it. |
437 | An interface already set will be released. |
438 | |
439 | @param pInterface an interface pointer |
440 | @param dummy UNO_QUERY to force obvious distinction to set methods |
441 | @return true, if non-null interface was set |
442 | */ |
443 | inline bool SAL_CALL set( XInterface * pInterface, UnoReference_Query dummy ); |
444 | /** Queries given interface for reference interface type (interface_type) and sets it. |
445 | An interface already set will be released. |
446 | |
447 | @param rRef another reference |
448 | @param dummy UNO_QUERY to force obvious distinction to set methods |
449 | @return true, if non-null interface was set |
450 | */ |
451 | inline bool SAL_CALL set( const BaseReference & rRef, UnoReference_Query dummy); |
452 | |
453 | /** Queries given any for reference interface type (interface_type) |
454 | and sets it. An interface already set will be released. |
455 | |
456 | @param rAny |
457 | an Any containing an interface |
458 | @param dummy |
459 | UNO_QUERY to force obvious distinction |
460 | to set methods |
461 | @return |
462 | true, if non-null interface was set |
463 | */ |
464 | inline bool set( Any const & rAny, UnoReference_Query dummy ); |
465 | |
466 | /** Queries given interface for reference interface type (interface_type) and sets it. |
467 | An interface already set will be released. |
468 | Throws a RuntimeException if the demanded interface cannot be set. |
469 | |
470 | @param pInterface an interface pointer |
471 | @param dummy UNO_QUERY_THROW to force obvious distinction |
472 | to set methods |
473 | */ |
474 | inline void SAL_CALL set( XInterface * pInterface, UnoReference_QueryThrow dummy ); |
475 | /** Queries given interface for reference interface type (interface_type) and sets it. |
476 | An interface already set will be released. |
477 | Throws a RuntimeException if the demanded interface cannot be set. |
478 | |
479 | @param rRef another reference |
480 | @param dummy UNO_QUERY_THROW to force obvious distinction |
481 | to set methods |
482 | */ |
483 | inline void SAL_CALL set( const BaseReference & rRef, UnoReference_QueryThrow dummy ); |
484 | #ifdef LIBO_INTERNAL_ONLY1 |
485 | /** |
486 | Prevent code from calling the QUERY_THROW version, when they meant to use the SET_THROW version. |
487 | */ |
488 | void set( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete; |
489 | #endif |
490 | |
491 | /** Queries given any for reference interface type (interface_type) and |
492 | sets it. An interface already set will be released. |
493 | Throws a RuntimeException if the demanded interface cannot be set. |
494 | |
495 | @param rAny |
496 | an Any containing an interface |
497 | @param dummy |
498 | UNO_QUERY_THROW to force obvious distinction to set methods |
499 | */ |
500 | inline void set( Any const & rAny, UnoReference_QueryThrow dummy); |
501 | /** sets the given interface |
502 | An interface already set will be released. |
503 | Throws a RuntimeException if the source interface is @b NULL. |
504 | |
505 | @param pInterface an interface pointer |
506 | @param dummy UNO_SET_THROW to force obvious distinction to other set methods |
507 | |
508 | @since UDK 3.2.8 |
509 | */ |
510 | inline void SAL_CALL set( interface_type * pInterface, UnoReference_SetThrow dummy); |
511 | /** sets the given interface |
512 | An interface already set will be released. |
513 | Throws a RuntimeException if the source interface is @b NULL. |
514 | |
515 | @param rRef an interface reference |
516 | @param dummy UNO_SET_THROW to force obvious distinction to other set methods |
517 | |
518 | @since UDK 3.2.8 |
519 | */ |
520 | inline void SAL_CALL set( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy); |
521 | |
522 | |
523 | /** Assignment operator: Acquires given interface pointer and sets reference. |
524 | An interface already set will be released. |
525 | |
526 | @param pInterface an interface pointer |
527 | @return this reference |
528 | */ |
529 | inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface ); |
530 | /** Assignment operator: Acquires given interface reference and sets reference. |
531 | An interface already set will be released. |
532 | |
533 | @param rRef an interface reference |
534 | @return this reference |
535 | */ |
536 | inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef ); |
537 | #if defined LIBO_INTERNAL_ONLY1 |
538 | /** Assignment move operator: Acquires given interface reference and sets reference. |
539 | An interface already set will be released. |
540 | |
541 | @param rRef an interface reference |
542 | @return this reference |
543 | */ |
544 | inline Reference< interface_type > & SAL_CALL operator = ( Reference< interface_type > && rRef ) noexcept; |
545 | #endif |
546 | /** Queries given interface reference for type interface_type. |
547 | |
548 | @param rRef interface reference |
549 | @return interface reference of demanded type (may be null) |
550 | */ |
551 | SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef ); |
552 | /** Queries given interface for type interface_type. |
553 | |
554 | @param pInterface interface pointer |
555 | @return interface reference of demanded type (may be null) |
556 | */ |
557 | SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface ); |
558 | }; |
559 | |
560 | } |
561 | } |
562 | } |
563 | } |
564 | |
565 | #endif |
566 | |
567 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |