[Libreoffice-commits] core.git: include/comphelper
Jan Holesovsky
kendy at collabora.com
Thu Jul 20 11:43:35 UTC 2017
include/comphelper/propertysequence.hxx | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
New commits:
commit 36ff567740b58566fc5bf43d7a864d753c079e89
Author: Jan Holesovsky <kendy at collabora.com>
Date: Wed Jul 19 08:35:26 2017 +0200
comphelper: Allow initializer lists for Sequences of NamedValues.
This is particularly useful for creation of sequences that are later
unwrapped using comphelper::SequenceAsHashMap.
Eg.
uno::Sequence<uno::Any> aArguments(comphelper::InitAnySequence(
{
{"SomethingNamed", uno::makeAny(true)},
}));
Reference<XExporter> xExporter(aFactory->createInstanceWithArguments(..., aArguments), UNO_QUERY);
and in the implementation where the arguments are consumed:
comphelper::SequenceAsHashMap aArgumentsMap(rArguments);
mbSomething = aArgumentsMap.getUnpackedValueOrDefault("SomethingNamed", false);
Change-Id: Ib1135078a99ca08f50bf51184f2ec7d13f5e6b4d
Reviewed-on: https://gerrit.libreoffice.org/40201
Reviewed-by: Jan Holesovsky <kendy at collabora.com>
Tested-by: Jan Holesovsky <kendy at collabora.com>
diff --git a/include/comphelper/propertysequence.hxx b/include/comphelper/propertysequence.hxx
index 28561a6904d7..6af3bb389929 100644
--- a/include/comphelper/propertysequence.hxx
+++ b/include/comphelper/propertysequence.hxx
@@ -14,10 +14,12 @@
#include <initializer_list>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/beans/NamedValue.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
namespace comphelper
{
+ /// Init list for property sequences.
inline css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(
::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
{
@@ -33,6 +35,23 @@ namespace comphelper
}
return vResult;
}
+
+ /// Init list for property sequences that wrap the NamedValues in Anys.
+ ///
+ /// This is particularly useful for creation of sequences that are later
+ /// unwrapped using comphelper::SequenceAsHashMap.
+ inline css::uno::Sequence< css::uno::Any > InitAnySequence(
+ ::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
+ {
+ css::uno::Sequence<css::uno::Any> vResult{static_cast<sal_Int32>(vInit.size())};
+ size_t nCount{0};
+ for(const auto& aEntry : vInit)
+ {
+ vResult[nCount] <<= css::beans::NamedValue(aEntry.first, aEntry.second);
+ ++nCount;
+ }
+ return vResult;
+ }
} // namespace comphelper
More information about the Libreoffice-commits
mailing list