1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <rtl/ustrbuf.hxx>
24 #include <com/sun/star/uno/Sequence.hxx>
25 #include <com/sun/star/uno/XInterface.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
27 #include <cppu/unotype.hxx>
28 #include <boost/optional.hpp>
30 namespace comphelper
{
34 inline void unwrapArgsError(
35 const OUString
& str
, sal_Int32 nArg
,
36 const css::uno::Reference
< css::uno::XInterface
>& xErrorContext
=
37 css::uno::Reference
< css::uno::XInterface
>() )
39 throw css::lang::IllegalArgumentException(
40 str
, xErrorContext
, static_cast< sal_Int16
>( nArg
) );
43 template< typename T
, typename
... Args
>
44 inline void unwrapArgsError( const OUString
& str
, sal_Int32 nArg
, T
&, Args
&... args
)
46 return unwrapArgsError( str
, nArg
, args
... );
49 inline void unwrapArgs(
50 const css::uno::Sequence
< css::uno::Any
>&,
52 const css::uno::Reference
< css::uno::XInterface
>& )
57 inline void unwrapArgs(
58 const css::uno::Sequence
< css::uno::Any
>&,
64 template< typename T
, typename
... Args
>
65 inline void unwrapArgs(
66 const css::uno::Sequence
< css::uno::Any
>& seq
,
67 sal_Int32 nArg
, ::boost::optional
< T
>& v
, Args
&... args
);
69 template< typename T
, typename
... Args
>
70 inline void unwrapArgs(
71 const css::uno::Sequence
< css::uno::Any
>& seq
,
72 sal_Int32 nArg
, T
& v
, Args
&... args
)
74 if( seq
.getLength() <= nArg
)
76 return unwrapArgsError( OUString( "No such argument available!"),
79 if( !fromAny( seq
[nArg
], &v
) )
82 buf
.append( "Cannot extract ANY { " );
83 buf
.append( seq
[nArg
].getValueType().getTypeName() );
84 buf
.append( " } to " );
85 buf
.append( ::cppu::UnoType
<T
>::get().getTypeName() );
87 return unwrapArgsError( buf
.makeStringAndClear(), nArg
, args
... );
89 return unwrapArgs( seq
, ++nArg
, args
... );
92 template< typename T
, typename
... Args
>
93 inline void unwrapArgs(
94 const css::uno::Sequence
< css::uno::Any
>& seq
,
95 sal_Int32 nArg
, ::boost::optional
< T
>& v
, Args
&... args
)
97 if( nArg
< seq
.getLength() )
100 unwrapArgs( seq
, nArg
, t
, args
... );
103 unwrapArgs( seq
, ++nArg
, args
... );
108 template< typename
... Args
>
109 inline void unwrapArgs(
110 const css::uno::Sequence
< css::uno::Any
>& seq
,
113 return detail::unwrapArgs( seq
, 0, args
... );
116 } // namespace comphelper
118 #endif // ! defined( INCLUDED_COMPHELPER_UNWRAPARGS_HXX)
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */