diff options
author | Jan Holesovsky <kendy@collabora.com> | 2017-07-19 08:35:26 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-07-20 09:18:16 +0200 |
commit | 96c54dc16b6870a634b2779b954d7eca35d5a606 (patch) | |
tree | 9f50c5b321f5a124e16390486614196bb99a6a5c /include | |
parent | 0eb0c7308ad57f4a20b5691d450b5185e52475f6 (diff) |
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:
comphelper::SequenceAsHashMap aArgumentsMap(rArguments);
mbSomething = aArgumentsMap.getUnpackedValueOrDefault("SomethingNamed", false);
Change-Id: Ib1135078a99ca08f50bf51184f2ec7d13f5e6b4d
Reviewed-on: https://gerrit.libreoffice.org/40194
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r-- | include/comphelper/propertysequence.hxx | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/comphelper/propertysequence.hxx b/include/comphelper/propertysequence.hxx index 28561a6904d7..6af5bcccc6fc 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::uno::makeAny(css::beans::NamedValue(aEntry.first, aEntry.second)); + ++nCount; + } + return vResult; + } } // namespace comphelper |