include/comphelper/sequenceashashmap.hxx | 24 ++++++++++++++++ sw/source/core/unocore/unocrsrhelper.cxx | 44 +++++++------------------------ sw/source/core/unocore/unotbl.cxx | 16 ++++++----- 3 files changed, 43 insertions(+), 41 deletions(-)
New commits: commit 783b93978d49ccdbc30b4afdd95a94980f99100e Author: Jochen Nitschke <[email protected]> Date: Fri Oct 21 17:23:10 2016 +0200 introduce getValue(sKey) for SequenceAsHashMap returns the plain value (Any) if it exists, else return an empty Any replaces some getUnpackedValueOrDefault calls in sw where is was not clear if the unpacked value exsisted or was default needed for removal of Any-to-Any template specialisations Change-Id: I618da7a7174143f5edef48e47e7aa1b6a52845e1 Reviewed-on: https://gerrit.libreoffice.org/30114 Tested-by: Jenkins <[email protected]> Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/include/comphelper/sequenceashashmap.hxx b/include/comphelper/sequenceashashmap.hxx index cea5493..fdec8cc 100644 --- a/include/comphelper/sequenceashashmap.hxx +++ b/include/comphelper/sequenceashashmap.hxx @@ -237,6 +237,30 @@ class COMPHELPER_DLLPUBLIC SequenceAsHashMap : public SequenceAsHashMapBase return aValue; } + /** @short check if the specified item exists + and return its value or it returns + an empty css::uno::Any. + + @descr If a value should be extracted only in case + the requested property exists really (without creating + of new items as the index operator of a + hash map does!) this method can be used. + + @param sKey + key name of the item. + + @return The value of the specified property or + an empty css::uno::Any. + */ + inline css::uno::Any getValue(const OUString& sKey) const + { + const_iterator pIt = find(sKey); + if (pIt == end()) + return css::uno::Any(); + + return pIt->second; + } + /** @short creates a new item with the specified name and value only in case such item name diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx index 8de8c1e..6ee2bb8 100644 --- a/sw/source/core/unocore/unocrsrhelper.cxx +++ b/sw/source/core/unocore/unocrsrhelper.cxx @@ -1172,25 +1172,18 @@ void makeRedline( SwPaM& rPaM, //todo: what about REDLINE_FMTCOLL? comphelper::SequenceAsHashMap aPropMap( rRedlineProperties ); - uno::Any aAuthorValue; - aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue); sal_uInt16 nAuthor = 0; OUString sAuthor; - if( aAuthorValue >>= sAuthor ) + if( aPropMap.getValue("RedlineAuthor") >>= sAuthor ) nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor); OUString sComment; - uno::Any aCommentValue; - aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue); - SwRedlineData aRedlineData( eType, nAuthor ); - if( aCommentValue >>= sComment ) + if( aPropMap.getValue("RedlineComment") >>= sComment ) aRedlineData.SetComment( sComment ); ::util::DateTime aStamp; - uno::Any aDateTimeValue; - aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue); - if( aDateTimeValue >>= aStamp ) + if( aPropMap.getValue("RedlineDateTime") >>= aStamp ) { aRedlineData.SetTimeStamp( DateTime( aStamp)); } @@ -1199,11 +1192,8 @@ void makeRedline( SwPaM& rPaM, // Read the 'Redline Revert Properties' from the parameters uno::Sequence< beans::PropertyValue > aRevertProperties; - uno::Any aRevertPropertiesValue; - aRevertPropertiesValue = aPropMap.getUnpackedValueOrDefault("RedlineRevertProperties", aRevertPropertiesValue); - // Check if the value exists - if ( aRevertPropertiesValue >>= aRevertProperties ) + if ( aPropMap.getValue("RedlineRevertProperties") >>= aRevertProperties ) { int nMap = 0; // Make sure that paragraph format gets its own map, otherwise e.g. fill attributes are not preserved. @@ -1297,25 +1287,18 @@ void makeTableRowRedline( SwTableLine& rTableLine, } comphelper::SequenceAsHashMap aPropMap( rRedlineProperties ); - uno::Any aAuthorValue; - aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue); sal_uInt16 nAuthor = 0; OUString sAuthor; - if( aAuthorValue >>= sAuthor ) + if( aPropMap.getValue("RedlineAuthor") >>= sAuthor ) nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor); OUString sComment; - uno::Any aCommentValue; - aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue); - SwRedlineData aRedlineData( eType, nAuthor ); - if( aCommentValue >>= sComment ) + if( aPropMap.getValue("RedlineComment") >>= sComment ) aRedlineData.SetComment( sComment ); ::util::DateTime aStamp; - uno::Any aDateTimeValue; - aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue); - if( aDateTimeValue >>= aStamp ) + if( aPropMap.getValue("RedlineDateTime") >>= aStamp ) { aRedlineData.SetTimeStamp( DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), tools::Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) ); @@ -1354,25 +1337,18 @@ void makeTableCellRedline( SwTableBox& rTableBox, } comphelper::SequenceAsHashMap aPropMap( rRedlineProperties ); - uno::Any aAuthorValue; - aAuthorValue = aPropMap.getUnpackedValueOrDefault("RedlineAuthor", aAuthorValue); sal_uInt16 nAuthor = 0; OUString sAuthor; - if( aAuthorValue >>= sAuthor ) + if( aPropMap.getValue("RedlineAuthor") >>= sAuthor ) nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor); OUString sComment; - uno::Any aCommentValue; - aCommentValue = aPropMap.getUnpackedValueOrDefault("RedlineComment", aCommentValue); - SwRedlineData aRedlineData( eType, nAuthor ); - if( aCommentValue >>= sComment ) + if( aPropMap.getValue("RedlineComment") >>= sComment ) aRedlineData.SetComment( sComment ); ::util::DateTime aStamp; - uno::Any aDateTimeValue; - aDateTimeValue = aPropMap.getUnpackedValueOrDefault("RedlineDateTime", aDateTimeValue); - if( aDateTimeValue >>= aStamp ) + if( aPropMap.getValue("RedlineDateTime") >>= aStamp ) { aRedlineData.SetTimeStamp( DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), tools::Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) ); diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx index 88b85f5..0eab027 100644 --- a/sw/source/core/unocore/unotbl.cxx +++ b/sw/source/core/unocore/unotbl.cxx @@ -1037,11 +1037,15 @@ void SwXCell::setPropertyValue(const OUString& rPropertyName, const uno::Any& aV uno::Sequence<beans::PropertyValue> tableCellProperties; tableCellProperties = aValue.get< uno::Sequence< beans::PropertyValue > >(); comphelper::SequenceAsHashMap aPropMap(tableCellProperties); - uno::Any sRedlineTypeValue = aPropMap.getUnpackedValueOrDefault("RedlineType", uno::Any()); - if(!sRedlineTypeValue.has<OUString>()) + OUString sRedlineType; + if(aPropMap.getValue("RedlineType") >>= sRedlineType) + { + // Create a 'Table Cell Redline' object + SwUnoCursorHelper::makeTableCellRedline(*pBox, sRedlineType, tableCellProperties); + } + else throw beans::UnknownPropertyException("No redline type property: ", static_cast<cppu::OWeakObject*>(this)); - // Create a 'Table Cell Redline' object - SwUnoCursorHelper::makeTableCellRedline(*pBox, sRedlineTypeValue.get<OUString>(), tableCellProperties); + } else { @@ -1312,9 +1316,7 @@ void SwXTextTableRow::setPropertyValue(const OUString& rPropertyName, const uno: tableRowProperties = aValue.get< uno::Sequence< beans::PropertyValue > >(); comphelper::SequenceAsHashMap aPropMap( tableRowProperties ); OUString sRedlineType; - uno::Any sRedlineTypeValue; - sRedlineTypeValue = aPropMap.getUnpackedValueOrDefault("RedlineType", sRedlineTypeValue); - if( sRedlineTypeValue >>= sRedlineType ) + if( aPropMap.getValue("RedlineType") >>= sRedlineType ) { // Create a 'Table Row Redline' object SwUnoCursorHelper::makeTableRowRedline( *pLn, sRedlineType, tableRowProperties); _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
