tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / include / comphelper / unwrapargs.hxx
blobe6a1a856aaa63a8abd9d12f6e10fec3d686e2e83
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_COMPHELPER_UNWRAPARGS_HXX
21 #define INCLUDED_COMPHELPER_UNWRAPARGS_HXX
23 #include <sal/config.h>
25 #include <optional>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <com/sun/star/uno/XInterface.hpp>
29 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 #include <cppu/unotype.hxx>
32 namespace comphelper {
34 /// @internal
35 namespace detail {
36 inline void unwrapArgsError(
37 const OUString& str, sal_Int32 nArg,
38 const css::uno::Reference< css::uno::XInterface >& xErrorContext =
39 css::uno::Reference< css::uno::XInterface >() )
41 throw css::lang::IllegalArgumentException(
42 str, xErrorContext, static_cast< sal_Int16 >( nArg ) );
45 template< typename T, typename... Args >
46 inline void unwrapArgsError( const OUString& str, sal_Int32 nArg, T&, Args&... args )
48 return unwrapArgsError( str, nArg, args... );
51 inline void unwrapArgs(
52 const css::uno::Sequence< css::uno::Any >&,
53 sal_Int32,
54 const css::uno::Reference< css::uno::XInterface >& )
56 return;
59 inline void unwrapArgs(
60 const css::uno::Sequence< css::uno::Any >&,
61 sal_Int32 )
63 return;
66 template< typename T, typename... Args >
67 inline void unwrapArgs(
68 const css::uno::Sequence< css::uno::Any >& seq,
69 sal_Int32 nArg, ::std::optional< T >& v, Args&... args );
71 template< typename T, typename... Args >
72 inline void unwrapArgs(
73 const css::uno::Sequence< css::uno::Any >& seq,
74 sal_Int32 nArg, T& v, Args&... args )
76 if( seq.getLength() <= nArg )
78 return unwrapArgsError( u"No such argument available!"_ustr,
79 nArg, args... );
81 if( !fromAny( seq[nArg], &v ) )
83 OUString msg =
84 "Cannot extract ANY { " +
85 seq[nArg].getValueTypeName() +
86 " } to " +
87 ::cppu::UnoType<T>::get().getTypeName() +
88 "!";
89 return unwrapArgsError( msg, nArg, args... );
91 return unwrapArgs( seq, ++nArg, args... );
94 template< typename T, typename... Args >
95 inline void unwrapArgs(
96 const css::uno::Sequence< css::uno::Any >& seq,
97 sal_Int32 nArg, ::std::optional< T >& v, Args&... args )
99 if( nArg < seq.getLength() )
101 T t;
102 unwrapArgs( seq, nArg, t, args... );
103 v = t;
104 } else {
105 unwrapArgs( seq, ++nArg, args... );
110 template< typename... Args >
111 inline void unwrapArgs(
112 const css::uno::Sequence< css::uno::Any >& seq,
113 Args&... args )
115 return detail::unwrapArgs( seq, 0, args... );
118 } // namespace comphelper
120 #endif // ! defined( INCLUDED_COMPHELPER_UNWRAPARGS_HXX)
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */