summaryrefslogtreecommitdiff
path: root/xmloff/source/style/styleexp.cxx
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-06-02 15:06:06 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-06-02 15:33:59 +0200
commit0d7c5823124696f80583ac2a5f0e28f329f6f786 (patch)
treec62e4a5490e941f39d775477f1529e9c869fa273 /xmloff/source/style/styleexp.cxx
parente5d8dc12fcf64fbbefadefbe863c772dc9134d38 (diff)
New o3tl::try/doGet to obtain value from Any
...in an attempt to reduce usage of type-unsafe void const * css::uno::Any::getValue() These new functions are often more convenient to use than the existing ">>=" and Any::get<T>. Note how they are careful to provide a pointer directly into the given Any, instead of creating temporaries. As an example, replaced most calls of getValue across xmloff: * Cases that first check for a specific type (via getValueType etc.) and then call getValue can instead call tryGet. (But beware that tryGet supports some conversions, which a check for a specific type may have missed---either intentionally or by accident. Also beware the somewhat common idiom of checking for TypeClass_ENUM and then using getValue to obtain a sal_Int32; this cannot be replaced with a call to tryGet.) * Cases that seem confident that the Any is of the correct type when calling getValue (but apparently are confident due to some higher-layer protocol, as the surrounding code does not do any checking via getValueType or similar) can instead call doGet. It throws an exception if it turns out the confidence wasn't warranted. (Many of the existing calls that directly dereferenced the return value of getValue as sal_Bool look suspicious, in that the author might have thought the given code would also cover a VOID Any---which technically it even would have happened to do. If any RuntimeExceptions thrown from these doGet calls start to crop up, these changes need to be revisited. Some may even be rewritten as uses of ">>=". But at least "make check" did not show any such problems. Also note that casting the value obtained from getValue to any css::uno::Reference<X> with X being anything but the base css::uno::XInterface was always prone to producing a bad pointer, in case the interface actually stored in the Any derived from X via multiple inheritance.) * Should there ever be cases where an Any is known to be of the requested type, some additional forceGet could be introduced (which would assert instead of throwing an exception). Change-Id: I2d8739e86314eff73abfcafe01d806f5bc5c34db
Diffstat (limited to 'xmloff/source/style/styleexp.cxx')
-rw-r--r--xmloff/source/style/styleexp.cxx9
1 files changed, 6 insertions, 3 deletions
diff --git a/xmloff/source/style/styleexp.cxx b/xmloff/source/style/styleexp.cxx
index f96e1c78f188..d87979d57cba 100644
--- a/xmloff/source/style/styleexp.cxx
+++ b/xmloff/source/style/styleexp.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/any.hxx>
#include <tools/debug.hxx>
#include <xmloff/nmspmap.hxx>
#include <xmloff/xmlnmspe.hxx>
@@ -96,7 +99,7 @@ bool XMLStyleExport::exportStyle(
if( xPropSetInfo->hasPropertyByName( sIsPhysical ) )
{
aAny = xPropSet->getPropertyValue( sIsPhysical );
- if( !*static_cast<sal_Bool const *>(aAny.getValue()) )
+ if( !*o3tl::doGet<bool>(aAny) )
return false;
}
@@ -164,7 +167,7 @@ bool XMLStyleExport::exportStyle(
if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
{
aAny = xPropSet->getPropertyValue( sIsAutoUpdate );
- if( *static_cast<sal_Bool const *>(aAny.getValue()) )
+ if( *o3tl::doGet<bool>(aAny) )
GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_AUTO_UPDATE,
XML_TRUE );
}
@@ -474,7 +477,7 @@ void XMLStyleExport::exportStyleFamily(
if (xPropSetInfo->hasPropertyByName( sIsPhysical ))
{
Any aAny( xPropSet->getPropertyValue( sIsPhysical ) );
- if (!*static_cast<sal_Bool const *>(aAny.getValue()))
+ if (!*o3tl::doGet<bool>(aAny))
continue;
}