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 10 #ifndef INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX 11 #define INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX 12 13 #include <utility> 14 #include <algorithm> 15 #include <initializer_list> 16 #include <com/sun/star/uno/Any.hxx> 17 #include <com/sun/star/uno/Sequence.hxx> 18 #include <com/sun/star/beans/PropertyValue.hpp> 19 20 namespace comphelper 21 { 22 /// Init list for property sequences. InitPropertySequence(::std::initializer_list<::std::pair<OUString,css::uno::Any>> vInit)23 inline css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence( 24 ::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit) 25 { 26 css::uno::Sequence< css::beans::PropertyValue> vResult{static_cast<sal_Int32>(vInit.size())}; 27 std::transform(vInit.begin(), vInit.end(), vResult.begin(), 28 [](const std::pair<OUString, css::uno::Any>& rInit) { 29 return css::beans::PropertyValue(rInit.first, -1, rInit.second, 30 css::beans::PropertyState_DIRECT_VALUE); 31 }); 32 return vResult; 33 } 34 35 /// Init list for property sequences that wrap the PropertyValues in Anys. 36 /// 37 /// This is particularly useful for creation of sequences that are later 38 /// unwrapped using comphelper::SequenceAsHashMap. InitAnyPropertySequence(::std::initializer_list<::std::pair<OUString,css::uno::Any>> vInit)39 inline css::uno::Sequence< css::uno::Any > InitAnyPropertySequence( 40 ::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit) 41 { 42 css::uno::Sequence<css::uno::Any> vResult{static_cast<sal_Int32>(vInit.size())}; 43 std::transform(vInit.begin(), vInit.end(), vResult.begin(), 44 [](const std::pair<OUString, css::uno::Any>& rInit) { 45 return css::uno::Any( 46 css::beans::PropertyValue(rInit.first, -1, rInit.second, 47 css::beans::PropertyState_DIRECT_VALUE)); 48 }); 49 return vResult; 50 } 51 } // namespace comphelper 52 53 54 #endif // INCLUDED_COMPHELPER_PROPERTYSEQUENCE_HXX 55 56 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 57