Bug Summary

File:home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx
Warning:line 107, column 5
2nd function call argument is an uninitialized 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 unoapi_property_testers.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 OOO_DLLIMPLEMENTATION_TEST -D SYSTEM_LIBXML -D HAVE_VALGRIND_HEADERS -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/cppunit/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/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/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/test/source/unoapi_property_testers.cxx

/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10#include <test/unoapi_property_testers.hxx>
11
12#include <com/sun/star/uno/Any.hxx>
13#include <cppunit/TestAssert.h>
14
15using namespace css;
16
17namespace apitest
18{
19void testBooleanProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
20 const OUString& name)
21{
22 uno::Any aNewValue;
23
24 bool bPropertyGet = false;
25 bool bPropertySet = false;
26
27 OString msgGet
28 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
29 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= bPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= bPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= bPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 29 ) ) )
;
30
31 aNewValue <<= !bPropertyGet;
32 xPropertySet->setPropertyValue(name, aNewValue);
33 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= bPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= bPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= bPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 33 ) ) )
;
34 OString msgSet
35 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
36 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), !bPropertyGet, bPropertySet)( CppUnit::assertEquals( (!bPropertyGet), (bPropertySet), CppUnit
::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 36 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
37}
38
39void testBooleanOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
40 const OUString& rName)
41{
42 try
43 {
44 testBooleanProperty(xPropertySet, rName);
45 }
46 catch (const css::beans::UnknownPropertyException& /*ex*/)
47 {
48 // ignore if the property is unknown as it is optional
49 }
50}
51
52void testBooleanReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
53 const OUString& name)
54{
55 uno::Any aNewValue;
56
57 bool bPropertyGet = false;
58 bool bPropertySet = false;
59
60 OString msgGet
61 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
62 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= bPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= bPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= bPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 62 ) ) )
;
63
64 aNewValue <<= !bPropertyGet;
65 xPropertySet->setPropertyValue(name, aNewValue);
66 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= bPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= bPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= bPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 66 ) ) )
;
67 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
68 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), bPropertyGet, bPropertySet)( CppUnit::assertEquals( (bPropertyGet), (bPropertySet), CppUnit
::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 68 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
69}
70
71void testDoubleProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
72 const OUString& name, const double& dValue)
73{
74 uno::Any aNewValue;
75
76 double dPropertyGet;
77 double dPropertySet;
78
79 OString msgGet
80 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
81 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= dPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= dPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= dPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 81 ) ) )
;
82
83 aNewValue <<= dValue;
84 xPropertySet->setPropertyValue(name, aNewValue);
85 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= dPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= dPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= dPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 85 ) ) )
;
86 OString msgSet
87 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
88 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dValue, dPropertySet, 0.5)( CppUnit::assertDoubleEquals( (dValue), (dPropertySet), (0.5
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 88 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
89}
90
91void testDoubleReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
92 const OUString& name, const double& dValue)
93{
94 uno::Any aNewValue;
95
96 double dPropertyGet;
97 double dPropertySet;
1
'dPropertySet' declared without an initial value
98
99 OString msgGet
100 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
101 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= dPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= dPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= dPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 101 ) ) )
;
102
103 aNewValue <<= dValue;
104 xPropertySet->setPropertyValue(name, aNewValue);
105 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= dPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= dPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= dPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 105 ) ) )
;
2
Calling 'operator>>=<double>'
5
Returning from 'operator>>=<double>'
106 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
107 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(msgSet.getStr(), dPropertyGet, dPropertySet, 0.5)( CppUnit::assertDoubleEquals( (dPropertyGet), (dPropertySet)
, (0.5), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 107 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
6
2nd function call argument is an uninitialized value
108}
109
110void testLongProperty(uno::Reference<beans::XPropertySet> const& xPropertySet, const OUString& name,
111 const sal_Int32& nValue)
112{
113 uno::Any aNewValue;
114
115 sal_Int32 nPropertyGet;
116 sal_Int32 nPropertySet;
117
118 OString msgGet
119 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
120 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= nPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= nPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 120 ) ) )
;
121
122 aNewValue <<= nValue;
123 xPropertySet->setPropertyValue(name, aNewValue);
124 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= nPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= nPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 124 ) ) )
;
125 OString msgSet
126 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
127 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet)( CppUnit::assertEquals( (nValue), (nPropertySet), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 127 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
128}
129
130void testLongOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
131 const OUString& rName, const sal_Int32& rValue)
132{
133 try
134 {
135 testLongProperty(xPropertySet, rName, rValue);
136 }
137 catch (const css::beans::UnknownPropertyException& /*ex*/)
138 {
139 // ignore if the property is unknown as it is optional
140 }
141}
142
143void testLongReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
144 const OUString& name, const sal_Int32& nValue)
145{
146 uno::Any aNewValue;
147
148 sal_Int32 nPropertyGet;
149 sal_Int32 nPropertySet;
150
151 OString msgGet
152 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
153 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= nPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= nPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 153 ) ) )
;
154
155 aNewValue <<= nValue;
156 xPropertySet->setPropertyValue(name, aNewValue);
157 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= nPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= nPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 157 ) ) )
;
158 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
159 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nPropertyGet, nPropertySet)( CppUnit::assertEquals( (nPropertyGet), (nPropertySet), CppUnit
::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 159 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
160}
161
162void testShortProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
163 const OUString& name, const sal_Int16& nValue)
164{
165 uno::Any aNewValue;
166
167 sal_Int16 nPropertyGet;
168 sal_Int16 nPropertySet;
169
170 OString msgGet
171 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
172 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= nPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= nPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 172 ) ) )
;
173
174 aNewValue <<= nValue;
175 xPropertySet->setPropertyValue(name, aNewValue);
176 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= nPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= nPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 176 ) ) )
;
177 OString msgSet
178 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
179 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nValue, nPropertySet)( CppUnit::assertEquals( (nValue), (nPropertySet), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 179 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
180}
181
182void testShortOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
183 const OUString& rName, const sal_Int16& rValue)
184{
185 try
186 {
187 testShortProperty(xPropertySet, rName, rValue);
188 }
189 catch (const css::beans::UnknownPropertyException& /*ex*/)
190 {
191 // ignore if the property is unknown as it is optional
192 }
193}
194
195void testShortReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
196 const OUString& name, const sal_Int16& nValue)
197{
198 uno::Any aNewValue;
199
200 sal_Int16 nPropertyGet;
201 sal_Int16 nPropertySet;
202
203 OString msgGet
204 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
205 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= nPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= nPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= nPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 205 ) ) )
;
206
207 aNewValue <<= nValue;
208 xPropertySet->setPropertyValue(name, aNewValue);
209 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= nPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= nPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= nPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 209 ) ) )
;
210 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
211 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), nPropertyGet, nPropertySet)( CppUnit::assertEquals( (nPropertyGet), (nPropertySet), CppUnit
::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 211 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
212}
213
214void testStringOptionalProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
215 const OUString& rName, const OUString& rValue)
216{
217 try
218 {
219 testStringProperty(xPropertySet, rName, rValue);
220 }
221 catch (const css::beans::UnknownPropertyException& /*ex*/)
222 {
223 // ignore if the property is unknown as it is optional
224 }
225}
226
227void testStringProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
228 const OUString& name, const OUString& rValue)
229{
230 uno::Any aNewValue;
231
232 OUString sPropertyGet;
233 OUString sPropertySet;
234
235 OString msgGet
236 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
237 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= sPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= sPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 237 ) ) )
;
238
239 aNewValue <<= rValue;
240 xPropertySet->setPropertyValue(name, aNewValue);
241 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= sPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= sPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 241 ) ) )
;
242 OString msgSet
243 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
244 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), rValue, sPropertySet)( CppUnit::assertEquals( (rValue), (sPropertySet), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 244 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
245}
246
247void testStringReadonlyProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
248 const OUString& name, const OUString& rValue)
249{
250 uno::Any aNewValue;
251
252 OUString sPropertyGet;
253 OUString sPropertySet;
254
255 OString msgGet
256 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
257 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= sPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= sPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 257 ) ) )
;
258
259 aNewValue <<= rValue;
260 xPropertySet->setPropertyValue(name, aNewValue);
261 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= sPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= sPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 261 ) ) )
;
262 OString msgSet = "Able to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
263 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), sPropertyGet, sPropertySet)( CppUnit::assertEquals( (sPropertyGet), (sPropertySet), CppUnit
::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 263 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
264}
265
266void testColorProperty(uno::Reference<beans::XPropertySet> const& xPropertySet,
267 const OUString& name, const util::Color& rValue)
268{
269 uno::Any aNewValue;
270
271 util::Color sPropertyGet;
272 util::Color sPropertySet;
273
274 OString msgGet
275 = "Unable to get PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
276 CPPUNIT_ASSERT_MESSAGE(msgGet.getStr(), xPropertySet->getPropertyValue(name) >>= sPropertyGet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= sPropertyGet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= sPropertyGet"
, CppUnit::message_to_string(msgGet.getStr()) ), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 276 ) ) )
;
277
278 aNewValue <<= rValue;
279 xPropertySet->setPropertyValue(name, aNewValue);
280 CPPUNIT_ASSERT(xPropertySet->getPropertyValue(name) >>= sPropertySet)( CppUnit::Asserter::failIf( !(xPropertySet->getPropertyValue
(name) >>= sPropertySet), CppUnit::Message( "assertion failed"
, "Expression: " "xPropertySet->getPropertyValue(name) >>= sPropertySet"
), CppUnit::SourceLine( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 280 ) ) )
;
281 OString msgSet
282 = "Unable to set PropertyValue: " + OUStringToOString(name, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
283 CPPUNIT_ASSERT_EQUAL_MESSAGE(msgSet.getStr(), rValue, sPropertySet)( CppUnit::assertEquals( (rValue), (sPropertySet), CppUnit::SourceLine
( "/home/maarten/src/libreoffice/core/test/source/unoapi_property_testers.cxx"
, 283 ), CppUnit::message_to_string(msgSet.getStr()) ) )
;
284}
285
286} // namespace apitest
287
288/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */

/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)
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;
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)
3
Control jumps to the 'default' case at line 579
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;
4
Returning without writing to 'value'
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: */