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 <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 
29 namespace boost { template <class T> class optional; }
30 
31 namespace comphelper {
32 
34 namespace detail {
35  inline void unwrapArgsError(
36  const OUString& str, sal_Int32 nArg,
37  const css::uno::Reference< css::uno::XInterface >& xErrorContext =
38  css::uno::Reference< css::uno::XInterface >() )
39  {
40  throw css::lang::IllegalArgumentException(
41  str, xErrorContext, static_cast< sal_Int16 >( nArg ) );
42  }
43 
44  template< typename T, typename... Args >
45  inline void unwrapArgsError( const OUString& str, sal_Int32 nArg, T&, Args&... args )
46  {
47  return unwrapArgsError( str, nArg, args... );
48  }
49 
50  inline void unwrapArgs(
51  const css::uno::Sequence< css::uno::Any >&,
52  sal_Int32,
53  const css::uno::Reference< css::uno::XInterface >& )
54  {
55  return;
56  }
57 
58  inline void unwrapArgs(
59  const css::uno::Sequence< css::uno::Any >&,
60  sal_Int32 )
61  {
62  return;
63  }
64 
65  template< typename T, typename... Args >
66  inline void unwrapArgs(
67  const css::uno::Sequence< css::uno::Any >& seq,
68  sal_Int32 nArg, ::boost::optional< T >& v, Args&... args );
69 
70  template< typename T, typename... Args >
71  inline void unwrapArgs(
72  const css::uno::Sequence< css::uno::Any >& seq,
73  sal_Int32 nArg, T& v, Args&... args )
74  {
75  if( seq.getLength() <= nArg )
76  {
77  return unwrapArgsError( OUString( "No such argument available!"),
78  nArg, args... );
79  }
80  if( !fromAny( seq[nArg], &v ) )
81  {
82  OUString msg =
83  "Cannot extract ANY { " +
84  seq[nArg].getValueType().getTypeName() +
85  " } to " +
86  ::cppu::UnoType<T>::get().getTypeName() +
87  "!";
88  return unwrapArgsError( msg, nArg, args... );
89  }
90  return unwrapArgs( seq, ++nArg, args... );
91  }
92 
93  template< typename T, typename... Args >
94  inline void unwrapArgs(
95  const css::uno::Sequence< css::uno::Any >& seq,
96  sal_Int32 nArg, ::boost::optional< T >& v, Args&... args )
97  {
98  if( nArg < seq.getLength() )
99  {
100  T t;
101  unwrapArgs( seq, nArg, t, args... );
102  v = t;
103  } else {
104  unwrapArgs( seq, ++nArg, args... );
105  }
106  }
107 }
108 
109 template< typename... Args >
110 inline void unwrapArgs(
111  const css::uno::Sequence< css::uno::Any >& seq,
112  Args&... args )
113 {
114  return detail::unwrapArgs( seq, 0, args... );
115 }
116 
117 } // namespace comphelper
118 
119 #endif // ! defined( INCLUDED_COMPHELPER_UNWRAPARGS_HXX)
120 
121 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:35
css::uno::Type const & get()
XPropertyListType t
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &, sal_Int32, const css::uno::Reference< css::uno::XInterface > &)
Definition: unwrapargs.hxx:50
void unwrapArgs(const css::uno::Sequence< css::uno::Any > &seq, Args &...args)
Definition: unwrapargs.hxx:110