LibreOffice Module comphelper (master) 1
unwrapargs.hxx
Go to the documentation of this file.
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 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_COMPHELPER_UNWRAPARGS_HXX
21#define INCLUDED_COMPHELPER_UNWRAPARGS_HXX
22
23#include <sal/config.h>
24
25#include <optional>
26
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>
31
32namespace comphelper {
33
35namespace 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 >() )
40 {
41 throw css::lang::IllegalArgumentException(
42 str, xErrorContext, static_cast< sal_Int16 >( nArg ) );
43 }
44
45 template< typename T, typename... Args >
46 inline void unwrapArgsError( const OUString& str, sal_Int32 nArg, T&, Args&... args )
47 {
48 return unwrapArgsError( str, nArg, args... );
49 }
50
51 inline void unwrapArgs(
52 const css::uno::Sequence< css::uno::Any >&,
53 sal_Int32,
54 const css::uno::Reference< css::uno::XInterface >& )
55 {
56 return;
57 }
58
59 inline void unwrapArgs(
60 const css::uno::Sequence< css::uno::Any >&,
61 sal_Int32 )
62 {
63 return;
64 }
65
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 );
70
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 )
75 {
76 if( seq.getLength() <= nArg )
77 {
78 return unwrapArgsError( OUString( "No such argument available!"),
79 nArg, args... );
80 }
81 if( !fromAny( seq[nArg], &v ) )
82 {
83 OUString msg =
84 "Cannot extract ANY { " +
85 seq[nArg].getValueType().getTypeName() +
86 " } to " +
87 ::cppu::UnoType<T>::get().getTypeName() +
88 "!";
89 return unwrapArgsError( msg, nArg, args... );
90 }
91 return unwrapArgs( seq, ++nArg, args... );
92 }
93
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 )
98 {
99 if( nArg < seq.getLength() )
100 {
101 T t;
102 unwrapArgs( seq, nArg, t, args... );
103 v = t;
104 } else {
105 unwrapArgs( seq, ++nArg, args... );
106 }
107 }
108}
109
110template< typename... Args >
111inline void unwrapArgs(
112 const css::uno::Sequence< css::uno::Any >& seq,
113 Args&... args )
114{
115 return detail::unwrapArgs( seq, 0, args... );
116}
117
118} // namespace comphelper
119
120#endif // ! defined( INCLUDED_COMPHELPER_UNWRAPARGS_HXX)
121
122/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
XPropertyListType t
css::uno::Type const & get()
float v
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &, sal_Int32, const css::uno::Reference< css::uno::XInterface > &)
Definition: unwrapargs.hxx:51
void unwrapArgsError(const OUString &str, sal_Int32 nArg, const css::uno::Reference< css::uno::XInterface > &xErrorContext=css::uno::Reference< css::uno::XInterface >())
Definition: unwrapargs.hxx:36
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &seq, Args &... args)
Definition: unwrapargs.hxx:111
args