Bug Summary

File:home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx
Warning:line 571, column 19
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name request.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SFX2_DLLIMPLEMENTATION -D ENABLE_CUPS -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sfx2/inc -I /home/maarten/src/libreoffice/core/sfx2/source/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sfx2/sdi -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx

/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx

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 <memory>
21#include <com/sun/star/frame/DispatchStatement.hpp>
22#include <com/sun/star/container/XIndexReplace.hpp>
23#include <com/sun/star/beans/PropertyValue.hpp>
24#include <com/sun/star/uno/Sequence.hxx>
25#include <com/sun/star/beans/XPropertySet.hpp>
26#include <com/sun/star/util/URLTransformer.hpp>
27#include <com/sun/star/util/XURLTransformer.hpp>
28#include <com/sun/star/frame/XDispatchRecorderSupplier.hpp>
29#include <svl/itemiter.hxx>
30#include <sal/log.hxx>
31#include <osl/diagnose.h>
32#include <tools/debug.hxx>
33
34#include <svl/itempool.hxx>
35#include <itemdel.hxx>
36
37#include <comphelper/processfactory.hxx>
38
39#include <svl/hint.hxx>
40
41#include <sfx2/request.hxx>
42#include <sfx2/dispatch.hxx>
43#include <sfx2/msg.hxx>
44#include <sfx2/viewfrm.hxx>
45#include <sfx2/objface.hxx>
46#include <sfx2/sfxuno.hxx>
47
48
49using namespace ::com::sun::star;
50
51struct SfxRequest_Impl: public SfxListener
52
53/* [Description]
54
55 Implementation structure of the <SfxRequest> class.
56*/
57
58{
59 SfxRequest* pAnti; // Owner because of dying pool
60 OUString aTarget; // if possible from target object set by App
61 SfxItemPool* pPool; // ItemSet build with this pool
62 std::unique_ptr<SfxPoolItem> pRetVal; // Return value belongs to itself
63 SfxShell* pShell; // run from this shell
64 const SfxSlot* pSlot; // executed Slot
65 sal_uInt16 nModifier; // which Modifier was pressed?
66 bool bDone; // at all executed
67 bool bIgnored; // Cancelled by the User
68 bool bCancelled; // no longer notify
69 SfxCallMode nCallMode; // Synch/Asynch/API/Record
70 bool bAllowRecording;
71 std::unique_ptr<SfxAllItemSet>
72 pInternalArgs;
73 SfxViewFrame* pViewFrame;
74
75 css::uno::Reference< css::frame::XDispatchRecorder > xRecorder;
76 css::uno::Reference< css::util::XURLTransformer > xTransform;
77
78 explicit SfxRequest_Impl( SfxRequest *pOwner )
79 : pAnti( pOwner)
80 , pPool(nullptr)
81 , pShell(nullptr)
82 , pSlot(nullptr)
83 , nModifier(0)
84 , bDone(false)
85 , bIgnored(false)
86 , bCancelled(false)
87 , nCallMode( SfxCallMode::SYNCHRON )
88 , bAllowRecording( false )
89 , pViewFrame(nullptr)
90 {
91 }
92
93 void SetPool( SfxItemPool *pNewPool );
94 virtual void Notify( SfxBroadcaster &rBC, const SfxHint &rHint ) override;
95 void Record( const uno::Sequence < beans::PropertyValue >& rArgs );
96};
97
98
99void SfxRequest_Impl::Notify( SfxBroadcaster&, const SfxHint &rHint )
100{
101 if ( rHint.GetId() == SfxHintId::Dying )
102 pAnti->Cancel();
103}
104
105
106void SfxRequest_Impl::SetPool( SfxItemPool *pNewPool )
107{
108 if ( pNewPool != pPool )
109 {
110 if ( pPool )
111 EndListening( pPool->BC() );
112 pPool = pNewPool;
113 if ( pNewPool )
114 StartListening( pNewPool->BC() );
115 }
116}
117
118
119SfxRequest::~SfxRequest()
120{
121 // Leave out Done() marked requests with 'rem'
122 if ( pImpl->xRecorder.is() && !pImpl->bDone && !pImpl->bIgnored )
123 pImpl->Record( uno::Sequence < beans::PropertyValue >() );
124
125 // Clear object
126 pArgs.reset();
127 if ( pImpl->pRetVal )
128 DeleteItemOnIdle(std::move(pImpl->pRetVal));
129}
130
131
132SfxRequest::SfxRequest
133(
134 const SfxRequest& rOrig
135)
136: SfxHint( rOrig ),
137 nSlot(rOrig.nSlot),
138 pArgs(rOrig.pArgs? new SfxAllItemSet(*rOrig.pArgs): nullptr),
139 pImpl( new SfxRequest_Impl(this) )
140{
141 pImpl->bAllowRecording = rOrig.pImpl->bAllowRecording;
142 pImpl->bDone = false;
143 pImpl->bIgnored = false;
144 pImpl->pShell = nullptr;
145 pImpl->pSlot = nullptr;
146 pImpl->nCallMode = rOrig.pImpl->nCallMode;
147 pImpl->aTarget = rOrig.pImpl->aTarget;
148 pImpl->nModifier = rOrig.pImpl->nModifier;
149
150 // deep copy needed !
151 pImpl->pInternalArgs.reset( rOrig.pImpl->pInternalArgs ? new SfxAllItemSet(*rOrig.pImpl->pInternalArgs) : nullptr);
152
153 if ( pArgs )
154 pImpl->SetPool( pArgs->GetPool() );
155 else
156 pImpl->SetPool( rOrig.pImpl->pPool );
157
158 // setup macro recording if it was in the original SfxRequest
159 if (!rOrig.pImpl->pViewFrame || !rOrig.pImpl->xRecorder.is())
160 return;
161
162 nSlot = rOrig.nSlot;
163 pImpl->pViewFrame = rOrig.pImpl->pViewFrame;
164 if (pImpl->pViewFrame->GetDispatcher()->GetShellAndSlot_Impl(nSlot, &pImpl->pShell, &pImpl->pSlot, true, true))
165 {
166 pImpl->SetPool( &pImpl->pShell->GetPool() );
167 pImpl->xRecorder = SfxRequest::GetMacroRecorder(pImpl->pViewFrame);
168 if (pImpl->xRecorder)
169 pImpl->xTransform = util::URLTransformer::create(comphelper::getProcessComponentContext());
170 pImpl->aTarget = pImpl->pShell->GetName();
171 }
172 else
173 {
174 SAL_WARN("sfx", "Recording unsupported slot: " << pImpl->pPool->GetSlotId(nSlot))do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sfx")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording unsupported slot: " << pImpl->
pPool->GetSlotId(nSlot)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "174" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording unsupported slot: " <<
pImpl->pPool->GetSlotId(nSlot)), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording unsupported slot: "
<< pImpl->pPool->GetSlotId(nSlot); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "174" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording unsupported slot: " << pImpl->
pPool->GetSlotId(nSlot)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "174" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording unsupported slot: " <<
pImpl->pPool->GetSlotId(nSlot)), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording unsupported slot: "
<< pImpl->pPool->GetSlotId(nSlot); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "174" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
175 }
176}
177
178
179SfxRequest::SfxRequest
180(
181 SfxViewFrame* pViewFrame,
182 sal_uInt16 nSlotId
183
184)
185
186/* [Description]
187
188 With this constructor events can subsequently be recorded that are not run
189 across SfxDispatcher (eg from KeyInput() or mouse events). For this, a
190 SfxRequest instance is created by this constructor and then proceed
191 exactly as with a SfxRequest that in a <Slot-Execute-Method> is given as a
192 parameter.
193*/
194
195: nSlot(nSlotId),
196 pImpl( new SfxRequest_Impl(this) )
197{
198 pImpl->bDone = false;
199 pImpl->bIgnored = false;
200 pImpl->SetPool( &pViewFrame->GetPool() );
201 pImpl->pShell = nullptr;
202 pImpl->pSlot = nullptr;
203 pImpl->nCallMode = SfxCallMode::SYNCHRON;
204 pImpl->pViewFrame = pViewFrame;
205 if( pImpl->pViewFrame->GetDispatcher()->GetShellAndSlot_Impl( nSlotId, &pImpl->pShell, &pImpl->pSlot, true, true ) )
17
Value assigned to field 'pSlot'
18
Assuming the condition is false
19
Taking false branch
206 {
207 pImpl->SetPool( &pImpl->pShell->GetPool() );
208 pImpl->xRecorder = SfxRequest::GetMacroRecorder( pViewFrame );
209 if (pImpl->xRecorder)
210 pImpl->xTransform = util::URLTransformer::create(comphelper::getProcessComponentContext());
211 pImpl->aTarget = pImpl->pShell->GetName();
212 }
213 else
214 {
215 SAL_WARN( "sfx", "Recording unsupported slot: " << pImpl->pPool->GetSlotId(nSlotId) )do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "sfx")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording unsupported slot: " << pImpl->
pPool->GetSlotId(nSlotId)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "215" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording unsupported slot: " <<
pImpl->pPool->GetSlotId(nSlotId)), 0); } else { ::std::
ostringstream sal_detail_stream; sal_detail_stream << "Recording unsupported slot: "
<< pImpl->pPool->GetSlotId(nSlotId); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "215" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording unsupported slot: " << pImpl->
pPool->GetSlotId(nSlotId)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "215" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording unsupported slot: " <<
pImpl->pPool->GetSlotId(nSlotId)), 0); } else { ::std::
ostringstream sal_detail_stream; sal_detail_stream << "Recording unsupported slot: "
<< pImpl->pPool->GetSlotId(nSlotId); ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "215" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
20
Taking true branch
21
'Default' branch taken. Execution continues on line 215
22
Loop condition is false. Exiting loop
216 }
217}
218
219
220SfxRequest::SfxRequest
221(
222 sal_uInt16 nSlotId, // executed <Slot-Id>
223 SfxCallMode nMode, // Synch/API/...
224 SfxItemPool& rPool // necessary for the SfxItemSet for parameters
225)
226
227// creates a SfxRequest without arguments
228
229: nSlot(nSlotId),
230 pImpl( new SfxRequest_Impl(this) )
231{
232 pImpl->bDone = false;
233 pImpl->bIgnored = false;
234 pImpl->SetPool( &rPool );
235 pImpl->pShell = nullptr;
236 pImpl->pSlot = nullptr;
237 pImpl->nCallMode = nMode;
238}
239
240SfxRequest::SfxRequest
241(
242 const SfxSlot* pSlot, // executed <Slot-Id>
243 const css::uno::Sequence < css::beans::PropertyValue >& rArgs,
244 SfxCallMode nMode, // Synch/API/...
245 SfxItemPool& rPool // necessary for the SfxItemSet for parameters
246)
247: nSlot(pSlot->GetSlotId()),
248 pArgs(new SfxAllItemSet(rPool)),
249 pImpl( new SfxRequest_Impl(this) )
250{
251 pImpl->bDone = false;
252 pImpl->bIgnored = false;
253 pImpl->SetPool( &rPool );
254 pImpl->pShell = nullptr;
255 pImpl->pSlot = nullptr;
256 pImpl->nCallMode = nMode;
257 TransformParameters( nSlot, rArgs, *pArgs, pSlot );
258}
259
260
261SfxRequest::SfxRequest
262(
263 sal_uInt16 nSlotId,
264 SfxCallMode nMode,
265 const SfxAllItemSet& rSfxArgs
266)
267
268// creates a SfxRequest with arguments
269
270: nSlot(nSlotId),
271 pArgs(new SfxAllItemSet(rSfxArgs)),
272 pImpl( new SfxRequest_Impl(this) )
273{
274 pImpl->bDone = false;
275 pImpl->bIgnored = false;
276 pImpl->SetPool( rSfxArgs.GetPool() );
277 pImpl->pShell = nullptr;
278 pImpl->pSlot = nullptr;
279 pImpl->nCallMode = nMode;
280}
281
282
283SfxRequest::SfxRequest
284(
285 sal_uInt16 nSlotId,
286 SfxCallMode nMode,
287 const SfxAllItemSet& rSfxArgs,
288 const SfxAllItemSet& rSfxInternalArgs
289)
290: SfxRequest(nSlotId, nMode, rSfxArgs)
291{
292 SetInternalArgs_Impl(rSfxInternalArgs);
293}
294
295SfxCallMode SfxRequest::GetCallMode() const
296{
297 return pImpl->nCallMode;
298}
299
300
301bool SfxRequest::IsSynchronCall() const
302{
303 return SfxCallMode::SYNCHRON == ( SfxCallMode::SYNCHRON & pImpl->nCallMode );
304}
305
306
307void SfxRequest::SetSynchronCall( bool bSynchron )
308{
309 if ( bSynchron )
310 pImpl->nCallMode |= SfxCallMode::SYNCHRON;
311 else
312 pImpl->nCallMode &= ~SfxCallMode::SYNCHRON;
313}
314
315void SfxRequest::SetInternalArgs_Impl( const SfxAllItemSet& rArgs )
316{
317 pImpl->pInternalArgs.reset( new SfxAllItemSet( rArgs ) );
318}
319
320const SfxItemSet* SfxRequest::GetInternalArgs_Impl() const
321{
322 return pImpl->pInternalArgs.get();
323}
324
325
326void SfxRequest_Impl::Record
327(
328 const uno::Sequence < beans::PropertyValue >& rArgs // current Parameter
329)
330
331/* [Description]
332
333 Internal helper method to create a repeatable description of the just
334 executed SfxRequest.
335*/
336
337{
338 if(!xRecorder.is())
339 return;
340
341 OUString aCmd = ".uno:" + OUString::createFromAscii( pSlot->GetUnoName() );
342
343 uno::Reference< container::XIndexReplace > xReplace( xRecorder, uno::UNO_QUERY );
344 if ( xReplace.is() && aCmd == ".uno:InsertText" )
345 {
346 sal_Int32 nCount = xReplace->getCount();
347 if ( nCount )
348 {
349 frame::DispatchStatement aStatement;
350 uno::Any aElement = xReplace->getByIndex(nCount-1);
351 if ( (aElement >>= aStatement) && aStatement.aCommand == aCmd )
352 {
353 OUString aStr;
354 OUString aNew;
355 aStatement.aArgs[0].Value >>= aStr;
356 rArgs[0].Value >>= aNew;
357 aStr += aNew;
358 aStatement.aArgs[0].Value <<= aStr;
359 aElement <<= aStatement;
360 xReplace->replaceByIndex( nCount-1, aElement );
361 return;
362 }
363 }
364 }
365
366 css::util::URL aURL;
367 aURL.Complete = aCmd;
368 xTransform->parseStrict(aURL);
369
370 if (bDone)
371 xRecorder->recordDispatch(aURL,rArgs);
372 else
373 xRecorder->recordDispatchAsComment(aURL,rArgs);
374}
375
376
377void SfxRequest::Record_Impl
378(
379 SfxShell& rSh, // the <SfxShell>, which has executed the Request
380 const SfxSlot& rSlot, // the <SfxSlot>, which has executed the Request
381 const css::uno::Reference< css::frame::XDispatchRecorder >& xRecorder,
382 SfxViewFrame* pViewFrame
383)
384
385/* [Description]
386
387 This internal method marks the specified SfxMakro SfxRequest as recorded in
388 SfxMakro. Pointer to the parameters in Done() is used again, thus has to
389 still be alive.
390*/
391
392{
393 pImpl->pShell = &rSh;
394 pImpl->pSlot = &rSlot;
395 pImpl->xRecorder = xRecorder;
396 if (pImpl->xRecorder && !pImpl->xTransform)
397 pImpl->xTransform = util::URLTransformer::create(comphelper::getProcessComponentContext());
398 pImpl->aTarget = rSh.GetName();
399 pImpl->pViewFrame = pViewFrame;
400}
401
402
403void SfxRequest::SetArgs( const SfxAllItemSet& rArgs )
404{
405 pArgs.reset(new SfxAllItemSet(rArgs));
406 pImpl->SetPool( pArgs->GetPool() );
407}
408
409
410void SfxRequest::AppendItem(const SfxPoolItem &rItem)
411{
412 if(!pArgs)
413 pArgs.reset( new SfxAllItemSet(*pImpl->pPool) );
414 pArgs->Put(rItem, rItem.Which());
415}
416
417
418void SfxRequest::RemoveItem( sal_uInt16 nID )
419{
420 if (pArgs)
421 {
422 pArgs->ClearItem(nID);
423 if ( !pArgs->Count() )
424 pArgs.reset();
425 }
426}
427
428void SfxRequest::SetReturnValue(const SfxPoolItem &rItem)
429{
430 DBG_ASSERT(!pImpl->pRetVal, "Set Return value multiple times?")do { if (true && (!(!pImpl->pRetVal))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "430" ": "), "%s", "Set Return value multiple times?"); }
} while (false)
;
431 pImpl->pRetVal.reset(rItem.Clone());
432}
433
434
435const SfxPoolItem* SfxRequest::GetReturnValue() const
436{
437 return pImpl->pRetVal.get();
438}
439
440
441void SfxRequest::Done
442(
443 const SfxItemSet& rSet /* parameters passed on by the application,
444 that for example were asked for by the user
445 in a dialogue, 0 if no parameters have been
446 set */
447)
448
449/* [Description]
450
451 This method must be called in the <Execute-Method> of the <SfxSlot>s, which
452 has performed the SfxRequest when the execution actually took place. If
453 'Done()' is not called, then the SfxRequest is considered canceled.
454
455 Any return values are passed only when 'Done()' was called. Similar, when
456 recording a macro only true statements are generated if 'Done()' was
457 called; for SfxRequests that were not identified as such will instead
458 be commented out by inserting ('rem').
459
460 [Note]
461
462 'Done ()' is not called, for example when a dialog started by the function
463 was canceled by the user or if the execution could not be performed due to
464 a wrong context (without use of separate <SfxShell>s). 'Done ()' will be
465 launched, when executing the function led to a regular error
466 (for example, file could not be opened).
467*/
468
469{
470 Done_Impl( &rSet );
1
Calling 'SfxRequest::Done_Impl'
471
472 // Keep items if possible, so they can be queried by StarDraw.
473 if ( !pArgs )
474 {
475 pArgs.reset( new SfxAllItemSet( rSet ) );
476 pImpl->SetPool( pArgs->GetPool() );
477 }
478 else
479 {
480 SfxItemIter aIter(rSet);
481 for (const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem())
482 {
483 if(!IsInvalidItem(pItem))
484 pArgs->Put(*pItem,pItem->Which());
485 }
486 }
487}
488
489
490void SfxRequest::Done( bool bRelease )
491// [<SfxRequest::Done(SfxItemSet&)>]
492{
493 Done_Impl( pArgs.get() );
28
Calling 'SfxRequest::Done_Impl'
494 if( bRelease )
495 pArgs.reset();
496}
497
498
499void SfxRequest::ForgetAllArgs()
500{
501 pArgs.reset();
502 pImpl->pInternalArgs.reset();
503}
504
505
506bool SfxRequest::IsCancelled() const
507{
508 return pImpl->bCancelled;
509}
510
511
512void SfxRequest::Cancel()
513
514/* [Description]
515
516 Marks this request as no longer executable. For example, if called when
517 the target (more precisely, its pool) dies.
518*/
519
520{
521 pImpl->bCancelled = true;
522 pImpl->SetPool( nullptr );
523 pArgs.reset();
524}
525
526
527void SfxRequest::Ignore()
528
529/* [Description]
530
531 If this method is called instead of <SfxRequest::Done()>, then this
532 request is not recorded.
533
534 [Example]
535
536 The selecting of tools in StarDraw should not be recorded, but the same
537 slots are to be used from the generation of the tools to the generated
538 objects. Thus can NoRecords not be specified, i.e. should not be recorded.
539*/
540
541{
542 // Mark as actually executed
543 pImpl->bIgnored = true;
544}
545
546
547void SfxRequest::Done_Impl
548(
549 const SfxItemSet* pSet /* parameters passed on by the application,
550 that for example were asked for by the user
551 in a dialogue, 0 if no parameters have been
552 set */
553
554)
555
556/* [Description]
557
558 Internal method to mark SfxRequest with 'done' and to evaluate the
559 parameters in 'pSet' in case it is recorded.
560*/
561
562{
563 // Mark as actually executed
564 pImpl->bDone = true;
565
566 // not Recording
567 if ( !pImpl->xRecorder.is() )
2
Taking false branch
29
Calling 'BaseReference::is'
32
Returning from 'BaseReference::is'
33
Taking false branch
568 return;
569
570 // was running a different slot than requested (Delegation)
571 if ( nSlot != pImpl->pSlot->GetSlotId() )
3
Assuming the condition is false
4
Taking false branch
34
Called C++ object pointer is null
572 {
573 // Search Slot again
574 pImpl->pSlot = pImpl->pShell->GetInterface()->GetSlot(nSlot);
575 DBG_ASSERT( pImpl->pSlot, "delegated SlotId not found" )do { if (true && (!(pImpl->pSlot))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "575" ": "), "%s", "delegated SlotId not found"); } } while
(false)
;
576 if ( !pImpl->pSlot ) // playing it safe
577 return;
578 }
579
580 // recordable?
581 // new Recording uses UnoName!
582 SAL_WARN_IF( !pImpl->pSlot->pUnoName, "sfx", "Recording not exported slot: "do { if (true && (!pImpl->pSlot->pUnoName)) { switch
(sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "sfx")) {
case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording not exported slot: " << pImpl->
pSlot->GetSlotId()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "583" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording not exported slot: " <<
pImpl->pSlot->GetSlotId()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording not exported slot: "
<< pImpl->pSlot->GetSlotId(); ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "583" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording not exported slot: " << pImpl->
pSlot->GetSlotId()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "583" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording not exported slot: " <<
pImpl->pSlot->GetSlotId()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording not exported slot: "
<< pImpl->pSlot->GetSlotId(); ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "583" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
5
Assuming field 'pUnoName' is non-null
6
Taking false branch
7
Loop condition is false. Exiting loop
583 << pImpl->pSlot->GetSlotId() )do { if (true && (!pImpl->pSlot->pUnoName)) { switch
(sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "sfx")) {
case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording not exported slot: " << pImpl->
pSlot->GetSlotId()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "583" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording not exported slot: " <<
pImpl->pSlot->GetSlotId()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording not exported slot: "
<< pImpl->pSlot->GetSlotId(); ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "583" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording not exported slot: " << pImpl->
pSlot->GetSlotId()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "583" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording not exported slot: " <<
pImpl->pSlot->GetSlotId()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording not exported slot: "
<< pImpl->pSlot->GetSlotId(); ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "583" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
584
585 if ( !pImpl->pSlot->pUnoName
7.1
Field 'pUnoName' is non-null
7.1
Field 'pUnoName' is non-null
) // playing it safe
8
Taking false branch
586 return;
587
588 // often required values
589 SfxItemPool &rPool = pImpl->pShell->GetPool();
590
591 // Property-Slot?
592 if ( !pImpl->pSlot->IsMode(SfxSlotMode::METHOD) )
9
Taking false branch
593 {
594 // get the property as SfxPoolItem
595 const SfxPoolItem *pItem;
596 sal_uInt16 nWhich = rPool.GetWhich(pImpl->pSlot->GetSlotId());
597 SfxItemState eState = pSet ? pSet->GetItemState( nWhich, false, &pItem ) : SfxItemState::UNKNOWN;
598 SAL_WARN_IF( SfxItemState::SET != eState, "sfx", "Recording property not available: "do { if (true && (SfxItemState::SET != eState)) { switch
(sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "sfx")) {
case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording property not available: " << pImpl
->pSlot->GetSlotId()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "599" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording property not available: " <<
pImpl->pSlot->GetSlotId()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording property not available: "
<< pImpl->pSlot->GetSlotId(); ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "599" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording property not available: " << pImpl
->pSlot->GetSlotId()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "599" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording property not available: " <<
pImpl->pSlot->GetSlotId()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording property not available: "
<< pImpl->pSlot->GetSlotId(); ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "599" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
599 << pImpl->pSlot->GetSlotId() )do { if (true && (SfxItemState::SET != eState)) { switch
(sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "sfx")) {
case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording property not available: " << pImpl
->pSlot->GetSlotId()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "599" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording property not available: " <<
pImpl->pSlot->GetSlotId()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording property not available: "
<< pImpl->pSlot->GetSlotId(); ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "599" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Recording property not available: " << pImpl
->pSlot->GetSlotId()) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "599" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Recording property not available: " <<
pImpl->pSlot->GetSlotId()), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Recording property not available: "
<< pImpl->pSlot->GetSlotId(); ::sal::detail::log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("sfx"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "599" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
600 uno::Sequence < beans::PropertyValue > aSeq;
601 if ( eState == SfxItemState::SET )
602 TransformItems( pImpl->pSlot->GetSlotId(), *pSet, aSeq, pImpl->pSlot );
603 pImpl->Record( aSeq );
604 }
605
606 // record everything in a single statement?
607 else if ( pImpl->pSlot->IsMode(SfxSlotMode::RECORDPERSET) )
10
Taking false branch
608 {
609 uno::Sequence < beans::PropertyValue > aSeq;
610 if ( pSet )
611 TransformItems( pImpl->pSlot->GetSlotId(), *pSet, aSeq, pImpl->pSlot );
612 pImpl->Record( aSeq );
613 }
614
615 // record each item as a single statement
616 else if ( pImpl->pSlot->IsMode(SfxSlotMode::RECORDPERITEM) )
11
Taking true branch
617 {
618 if ( pSet
11.1
'pSet' is non-null
11.1
'pSet' is non-null
)
12
Taking true branch
619 {
620 // iterate over Items
621 SfxItemIter aIter(*pSet);
622 for ( const SfxPoolItem* pItem = aIter.GetCurItem(); pItem; pItem = aIter.NextItem() )
13
Loop condition is true. Entering loop body
623 {
624 // to determine the slot ID for the individual item
625 sal_uInt16 nSlotId = rPool.GetSlotId( pItem->Which() );
626 if ( nSlotId == nSlot )
14
Assuming 'nSlotId' is not equal to field 'nSlot'
15
Taking false branch
627 {
628 // play it safe; repair the wrong flags
629 OSL_FAIL( "recursion RecordPerItem - use RecordPerSet!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sfx2/source/control/request.cxx"
":" "629" ": "), "%s", "recursion RecordPerItem - use RecordPerSet!"
); } } while (false)
;
630 SfxSlot *pSlot = const_cast<SfxSlot*>(pImpl->pSlot);
631 pSlot->nFlags &= ~SfxSlotMode::RECORDPERITEM;
632 pSlot->nFlags &= SfxSlotMode::RECORDPERSET;
633 }
634
635 // Record a Sub-Request
636 SfxRequest aReq( pImpl->pViewFrame, nSlotId );
16
Calling constructor for 'SfxRequest'
23
Returning from constructor for 'SfxRequest'
637 if ( aReq.pImpl->pSlot )
24
Assuming field 'pSlot' is null
25
Assuming pointer value is null
26
Taking false branch
638 aReq.AppendItem( *pItem );
639 aReq.Done();
27
Calling 'SfxRequest::Done'
640 }
641 }
642 else
643 {
644 //HACK(think about this again)
645 pImpl->Record( uno::Sequence < beans::PropertyValue >() );
646 }
647 }
648}
649
650
651bool SfxRequest::IsDone() const
652
653/* [Description]
654
655 With this method it can be queried whether the SfxRequest was actually
656 executed or not. If a SfxRequest was not executed, then this is for example
657 because it was canceled by the user or the context for this request was
658 wrong, this was not implemented on a separate <SfxShell>.
659
660 SfxRequest instances that return false will not be recorded.
661
662 [Cross-reference]
663
664 <SfxRequest::Done(const SfxItemSet&)>
665 <SfxRequest::Done()>
666*/
667
668{
669 return pImpl->bDone;
670}
671
672
673css::uno::Reference< css::frame::XDispatchRecorder > SfxRequest::GetMacroRecorder( SfxViewFrame const * pView )
674
675/* [Description]
676
677 This recorder is an attempt for dispatch () to get calls from the Frame.
678 This is then available through a property by a supplier but only when
679 recording was turned on.
680
681 (See also SfxViewFrame::MiscExec_Impl() and SID_RECORDING)
682*/
683
684{
685 css::uno::Reference< css::frame::XDispatchRecorder > xRecorder;
686
687 css::uno::Reference< css::beans::XPropertySet > xSet(
688 (pView ? pView : SfxViewFrame::Current())->GetFrame().GetFrameInterface(),
689 css::uno::UNO_QUERY);
690
691 if(xSet.is())
692 {
693 css::uno::Any aProp = xSet->getPropertyValue("DispatchRecorderSupplier");
694 css::uno::Reference< css::frame::XDispatchRecorderSupplier > xSupplier;
695 aProp >>= xSupplier;
696 if(xSupplier.is())
697 xRecorder = xSupplier->getDispatchRecorder();
698 }
699
700 return xRecorder;
701}
702
703bool SfxRequest::HasMacroRecorder( SfxViewFrame const * pView )
704{
705 return GetMacroRecorder( pView ).is();
706}
707
708
709bool SfxRequest::IsAPI() const
710
711/* [Description]
712
713 Returns true if this SfxRequest was generated by an API (for example BASIC),
714 otherwise false.
715*/
716
717{
718 return SfxCallMode::API == ( SfxCallMode::API & pImpl->nCallMode );
719}
720
721
722void SfxRequest::SetModifier( sal_uInt16 nModi )
723{
724 pImpl->nModifier = nModi;
725}
726
727
728sal_uInt16 SfxRequest::GetModifier() const
729{
730 return pImpl->nModifier;
731}
732
733
734void SfxRequest::AllowRecording( bool bSet )
735{
736 pImpl->bAllowRecording = bSet;
737}
738
739bool SfxRequest::AllowsRecording() const
740{
741 bool bAllow = pImpl->bAllowRecording;
742 if( !bAllow )
743 bAllow = ( SfxCallMode::API != ( SfxCallMode::API & pImpl->nCallMode ) ) &&
744 ( SfxCallMode::RECORD == ( SfxCallMode::RECORD & pImpl->nCallMode ) );
745 return bAllow;
746}
747
748void SfxRequest::ReleaseArgs()
749{
750 pArgs.reset();
751 pImpl->pInternalArgs.reset();
752}
753
754/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h

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
33namespace com
34{
35namespace sun
36{
37namespace star
38{
39namespace uno
40{
41
42class RuntimeException;
43class XInterface;
44class Type;
45class 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*/
51enum 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*/
62class BaseReference
63{
64protected:
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
85public:
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); }
30
Assuming NULL is not equal to field '_pInterface'
31
Returning the value 1, which participates in a condition later
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*/
149enum 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*/
158enum 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*/
169enum 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*/
178template< class interface_type >
179class 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
231public:
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: */