Bug Summary

File:home/maarten/src/libreoffice/core/sw/source/filter/xml/xmltexte.cxx
Warning:line 196, column 22
The right operand of '!=' is a garbage value

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 xmltexte.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 SW_DLLIMPLEMENTATION -D SWUI_DLL_NAME="libswuilo.so" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sw/source/core/inc -I /home/maarten/src/libreoffice/core/sw/source/filter/inc -I /home/maarten/src/libreoffice/core/sw/source/uibase/inc -I /home/maarten/src/libreoffice/core/sw/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sw/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/CustomTarget/sw/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/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/sw/source/filter/xml/xmltexte.cxx

/home/maarten/src/libreoffice/core/sw/source/filter/xml/xmltexte.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 <sal/config.h>
21
22#include <string_view>
23
24#include <comphelper/classids.hxx>
25#include <com/sun/star/embed/XEmbeddedObject.hpp>
26#include <com/sun/star/embed/XLinkageSupport.hpp>
27#include <com/sun/star/document/XEmbeddedObjectSupplier.hpp>
28#include <xmloff/families.hxx>
29#include <xmloff/xmlnamespace.hxx>
30#include <xmloff/xmltoken.hxx>
31#include <xmloff/txtprmap.hxx>
32#include <xmloff/maptype.hxx>
33#include <xmloff/xmlexppr.hxx>
34
35#include <ndole.hxx>
36#include <fmtcntnt.hxx>
37#include <unoframe.hxx>
38#include "xmlexp.hxx"
39#include "xmltexte.hxx"
40#include <SwAppletImpl.hxx>
41#include <ndindex.hxx>
42
43#include <sot/exchange.hxx>
44#include <svl/urihelper.hxx>
45#include <sfx2/frmdescr.hxx>
46
47using namespace ::com::sun::star;
48using namespace ::com::sun::star::uno;
49using namespace ::com::sun::star::style;
50using namespace ::com::sun::star::beans;
51using namespace ::com::sun::star::lang;
52using namespace ::com::sun::star::document;
53using namespace ::com::sun::star::io;
54using namespace ::xmloff::token;
55
56namespace {
57
58enum SvEmbeddedObjectTypes
59{
60 SV_EMBEDDED_OWN,
61 SV_EMBEDDED_OUTPLACE,
62 SV_EMBEDDED_APPLET,
63 SV_EMBEDDED_PLUGIN,
64 SV_EMBEDDED_FRAME
65};
66
67}
68
69SwNoTextNode *SwXMLTextParagraphExport::GetNoTextNode(
70 const Reference < XPropertySet >& rPropSet )
71{
72 Reference<XUnoTunnel> xCursorTunnel( rPropSet, UNO_QUERY );
73 assert(xCursorTunnel.is() && "missing XUnoTunnel for embedded")(static_cast <bool> (xCursorTunnel.is() && "missing XUnoTunnel for embedded"
) ? void (0) : __assert_fail ("xCursorTunnel.is() && \"missing XUnoTunnel for embedded\""
, "/home/maarten/src/libreoffice/core/sw/source/filter/xml/xmltexte.cxx"
, 73, __extension__ __PRETTY_FUNCTION__))
;
74 SwXFrame *pFrame = reinterpret_cast< SwXFrame * >(
75 sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( SwXFrame::getUnoTunnelId() )));
76 assert(pFrame && "SwXFrame missing")(static_cast <bool> (pFrame && "SwXFrame missing"
) ? void (0) : __assert_fail ("pFrame && \"SwXFrame missing\""
, "/home/maarten/src/libreoffice/core/sw/source/filter/xml/xmltexte.cxx"
, 76, __extension__ __PRETTY_FUNCTION__))
;
77 SwFrameFormat *pFrameFormat = pFrame->GetFrameFormat();
78 const SwFormatContent& rContent = pFrameFormat->GetContent();
79 const SwNodeIndex *pNdIdx = rContent.GetContentIdx();
80 return pNdIdx->GetNodes()[pNdIdx->GetIndex() + 1]->GetNoTextNode();
81}
82
83constexpr OUStringLiteral gsEmbeddedObjectProtocol( u"vnd.sun.star.EmbeddedObject:" );
84
85SwXMLTextParagraphExport::SwXMLTextParagraphExport(
86 SwXMLExport& rExp,
87 SvXMLAutoStylePoolP& _rAutoStylePool ) :
88 XMLTextParagraphExport( rExp, _rAutoStylePool ),
89 aAppletClassId( SO3_APPLET_CLASSID0x970b1e81, 0xcf2d, 0x11cf, 0x89,0xca,0x00,0x80,0x29,0xe4,0xb0
,0xb1
),
90 aPluginClassId( SO3_PLUGIN_CLASSID0x4caa7761, 0x6b8b, 0x11cf, 0x89,0xca,0x0,0x80,0x29,0xe4,0xb0
,0xb1
),
91 aIFrameClassId( SO3_IFRAME_CLASSID0x1a8a6701, 0xde58, 0x11cf, 0x89, 0xca, 0x0, 0x80, 0x29, 0xe4
, 0xb0, 0xb1
)
92{
93}
94
95SwXMLTextParagraphExport::~SwXMLTextParagraphExport()
96{
97}
98
99static void lcl_addURL ( SvXMLExport &rExport, const OUString &rURL,
100 bool bToRel = true )
101{
102 const OUString sRelURL = ( bToRel && !rURL.isEmpty() )
103 ? URIHelper::simpleNormalizedMakeRelative(rExport.GetOrigFileName(), rURL)
104 : rURL;
105
106 if (!sRelURL.isEmpty())
107 {
108 rExport.AddAttribute ( XML_NAMESPACE_XLINK, XML_HREF, sRelURL );
109 rExport.AddAttribute ( XML_NAMESPACE_XLINK, XML_TYPE, XML_SIMPLE );
110 rExport.AddAttribute ( XML_NAMESPACE_XLINK, XML_SHOW, XML_EMBED );
111 rExport.AddAttribute ( XML_NAMESPACE_XLINK, XML_ACTUATE, XML_ONLOAD );
112 }
113}
114
115static void lcl_addAspect(
116 const svt::EmbeddedObjectRef& rObj,
117 const XMLPropertyState **pStates,
118 const rtl::Reference < XMLPropertySetMapper >& rMapper )
119{
120 sal_Int64 nAspect = rObj.GetViewAspect();
121 if ( nAspect )
122 {
123 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_OLE_DRAW_ASPECT(0x00003000 + 116) ), uno::makeAny( nAspect ) );
124 }
125}
126
127static void lcl_addOutplaceProperties(
128 const svt::EmbeddedObjectRef& rObj,
129 const XMLPropertyState **pStates,
130 const rtl::Reference < XMLPropertySetMapper >& rMapper )
131{
132 MapMode aMode( MapUnit::Map100thMM ); // the API expects this map mode for the embedded objects
133 Size aSize = rObj.GetSize( &aMode ); // get the size in the requested map mode
134
135 if( !(aSize.Width() && aSize.Height()) )
136 return;
137
138 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_OLE_VIS_AREA_LEFT(0x00003000 + 113) ), Any(sal_Int32(0)) );
139 pStates++;
140
141 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_OLE_VIS_AREA_TOP(0x00003000 + 112) ), Any(sal_Int32(0)) );
142 pStates++;
143
144 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_OLE_VIS_AREA_WIDTH(0x00003000 + 114) ), Any(static_cast<sal_Int32>(aSize.Width())) );
145 pStates++;
146
147 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_OLE_VIS_AREA_HEIGHT(0x00003000 + 115) ), Any(static_cast<sal_Int32>(aSize.Height())) );
148}
149
150static void lcl_addFrameProperties(
151 const uno::Reference < embed::XEmbeddedObject >& xObj,
152 const XMLPropertyState **pStates,
153 const rtl::Reference < XMLPropertySetMapper >& rMapper )
154{
155 if ( !::svt::EmbeddedObjectRef::TryRunningState( xObj ) )
6
Assuming the condition is false
7
Taking false branch
156 return;
157
158 uno::Reference < beans::XPropertySet > xSet( xObj->getComponent(), uno::UNO_QUERY );
159 if ( !xSet.is() )
8
Calling 'BaseReference::is'
11
Returning from 'BaseReference::is'
12
Taking false branch
160 return;
161
162 bool bIsAutoScroll = false, bIsScrollingMode = false;
163 Any aAny = xSet->getPropertyValue("FrameIsAutoScroll");
164 aAny >>= bIsAutoScroll;
165 if ( !bIsAutoScroll )
13
Assuming 'bIsAutoScroll' is true
14
Taking false branch
166 {
167 aAny = xSet->getPropertyValue("FrameIsScrollingMode");
168 aAny >>= bIsScrollingMode;
169 }
170
171 bool bIsBorderSet = false, bIsAutoBorder = false;
172 aAny = xSet->getPropertyValue("FrameIsAutoBorder");
173 aAny >>= bIsAutoBorder;
174 if ( !bIsAutoBorder )
15
Assuming 'bIsAutoBorder' is true
16
Taking false branch
175 {
176 aAny = xSet->getPropertyValue("FrameIsBorder");
177 aAny >>= bIsBorderSet;
178 }
179
180 sal_Int32 nWidth, nHeight;
17
'nWidth' declared without an initial value
181 aAny = xSet->getPropertyValue("FrameMarginWidth");
182 aAny >>= nWidth;
18
Calling 'operator>>=<int>'
21
Returning from 'operator>>=<int>'
183 aAny = xSet->getPropertyValue("FrameMarginHeight");
184 aAny >>= nHeight;
185
186 if( !bIsAutoScroll
21.1
'bIsAutoScroll' is true
21.1
'bIsAutoScroll' is true
21.1
'bIsAutoScroll' is true
)
22
Taking false branch
187 {
188 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_FRAME_DISPLAY_SCROLLBAR(0x00003000 + 107) ), makeAny(bIsScrollingMode) );
189 pStates++;
190 }
191 if( !bIsAutoBorder
22.1
'bIsAutoBorder' is true
22.1
'bIsAutoBorder' is true
22.1
'bIsAutoBorder' is true
)
23
Taking false branch
192 {
193 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_FRAME_DISPLAY_BORDER(0x00003000 + 108) ), makeAny(bIsBorderSet) );
194 pStates++;
195 }
196 if( SIZE_NOT_SET-1L != nWidth )
24
The right operand of '!=' is a garbage value
197 {
198 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_FRAME_MARGIN_HORI(0x00003000 + 109) ), Any(nWidth) );
199 pStates++;
200 }
201 if( SIZE_NOT_SET-1L != nHeight )
202 {
203 *pStates = new XMLPropertyState( rMapper->FindEntryIndex( CTF_FRAME_MARGIN_VERT(0x00003000 + 110) ), Any(nHeight) );
204 }
205}
206
207void SwXMLTextParagraphExport::_collectTextEmbeddedAutoStyles(
208 const Reference < XPropertySet > & rPropSet )
209{
210 SwOLENode *pOLENd = GetNoTextNode( rPropSet )->GetOLENode();
211 svt::EmbeddedObjectRef& rObjRef = pOLENd->GetOLEObj().GetObject();
212 if( !rObjRef.is() )
1
Assuming the condition is false
2
Taking false branch
213 return;
214
215 const XMLPropertyState *aStates[8] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
216 SvGlobalName aClassId( rObjRef->getClassID() );
217
218 if( aIFrameClassId == aClassId )
3
Assuming the condition is true
4
Taking true branch
219 {
220 lcl_addFrameProperties( rObjRef.GetObject(), aStates,
5
Calling 'lcl_addFrameProperties'
221 GetAutoFramePropMapper()->getPropertySetMapper() );
222 }
223 else if ( !SotExchange::IsInternal( aClassId ) )
224 {
225 lcl_addOutplaceProperties( rObjRef, aStates,
226 GetAutoFramePropMapper()->getPropertySetMapper() );
227 }
228
229 lcl_addAspect( rObjRef, aStates,
230 GetAutoFramePropMapper()->getPropertySetMapper() );
231
232 Add( XmlStyleFamily::TEXT_FRAME, rPropSet, aStates );
233
234 const XMLPropertyState **pStates = aStates;
235 while( *pStates )
236 {
237 delete *pStates;
238 pStates++;
239 }
240}
241
242void SwXMLTextParagraphExport::_exportTextEmbedded(
243 const Reference < XPropertySet > & rPropSet,
244 const Reference < XPropertySetInfo > & rPropSetInfo )
245{
246 SwOLENode *pOLENd = GetNoTextNode( rPropSet )->GetOLENode();
247 SwOLEObj& rOLEObj = pOLENd->GetOLEObj();
248 svt::EmbeddedObjectRef& rObjRef = rOLEObj.GetObject();
249 if( !rObjRef.is() )
250 return;
251
252 SvGlobalName aClassId( rObjRef->getClassID() );
253
254 SvEmbeddedObjectTypes nType = SV_EMBEDDED_OWN;
255 if( aPluginClassId == aClassId )
256 {
257 nType = SV_EMBEDDED_PLUGIN;
258 }
259 else if( aAppletClassId == aClassId )
260 {
261 nType = SV_EMBEDDED_APPLET;
262 }
263 else if( aIFrameClassId == aClassId )
264 {
265 nType = SV_EMBEDDED_FRAME;
266 }
267 else if ( !SotExchange::IsInternal( aClassId ) )
268 {
269 nType = SV_EMBEDDED_OUTPLACE;
270 }
271
272 enum XMLTokenEnum eElementName = XML__UNKNOWN_;
273 SvXMLExport &rXMLExport = GetExport();
274
275 // First the stuff common to each of Applet/Plugin/Floating Frame
276 OUString sStyle;
277 Any aAny;
278 if( rPropSetInfo->hasPropertyByName( gsFrameStyleName ) )
279 {
280 aAny = rPropSet->getPropertyValue( gsFrameStyleName );
281 aAny >>= sStyle;
282 }
283
284 const XMLPropertyState *aStates[8] = { nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr };
285 switch( nType )
286 {
287 case SV_EMBEDDED_FRAME:
288 lcl_addFrameProperties( rObjRef.GetObject(), aStates,
289 GetAutoFramePropMapper()->getPropertySetMapper() );
290 break;
291 case SV_EMBEDDED_OUTPLACE:
292 lcl_addOutplaceProperties( rObjRef, aStates,
293 GetAutoFramePropMapper()->getPropertySetMapper() );
294 break;
295 default:
296 ;
297 }
298
299 lcl_addAspect( rObjRef, aStates,
300 GetAutoFramePropMapper()->getPropertySetMapper() );
301
302 const OUString sAutoStyle = Find( XmlStyleFamily::TEXT_FRAME,
303 rPropSet, sStyle, aStates );
304 const XMLPropertyState **pStates = aStates;
305 while( *pStates )
306 {
307 delete *pStates;
308 pStates++;
309 }
310
311 if( !sAutoStyle.isEmpty() )
312 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE_NAME, sAutoStyle );
313 addTextFrameAttributes( rPropSet, false );
314
315 SvXMLElementExport aElem( GetExport(), XML_NAMESPACE_DRAW,
316 XML_FRAME, false, true );
317
318 switch (nType)
319 {
320 case SV_EMBEDDED_OUTPLACE:
321 case SV_EMBEDDED_OWN:
322 if( !(rXMLExport.getExportFlags() & SvXMLExportFlags::EMBEDDED) )
323 {
324 OUString sURL;
325
326 bool bIsOwnLink = false;
327 if( SV_EMBEDDED_OWN == nType )
328 {
329 try
330 {
331 uno::Reference< embed::XLinkageSupport > xLinkage( rObjRef.GetObject(), uno::UNO_QUERY );
332 bIsOwnLink = xLinkage.is() && xLinkage->isLink();
333 if ( bIsOwnLink )
334 sURL = xLinkage->getLinkURL();
335 }
336 catch(const uno::Exception&)
337 {
338 // TODO/LATER: error handling
339 OSL_FAIL( "Link detection or retrieving of the URL of OOo link is failed!" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/xml/xmltexte.cxx"
":" "339" ": "), "%s", "Link detection or retrieving of the URL of OOo link is failed!"
); } } while (false)
;
340 }
341 }
342
343 if ( !bIsOwnLink )
344 {
345 sURL = gsEmbeddedObjectProtocol + rOLEObj.GetCurrentPersistName();
346 }
347
348 sURL = GetExport().AddEmbeddedObject( sURL );
349 lcl_addURL( rXMLExport, sURL, false );
350 }
351 if( SV_EMBEDDED_OWN == nType && !pOLENd->GetChartTableName().isEmpty() )
352 {
353 OUString sRange( pOLENd->GetChartTableName() );
354 OUStringBuffer aBuffer( sRange.getLength() + 2 );
355 for( sal_Int32 i=0; i < sRange.getLength(); i++ )
356 {
357 sal_Unicode c = sRange[i];
358 switch( c )
359 {
360 case ' ':
361 case '.':
362 case '\'':
363 case '\\':
364 if( aBuffer.isEmpty() )
365 {
366 aBuffer.append( '\'' );
367 aBuffer.append( std::u16string_view(sRange).substr(0, i) );
368 }
369 if( '\'' == c || '\\' == c )
370 aBuffer.append( '\\' );
371 [[fallthrough]];
372 default:
373 if( !aBuffer.isEmpty() )
374 aBuffer.append( c );
375 }
376 }
377 if( !aBuffer.isEmpty() )
378 {
379 aBuffer.append( '\'' );
380 sRange = aBuffer.makeStringAndClear();
381 }
382
383 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NOTIFY_ON_UPDATE_OF_RANGES,
384 sRange );
385 }
386 eElementName = SV_EMBEDDED_OUTPLACE==nType ? XML_OBJECT_OLE
387 : XML_OBJECT;
388 break;
389 case SV_EMBEDDED_APPLET:
390 {
391 // It's an applet!
392 if( svt::EmbeddedObjectRef::TryRunningState( rObjRef.GetObject() ) )
393 {
394 uno::Reference < beans::XPropertySet > xSet( rObjRef->getComponent(), uno::UNO_QUERY );
395 OUString aStr;
396 Any aAny2 = xSet->getPropertyValue("AppletCodeBase");
397 aAny2 >>= aStr;
398 if (!aStr.isEmpty() )
399 lcl_addURL(rXMLExport, aStr);
400
401 aAny2 = xSet->getPropertyValue("AppletName");
402 aAny2 >>= aStr;
403 if (!aStr.isEmpty())
404 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_APPLET_NAME, aStr );
405
406 aAny2 = xSet->getPropertyValue("AppletCode");
407 aAny2 >>= aStr;
408 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_CODE, aStr );
409
410 bool bScript = false;
411 aAny2 = xSet->getPropertyValue("AppletIsScript");
412 aAny2 >>= bScript;
413 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_MAY_SCRIPT, bScript ? XML_TRUE : XML_FALSE );
414
415 uno::Sequence < beans::PropertyValue > aProps;
416 aAny2 = xSet->getPropertyValue("AppletCommands");
417 aAny2 >>= aProps;
418
419 sal_Int32 i = aProps.getLength();
420 while ( i > 0 )
421 {
422 beans::PropertyValue& aProp = aProps[--i];
423 const SwHtmlOptType nType2 = SwApplet_Impl::GetOptionType( aProp.Name, true );
424 if ( nType2 == SwHtmlOptType::TAG)
425 {
426 OUString aStr2;
427 aProp.Value >>= aStr2;
428 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, aProp.Name, aStr2);
429 }
430 }
431
432 eElementName = XML_APPLET;
433 }
434 }
435 break;
436 case SV_EMBEDDED_PLUGIN:
437 {
438 // It's a plugin!
439 if ( svt::EmbeddedObjectRef::TryRunningState( rObjRef.GetObject() ) )
440 {
441 uno::Reference < beans::XPropertySet > xSet( rObjRef->getComponent(), uno::UNO_QUERY );
442 OUString aStr;
443 Any aAny2 = xSet->getPropertyValue("PluginURL");
444 aAny2 >>= aStr;
445 lcl_addURL( rXMLExport, aStr );
446
447 aAny2 = xSet->getPropertyValue("PluginMimeType");
448 aAny2 >>= aStr;
449 if (!aStr.isEmpty())
450 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_MIME_TYPE, aStr );
451 eElementName = XML_PLUGIN;
452 }
453 }
454 break;
455 case SV_EMBEDDED_FRAME:
456 {
457 // It's a floating frame!
458 if ( svt::EmbeddedObjectRef::TryRunningState( rObjRef.GetObject() ) )
459 {
460 uno::Reference < beans::XPropertySet > xSet( rObjRef->getComponent(), uno::UNO_QUERY );
461 OUString aStr;
462 Any aAny2 = xSet->getPropertyValue("FrameURL");
463 aAny2 >>= aStr;
464
465 lcl_addURL( rXMLExport, aStr );
466
467 aAny2 = xSet->getPropertyValue("FrameName");
468 aAny2 >>= aStr;
469
470 if (!aStr.isEmpty())
471 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_FRAME_NAME, aStr );
472 eElementName = XML_FLOATING_FRAME;
473 }
474 }
475 break;
476 default:
477 OSL_ENSURE( false, "unknown object type! Base class should have been called!" )do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/xml/xmltexte.cxx"
":" "477" ": "), "%s", "unknown object type! Base class should have been called!"
); } } while (false)
;
478 }
479
480 {
481 SvXMLElementExport aElementExport( rXMLExport, XML_NAMESPACE_DRAW, eElementName,
482 false, true );
483 switch( nType )
484 {
485 case SV_EMBEDDED_OWN:
486 if( rXMLExport.getExportFlags() & SvXMLExportFlags::EMBEDDED )
487 {
488 Reference < XEmbeddedObjectSupplier > xEOS( rPropSet, UNO_QUERY );
489 OSL_ENSURE( xEOS.is(), "no embedded object supplier for own object" )do { if (true && (!(xEOS.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/filter/xml/xmltexte.cxx"
":" "489" ": "), "%s", "no embedded object supplier for own object"
); } } while (false)
;
490 Reference < XComponent > xComp = xEOS->getEmbeddedObject();
491 rXMLExport.ExportEmbeddedOwnObject( xComp );
492 }
493 break;
494 case SV_EMBEDDED_OUTPLACE:
495 if( rXMLExport.getExportFlags() & SvXMLExportFlags::EMBEDDED )
496 {
497 OUString sURL( gsEmbeddedObjectProtocol + rOLEObj.GetCurrentPersistName() );
498
499 if ( !( rXMLExport.getExportFlags() & SvXMLExportFlags::OASIS ) )
500 sURL += "?oasis=false";
501
502 rXMLExport.AddEmbeddedObjectAsBase64( sURL );
503 }
504 break;
505 case SV_EMBEDDED_APPLET:
506 {
507 if ( svt::EmbeddedObjectRef::TryRunningState( rObjRef.GetObject() ) )
508 {
509 uno::Reference < beans::XPropertySet > xSet( rObjRef->getComponent(), uno::UNO_QUERY );
510 uno::Sequence < beans::PropertyValue > aProps;
511 aAny = xSet->getPropertyValue("AppletCommands");
512 aAny >>= aProps;
513
514 sal_Int32 i = aProps.getLength();
515 while ( i > 0 )
516 {
517 beans::PropertyValue& aProp = aProps[--i];
518 const SwHtmlOptType nType2 = SwApplet_Impl::GetOptionType( aProp.Name, true );
519 if (SwHtmlOptType::PARAM == nType2 || SwHtmlOptType::SIZE == nType2 )
520 {
521 OUString aStr;
522 aProp.Value >>= aStr;
523 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, aProp.Name );
524 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_VALUE, aStr );
525 SvXMLElementExport aElementExport2( rXMLExport, XML_NAMESPACE_DRAW, XML_PARAM, false, true );
526 }
527 }
528 }
529 }
530 break;
531 case SV_EMBEDDED_PLUGIN:
532 {
533 if ( svt::EmbeddedObjectRef::TryRunningState( rObjRef.GetObject() ) )
534 {
535 uno::Reference < beans::XPropertySet > xSet( rObjRef->getComponent(), uno::UNO_QUERY );
536 uno::Sequence < beans::PropertyValue > aProps;
537 aAny = xSet->getPropertyValue("PluginCommands");
538 aAny >>= aProps;
539
540 sal_Int32 i = aProps.getLength();
541 while ( i > 0 )
542 {
543 beans::PropertyValue& aProp = aProps[--i];
544 const SwHtmlOptType nType2 = SwApplet_Impl::GetOptionType( aProp.Name, false );
545 if ( nType2 == SwHtmlOptType::TAG)
546 {
547 OUString aStr;
548 aProp.Value >>= aStr;
549 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_NAME, aProp.Name );
550 rXMLExport.AddAttribute( XML_NAMESPACE_DRAW, XML_VALUE, aStr );
551 SvXMLElementExport aElementExport2( rXMLExport, XML_NAMESPACE_DRAW, XML_PARAM, false, true );
552 }
553 }
554 }
555 }
556 break;
557 default:
558 break;
559 }
560 }
561 if( SV_EMBEDDED_OUTPLACE==nType || SV_EMBEDDED_OWN==nType )
562 {
563 OUString sURL = XML_EMBEDDEDOBJECTGRAPHIC_URL_BASE"vnd.sun.star.GraphicObject:" + rOLEObj.GetCurrentPersistName();
564 if( !(rXMLExport.getExportFlags() & SvXMLExportFlags::EMBEDDED) )
565 {
566 sURL = GetExport().AddEmbeddedObject( sURL );
567 lcl_addURL( rXMLExport, sURL, false );
568 }
569
570 SvXMLElementExport aElementExport( GetExport(), XML_NAMESPACE_DRAW,
571 XML_IMAGE, false, true );
572
573 if( rXMLExport.getExportFlags() & SvXMLExportFlags::EMBEDDED )
574 GetExport().AddEmbeddedObjectAsBase64( sURL );
575 }
576
577 // Lastly the stuff common to each of Applet/Plugin/Floating Frame
578 exportEvents( rPropSet );
579 exportTitleAndDescription( rPropSet, rPropSetInfo ); // #i73249#
580 exportContour( rPropSet, rPropSetInfo );
581}
582
583/* 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); }
9
Assuming NULL is not equal to field '_pInterface'
10
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: */

/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Any.hxx

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_ANY_HXX
20#define INCLUDED_COM_SUN_STAR_UNO_ANY_HXX
21
22#include "sal/config.h"
23
24#include <algorithm>
25#include <cassert>
26#include <cstddef>
27#include <iomanip>
28#include <ostream>
29#include <utility>
30
31#include "com/sun/star/uno/Any.h"
32#include "uno/data.h"
33#include "uno/sequence2.h"
34#include "com/sun/star/uno/Type.hxx"
35#include "com/sun/star/uno/Reference.h"
36#include "com/sun/star/uno/genfunc.hxx"
37#include "com/sun/star/uno/RuntimeException.hpp"
38#include "cppu/cppudllapi.h"
39#include "cppu/unotype.hxx"
40
41extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) rtl_uString * SAL_CALL cppu_Any_extraction_failure_msg(
42 uno_Any const * pAny, typelib_TypeDescriptionReference * pType )
43 SAL_THROW_EXTERN_C()throw ();
44
45namespace com
46{
47namespace sun
48{
49namespace star
50{
51namespace uno
52{
53
54
55inline Any::Any()
56{
57 ::uno_any_construct( this, NULL__null, NULL__null, cpp_acquire );
58}
59
60
61template <typename T>
62inline Any::Any( T const & value )
63{
64 ::uno_type_any_construct(
65 this, const_cast<T *>(&value),
66 ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(),
67 cpp_acquire );
68}
69
70inline Any::Any( bool value )
71{
72 sal_Bool b = value;
73 ::uno_type_any_construct(
74 this, &b, cppu::UnoType<bool>::get().getTypeLibType(),
75 cpp_acquire );
76}
77
78#if defined LIBO_INTERNAL_ONLY1
79template<typename T1, typename T2>
80Any::Any(rtl::OUStringConcat<T1, T2> && value):
81 Any(rtl::OUString(std::move(value)))
82{}
83#endif
84
85inline Any::Any( const Any & rAny )
86{
87 ::uno_type_any_construct( this, rAny.pData, rAny.pType, cpp_acquire );
88}
89
90inline Any::Any( const void * pData_, const Type & rType )
91{
92 ::uno_type_any_construct(
93 this, const_cast< void * >( pData_ ), rType.getTypeLibType(),
94 cpp_acquire );
95}
96
97inline Any::Any( const void * pData_, typelib_TypeDescription * pTypeDescr )
98{
99 ::uno_any_construct(
100 this, const_cast< void * >( pData_ ), pTypeDescr, cpp_acquire );
101}
102
103inline Any::Any( const void * pData_, typelib_TypeDescriptionReference * pType_ )
104{
105 ::uno_type_any_construct(
106 this, const_cast< void * >( pData_ ), pType_, cpp_acquire );
107}
108
109inline Any::~Any()
110{
111 ::uno_any_destruct(
112 this, cpp_release );
113}
114
115inline Any & Any::operator = ( const Any & rAny )
116{
117 if (this != &rAny)
118 {
119 ::uno_type_any_assign(
120 this, rAny.pData, rAny.pType,
121 cpp_acquire, cpp_release );
122 }
123 return *this;
124}
125
126#if defined LIBO_INTERNAL_ONLY1
127
128namespace detail {
129
130inline void moveAnyInternals(Any & from, Any & to) noexcept {
131 uno_any_construct(&to, nullptr, nullptr, &cpp_acquire);
132 std::swap(from.pType, to.pType);
133 std::swap(from.pData, to.pData);
134 std::swap(from.pReserved, to.pReserved);
135 if (to.pData == &from.pReserved) {
136 to.pData = &to.pReserved;
137 }
138 // This leaves from.pData (where "from" is now VOID) dangling to somewhere (cf.
139 // CONSTRUCT_EMPTY_ANY, cppu/source/uno/prim.hxx), but what's relevant is
140 // only that it isn't a nullptr (as e.g. >>= -> uno_type_assignData ->
141 // _assignData takes a null pSource to mean "construct a default value").
142}
143
144}
145
146Any::Any(Any && other) noexcept {
147 detail::moveAnyInternals(other, *this);
148}
149
150Any & Any::operator =(Any && other) noexcept {
151 uno_any_destruct(this, &cpp_release);
152 detail::moveAnyInternals(other, *this);
153 return *this;
154}
155
156#endif
157
158inline ::rtl::OUString Any::getValueTypeName() const
159{
160 return ::rtl::OUString( pType->pTypeName );
161}
162
163inline void Any::setValue( const void * pData_, const Type & rType )
164{
165 ::uno_type_any_assign(
166 this, const_cast< void * >( pData_ ), rType.getTypeLibType(),
167 cpp_acquire, cpp_release );
168}
169
170inline void Any::setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ )
171{
172 ::uno_type_any_assign(
173 this, const_cast< void * >( pData_ ), pType_,
174 cpp_acquire, cpp_release );
175}
176
177inline void Any::setValue( const void * pData_, typelib_TypeDescription * pTypeDescr )
178{
179 ::uno_any_assign(
180 this, const_cast< void * >( pData_ ), pTypeDescr,
181 cpp_acquire, cpp_release );
182}
183
184inline void Any::clear()
185{
186 ::uno_any_clear(
187 this, cpp_release );
188}
189
190inline bool Any::isExtractableTo( const Type & rType ) const
191{
192 return ::uno_type_isAssignableFromData(
193 rType.getTypeLibType(), pData, pType,
194 cpp_queryInterface, cpp_release );
195}
196
197
198template <typename T>
199inline bool Any::has() const
200{
201 Type const & rType = ::cppu::getTypeFavourUnsigned(static_cast< T * >(0));
202 return ::uno_type_isAssignableFromData(
203 rType.getTypeLibType(), pData, pType,
204 cpp_queryInterface,
205 cpp_release );
206}
207
208#if defined LIBO_INTERNAL_ONLY1
209template<> bool Any::has<Any>() const = delete;
210#endif
211
212inline bool Any::operator == ( const Any & rAny ) const
213{
214 return ::uno_type_equalData(
215 pData, pType, rAny.pData, rAny.pType,
216 cpp_queryInterface, cpp_release );
217}
218
219inline bool Any::operator != ( const Any & rAny ) const
220{
221 return (! ::uno_type_equalData(
222 pData, pType, rAny.pData, rAny.pType,
223 cpp_queryInterface, cpp_release ));
224}
225
226
227template< class C >
228inline Any SAL_CALL makeAny( const C & value )
229{
230 return Any(value);
231}
232
233#if !defined LIBO_INTERNAL_ONLY1
234template<> Any makeAny(sal_uInt16 const & value)
235{ return Any(&value, cppu::UnoType<cppu::UnoUnsignedShortType>::get()); }
236#endif
237
238template<typename T> Any toAny(T const & value) { return makeAny(value); }
239
240template<> Any toAny(Any const & value) { return value; }
241
242#if defined LIBO_INTERNAL_ONLY1
243
244template<typename T1, typename T2>
245Any makeAny(rtl::OUStringConcat<T1, T2> && value)
246{ return Any(std::move(value)); }
247
248template<typename T1, typename T2>
249Any toAny(rtl::OUStringConcat<T1, T2> && value)
250{ return makeAny(std::move(value)); }
251
252template<typename T>
253Any makeAny(rtl::OUStringNumber<T> && value)
254{ return Any(OUString(std::move(value))); }
255
256template<typename T>
257Any toAny(rtl::OUStringNumber<T> && value)
258{ return makeAny(std::move(value)); }
259
260template<typename T> bool fromAny(Any const & any, T * value) {
261 assert(value != nullptr)(static_cast <bool> (value != nullptr) ? void (0) : __assert_fail
("value != nullptr", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Any.hxx"
, 261, __extension__ __PRETTY_FUNCTION__))
;
262 return any >>= *value;
263}
264
265template<> bool fromAny(Any const & any, Any * value) {
266 assert(value != nullptr)(static_cast <bool> (value != nullptr) ? void (0) : __assert_fail
("value != nullptr", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Any.hxx"
, 266, __extension__ __PRETTY_FUNCTION__))
;
267 *value = any;
268 return true;
269}
270
271#endif
272
273template< class C >
274inline void SAL_CALL operator <<= ( Any & rAny, const C & value )
275{
276 const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
277 ::uno_type_any_assign(
278 &rAny, const_cast< C * >( &value ), rType.getTypeLibType(),
279 cpp_acquire, cpp_release );
280}
281
282// additionally for C++ bool:
283
284template<>
285inline void SAL_CALL operator <<= ( Any & rAny, bool const & value )
286{
287 sal_Bool b = value;
288 ::uno_type_any_assign(
289 &rAny, &b, cppu::UnoType<bool>::get().getTypeLibType(),
290 cpp_acquire, cpp_release );
291}
292
293
294#ifdef LIBO_INTERNAL_ONLY1 // "RTL_FAST_STRING"
295template< class C1, class C2 >
296inline void SAL_CALL operator <<= ( Any & rAny, rtl::OUStringConcat< C1, C2 >&& value )
297{
298 const rtl::OUString str( std::move(value) );
299 const Type & rType = ::cppu::getTypeFavourUnsigned(&str);
300 ::uno_type_any_assign(
301 &rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(),
302 cpp_acquire, cpp_release );
303}
304template<typename T1, typename T2>
305void operator <<=(Any &, rtl::OUStringConcat<T1, T2> const &) = delete;
306template< class C >
307inline void SAL_CALL operator <<= ( Any & rAny, rtl::OUStringNumber< C >&& value )
308{
309 const rtl::OUString str( std::move(value) );
310 const Type & rType = ::cppu::getTypeFavourUnsigned(&str);
311 ::uno_type_any_assign(
312 &rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(),
313 cpp_acquire, cpp_release );
314}
315template<typename T>
316void operator <<=(Any &, rtl::OUStringNumber<T> const &) = delete;
317#endif
318
319#if defined LIBO_INTERNAL_ONLY1
320template<> void SAL_CALL operator <<=(Any &, Any const &) = delete;
321#endif
322
323template< class C >
324inline bool SAL_CALL operator >>= ( const Any & rAny, C & value )
325{
326 const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
327 return ::uno_type_assignData(
328 &value, rType.getTypeLibType(),
329 rAny.pData, rAny.pType,
330 cpp_queryInterface,
331 cpp_acquire, cpp_release );
332}
333
334// bool
335
336template<>
337inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value )
338{
339 if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass)
340 {
341 value = bool(* static_cast< const sal_Bool * >( rAny.pData ));
342 return true;
343 }
344 return false;
345}
346
347template<>
348inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value )
349{
350 return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass &&
351 bool(value) == bool(* static_cast< const sal_Bool * >( rAny.pData )));
352}
353
354
355template<>
356inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value )
357{
358 if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN)
359 {
360 value = *static_cast< sal_Bool const * >( rAny.pData );
361 return true;
362 }
363 return false;
364}
365
366
367template<>
368inline bool SAL_CALL operator == ( Any const & rAny, bool const & value )
369{
370 return (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN &&
371 (value ==
372 bool(*static_cast< sal_Bool const * >( rAny.pData ))));
373}
374
375// byte
376
377template<>
378inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value )
379{
380 if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass)
381 {
382 value = * static_cast< const sal_Int8 * >( rAny.pData );
383 return true;
384 }
385 return false;
386}
387// short
388
389template<>
390inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value )
391{
392 switch (rAny.pType->eTypeClass)
393 {
394 case typelib_TypeClass_BYTE:
395 value = * static_cast< const sal_Int8 * >( rAny.pData );
396 return true;
397 case typelib_TypeClass_SHORT:
398 case typelib_TypeClass_UNSIGNED_SHORT:
399 value = * static_cast< const sal_Int16 * >( rAny.pData );
400 return true;
401 default:
402 return false;
403 }
404}
405
406template<>
407inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value )
408{
409 switch (rAny.pType->eTypeClass)
410 {
411 case typelib_TypeClass_BYTE:
412 value = static_cast<sal_uInt16>( * static_cast< const sal_Int8 * >( rAny.pData ) );
413 return true;
414 case typelib_TypeClass_SHORT:
415 case typelib_TypeClass_UNSIGNED_SHORT:
416 value = * static_cast< const sal_uInt16 * >( rAny.pData );
417 return true;
418 default:
419 return false;
420 }
421}
422// long
423
424template<>
425inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value )
426{
427 switch (rAny.pType->eTypeClass)
19
Control jumps to the 'default' case at line 442
428 {
429 case typelib_TypeClass_BYTE:
430 value = * static_cast< const sal_Int8 * >( rAny.pData );
431 return true;
432 case typelib_TypeClass_SHORT:
433 value = * static_cast< const sal_Int16 * >( rAny.pData );
434 return true;
435 case typelib_TypeClass_UNSIGNED_SHORT:
436 value = * static_cast< const sal_uInt16 * >( rAny.pData );
437 return true;
438 case typelib_TypeClass_LONG:
439 case typelib_TypeClass_UNSIGNED_LONG:
440 value = * static_cast< const sal_Int32 * >( rAny.pData );
441 return true;
442 default:
443 return false;
20
Returning without writing to 'value'
444 }
445}
446
447template<>
448inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value )
449{
450 switch (rAny.pType->eTypeClass)
451 {
452 case typelib_TypeClass_BYTE:
453 value = static_cast<sal_uInt32>( * static_cast< const sal_Int8 * >( rAny.pData ) );
454 return true;
455 case typelib_TypeClass_SHORT:
456 value = static_cast<sal_uInt32>( * static_cast< const sal_Int16 * >( rAny.pData ) );
457 return true;
458 case typelib_TypeClass_UNSIGNED_SHORT:
459 value = * static_cast< const sal_uInt16 * >( rAny.pData );
460 return true;
461 case typelib_TypeClass_LONG:
462 case typelib_TypeClass_UNSIGNED_LONG:
463 value = * static_cast< const sal_uInt32 * >( rAny.pData );
464 return true;
465 default:
466 return false;
467 }
468}
469// hyper
470
471template<>
472inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value )
473{
474 switch (rAny.pType->eTypeClass)
475 {
476 case typelib_TypeClass_BYTE:
477 value = * static_cast< const sal_Int8 * >( rAny.pData );
478 return true;
479 case typelib_TypeClass_SHORT:
480 value = * static_cast< const sal_Int16 * >( rAny.pData );
481 return true;
482 case typelib_TypeClass_UNSIGNED_SHORT:
483 value = * static_cast< const sal_uInt16 * >( rAny.pData );
484 return true;
485 case typelib_TypeClass_LONG:
486 value = * static_cast< const sal_Int32 * >( rAny.pData );
487 return true;
488 case typelib_TypeClass_UNSIGNED_LONG:
489 value = * static_cast< const sal_uInt32 * >( rAny.pData );
490 return true;
491 case typelib_TypeClass_HYPER:
492 case typelib_TypeClass_UNSIGNED_HYPER:
493 value = * static_cast< const sal_Int64 * >( rAny.pData );
494 return true;
495 default:
496 return false;
497 }
498}
499
500template<>
501inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value )
502{
503 switch (rAny.pType->eTypeClass)
504 {
505 case typelib_TypeClass_BYTE:
506 value = static_cast<sal_uInt64>( * static_cast< const sal_Int8 * >( rAny.pData ) );
507 return true;
508 case typelib_TypeClass_SHORT:
509 value = static_cast<sal_uInt64>( * static_cast< const sal_Int16 * >( rAny.pData ) );
510 return true;
511 case typelib_TypeClass_UNSIGNED_SHORT:
512 value = * static_cast< const sal_uInt16 * >( rAny.pData );
513 return true;
514 case typelib_TypeClass_LONG:
515 value = static_cast<sal_uInt64>( * static_cast< const sal_Int32 * >( rAny.pData ) );
516 return true;
517 case typelib_TypeClass_UNSIGNED_LONG:
518 value = * static_cast< const sal_uInt32 * >( rAny.pData );
519 return true;
520 case typelib_TypeClass_HYPER:
521 case typelib_TypeClass_UNSIGNED_HYPER:
522 value = * static_cast< const sal_uInt64 * >( rAny.pData );
523 return true;
524 default:
525 return false;
526 }
527}
528// float
529
530template<>
531inline bool SAL_CALL operator >>= ( const Any & rAny, float & value )
532{
533 switch (rAny.pType->eTypeClass)
534 {
535 case typelib_TypeClass_BYTE:
536 value = * static_cast< const sal_Int8 * >( rAny.pData );
537 return true;
538 case typelib_TypeClass_SHORT:
539 value = * static_cast< const sal_Int16 * >( rAny.pData );
540 return true;
541 case typelib_TypeClass_UNSIGNED_SHORT:
542 value = * static_cast< const sal_uInt16 * >( rAny.pData );
543 return true;
544 case typelib_TypeClass_FLOAT:
545 value = * static_cast< const float * >( rAny.pData );
546 return true;
547 default:
548 return false;
549 }
550}
551// double
552
553template<>
554inline bool SAL_CALL operator >>= ( const Any & rAny, double & value )
555{
556 switch (rAny.pType->eTypeClass)
557 {
558 case typelib_TypeClass_BYTE:
559 value = * static_cast< const sal_Int8 * >( rAny.pData );
560 return true;
561 case typelib_TypeClass_SHORT:
562 value = * static_cast< const sal_Int16 * >( rAny.pData );
563 return true;
564 case typelib_TypeClass_UNSIGNED_SHORT:
565 value = * static_cast< const sal_uInt16 * >( rAny.pData );
566 return true;
567 case typelib_TypeClass_LONG:
568 value = * static_cast< const sal_Int32 * >( rAny.pData );
569 return true;
570 case typelib_TypeClass_UNSIGNED_LONG:
571 value = * static_cast< const sal_uInt32 * >( rAny.pData );
572 return true;
573 case typelib_TypeClass_FLOAT:
574 value = * static_cast< const float * >( rAny.pData );
575 return true;
576 case typelib_TypeClass_DOUBLE:
577 value = * static_cast< const double * >( rAny.pData );
578 return true;
579 default:
580 return false;
581 }
582}
583// string
584
585template<>
586inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value )
587{
588 if (typelib_TypeClass_STRING == rAny.pType->eTypeClass)
589 {
590 value = * static_cast< const ::rtl::OUString * >( rAny.pData );
591 return true;
592 }
593 return false;
594}
595
596template<>
597inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value )
598{
599 return (typelib_TypeClass_STRING == rAny.pType->eTypeClass &&
600 value == * static_cast< const ::rtl::OUString * >( rAny.pData ) );
601}
602// type
603
604template<>
605inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value )
606{
607 if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass)
608 {
609 value = * static_cast< const Type * >( rAny.pData );
610 return true;
611 }
612 return false;
613}
614
615template<>
616inline bool SAL_CALL operator == ( const Any & rAny, const Type & value )
617{
618 return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass &&
619 value.equals( * static_cast< const Type * >( rAny.pData ) ));
620}
621// any
622
623#if defined LIBO_INTERNAL_ONLY1
624template<> bool SAL_CALL operator >>=(Any const &, Any &) = delete;
625#else
626template<>
627inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value )
628{
629 if (&rAny != &value)
630 {
631 ::uno_type_any_assign(
632 &value, rAny.pData, rAny.pType,
633 cpp_acquire, cpp_release );
634 }
635 return true;
636}
637#endif
638// interface
639
640template<>
641inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value )
642{
643 if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass)
644 {
645 return static_cast< const BaseReference * >( rAny.pData )->operator == ( value );
646 }
647 return false;
648}
649
650// operator to compare to an any.
651
652template< class C >
653inline bool SAL_CALL operator == ( const Any & rAny, const C & value )
654{
655 const Type & rType = ::cppu::getTypeFavourUnsigned(&value);
656 return ::uno_type_equalData(
657 rAny.pData, rAny.pType,
658 const_cast< C * >( &value ), rType.getTypeLibType(),
659 cpp_queryInterface, cpp_release );
660}
661// operator to compare to an any. may use specialized operators ==.
662
663template< class C >
664inline bool SAL_CALL operator != ( const Any & rAny, const C & value )
665{
666 return (! operator == ( rAny, value ));
667}
668
669template <typename T>
670T Any::get() const
671{
672 T value = T();
673 if (! (*this >>= value)) {
674 throw RuntimeException(
675 ::rtl::OUString(
676 cppu_Any_extraction_failure_msg(
677 this,
678 ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ),
679 SAL_NO_ACQUIRE ) );
680 }
681 return value;
682}
683
684#if defined LIBO_INTERNAL_ONLY1
685template<> Any Any::get() const = delete;
686#endif
687
688/**
689 Support for Any in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO
690 macros, for example).
691
692 @since LibreOffice 4.2
693*/
694template<typename charT, typename traits>
695inline std::basic_ostream<charT, traits> &operator<<(std::basic_ostream<charT, traits> &o, Any const &any) {
696 o << "<Any: (" << any.getValueTypeName() << ')';
697 switch(any.pType->eTypeClass) {
698 case typelib_TypeClass_VOID:
699 break;
700 case typelib_TypeClass_BOOLEAN:
701 o << ' ' << any.get<bool>();
702 break;
703 case typelib_TypeClass_BYTE:
704 case typelib_TypeClass_SHORT:
705 case typelib_TypeClass_LONG:
706 case typelib_TypeClass_HYPER:
707 o << ' ' << any.get<sal_Int64>();
708 break;
709 case typelib_TypeClass_UNSIGNED_SHORT:
710 case typelib_TypeClass_UNSIGNED_LONG:
711 case typelib_TypeClass_UNSIGNED_HYPER:
712 o << ' ' << any.get<sal_uInt64>();
713 break;
714 case typelib_TypeClass_FLOAT:
715 case typelib_TypeClass_DOUBLE:
716 o << ' ' << any.get<double>();
717 break;
718 case typelib_TypeClass_CHAR: {
719 std::ios_base::fmtflags flgs = o.setf(
720 std::ios_base::hex, std::ios_base::basefield);
721 charT fill = o.fill('0');
722 o << " U+" << std::setw(4)
723 << unsigned(*static_cast<sal_Unicode const *>(any.getValue()));
724 o.setf(flgs);
725 o.fill(fill);
726 break;
727 }
728 case typelib_TypeClass_STRING:
729 o << ' ' << any.get<rtl::OUString>();
730 break;
731 case typelib_TypeClass_TYPE:
732 o << ' ' << any.get<css::uno::Type>().getTypeName();
733 break;
734 case typelib_TypeClass_SEQUENCE:
735 o << " len "
736 << ((*static_cast<uno_Sequence * const *>(any.getValue()))->
737 nElements);
738 break;
739 case typelib_TypeClass_ENUM:
740 o << ' ' << *static_cast<sal_Int32 const *>(any.getValue());
741 break;
742 case typelib_TypeClass_STRUCT:
743 case typelib_TypeClass_EXCEPTION:
744 o << ' ' << any.getValue();
745 break;
746 case typelib_TypeClass_INTERFACE:
747 o << ' ' << *static_cast<void * const *>(any.getValue());
748 break;
749 default:
750 assert(false)(static_cast <bool> (false) ? void (0) : __assert_fail (
"false", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Any.hxx"
, 750, __extension__ __PRETTY_FUNCTION__))
; // this cannot happen
751 break;
752 }
753 o << '>';
754 return o;
755}
756
757}
758}
759}
760}
761
762#endif
763
764/* vim:set shiftwidth=4 softtabstop=4 expandtab: */