summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDaniel Robertson <danlrobertson89@gmail.com>2015-09-25 22:09:56 -0400
committerMichael Stahl <mstahl@redhat.com>2015-10-06 19:29:43 +0000
commit6ca355d281133c1e0e54df4e4710a4e99bc38c17 (patch)
treee704d05e13f8122e44a360c8ef6cb7bba2307323 /include
parent43d35f56efc0a4b79909dc9fbd7b0483204b6f1a (diff)
tdf#94228 comphelper: replace BOOST_PP
Replace BOOST_PP macros in comphelper with variadic templates. The client interface should not change. However, there are a few side effects due to this change. The most important being 1) There is no longer a maximum number of service declarations limmited by default at 12 for unwrapArgs and component_getFactoryHelper. 2) component_getFactoryHelper now terminates early as soon as pRet is not a null pointer. Change-Id: I016fd208d0e80f91d8669fff29d58b6189e946d3 Reviewed-on: https://gerrit.libreoffice.org/18891 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'include')
-rw-r--r--include/comphelper/servicedecl.hxx70
-rw-r--r--include/comphelper/unwrapargs.hxx164
2 files changed, 101 insertions, 133 deletions
diff --git a/include/comphelper/servicedecl.hxx b/include/comphelper/servicedecl.hxx
index f9b0b12ddb01..b315e8e04ec5 100644
--- a/include/comphelper/servicedecl.hxx
+++ b/include/comphelper/servicedecl.hxx
@@ -24,10 +24,6 @@
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <uno/environment.h>
-#include <boost/noncopyable.hpp>
-#include <boost/preprocessor/cat.hpp>
-#include <boost/preprocessor/repetition.hpp>
-#include <boost/preprocessor/seq/enum.hpp>
#include <functional>
@@ -97,7 +93,7 @@ typedef ::std::function<
In the latter case, somePostProcCode gets the yet unacquired "raw" pointer.
*/
-class COMPHELPER_DLLPUBLIC ServiceDecl : private ::boost::noncopyable
+class COMPHELPER_DLLPUBLIC ServiceDecl
{
public:
/** Ctor for multiple supported service names.
@@ -107,6 +103,8 @@ public:
@param pSupportedServiceNames supported service names
@param cDelim delimiter for supported service names
*/
+ ServiceDecl( const ServiceDecl& ) = delete;
+ ServiceDecl& operator=( const ServiceDecl& ) = delete;
template <typename ImplClassT>
ServiceDecl( ImplClassT const& implClass,
char const* pImplName,
@@ -148,12 +146,13 @@ template <bool> struct with_args;
namespace detail {
template <typename ImplT>
class OwnServiceImpl
- : public ImplT,
- private ::boost::noncopyable
+ : public ImplT
{
typedef ImplT BaseT;
public:
+ OwnServiceImpl( const OwnServiceImpl& ) = delete;
+ OwnServiceImpl& operator=( const OwnServiceImpl& ) = delete;
OwnServiceImpl(
ServiceDecl const& rServiceDecl,
css::uno::Sequence<css::uno::Any> const& args,
@@ -336,44 +335,31 @@ struct inheritingClass_ : public serviceimpl_base< detail::InheritingServiceImpl
// component_... helpers with arbitrary service declarations:
-
-#define COMPHELPER_SERVICEDECL_getFactory(z_, n_, unused_) \
- if (pRet == 0) \
- pRet = BOOST_PP_CAT(s, n_).getFactory(pImplName);
-
-/** The following preprocessor repetitions generate functions like
-
- <pre>
- inline void * component_getFactoryHelper(
- sal_Char const* pImplName,
- ServiceDecl const& s0, ServiceDecl const& s1, ... );
- </pre>
-
- which call on the passed service declarations.
-
- The maximum number of service declarations can be set by defining
- COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS; its default is 8.
-*/
-#define COMPHELPER_SERVICEDECL_make(z_, n_, unused_) \
-inline void * component_getFactoryHelper( \
- sal_Char const* pImplName, \
- BOOST_PP_ENUM_PARAMS(n_, ServiceDecl const& s) ) \
-{ \
- void * pRet = 0; \
- BOOST_PP_REPEAT(n_, COMPHELPER_SERVICEDECL_getFactory, ~) \
- return pRet; \
+template< typename T >
+inline void* component_getFactoryHelper( const sal_Char* pImplName, void* pRet,
+ const T& s )
+{
+ if( pRet == 0 )
+ return s.getFactory( pImplName );
+ return pRet;
}
-#ifndef COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS
-#define COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS 8
-#endif
-
-BOOST_PP_REPEAT_FROM_TO(1, COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS,
- COMPHELPER_SERVICEDECL_make, ~)
+template< typename T, typename... Args >
+inline void* component_getFactoryHelper( const sal_Char* pImplName, void* pRet,
+ const T& s, const Args&... args )
+{
+ if( pRet == 0 )
+ return component_getFactoryHelper( pImplName, s.getFactory( pImplName ), args... );
+ return pRet;
+}
-#undef COMPHELPER_SERVICEDECL_COMPONENT_HELPER_MAX_ARGS
-#undef COMPHELPER_SERVICEDECL_make
-#undef COMPHELPER_SERVICEDECL_getFactory
+template< typename... Args >
+inline void* component_getFactoryHelper( const sal_Char* pImplName,
+ const Args&... args )
+{
+ void* pRet = 0;
+ return component_getFactoryHelper( pImplName, pRet, args... );
+}
} // namespace service_decl
} // namespace comphelper
diff --git a/include/comphelper/unwrapargs.hxx b/include/comphelper/unwrapargs.hxx
index 6c76f9dcbde4..af07ef66987c 100644
--- a/include/comphelper/unwrapargs.hxx
+++ b/include/comphelper/unwrapargs.hxx
@@ -22,114 +22,96 @@
#include <rtl/ustrbuf.hxx>
#include <com/sun/star/uno/Sequence.hxx>
+#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
-#include <boost/optional.hpp>
-#include <boost/preprocessor/cat.hpp>
-#include <boost/preprocessor/repetition.hpp>
-#include <boost/preprocessor/arithmetic/add.hpp>
#include <cppu/unotype.hxx>
+#include <boost/optional.hpp>
namespace comphelper {
-
-// generating helper functions to unwrap the service's argument sequence:
-
-
/// @internal
namespace detail {
-
-template <typename T>
-inline void extract(
- ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> const& seq,
- sal_Int32 nArg, T & v,
- ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>
- const& xErrorContext )
-{
- if (nArg >= seq.getLength()) {
- throw ::com::sun::star::lang::IllegalArgumentException(
- OUString( "No such argument available!"),
- xErrorContext, static_cast<sal_Int16>(nArg) );
- }
- if (! (seq[nArg] >>= v)) {
- OUStringBuffer buf;
- buf.append( "Cannot extract ANY { " );
- buf.append( seq[nArg].getValueType().getTypeName() );
- buf.append( " } to " );
- buf.append( ::cppu::UnoType<T>::get().getTypeName() );
- buf.append( static_cast<sal_Unicode>('!') );
+ inline void unwrapArgsError(
+ const OUString& str, sal_Int32 nArg,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xErrorContext =
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() )
+ {
throw ::com::sun::star::lang::IllegalArgumentException(
- buf.makeStringAndClear(), xErrorContext,
- static_cast<sal_Int16>(nArg) );
+ str, xErrorContext, static_cast< sal_Int16 >( nArg ) );
}
-}
-template <typename T>
-inline void extract(
- ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> const& seq,
- sal_Int32 nArg, ::boost::optional<T> & v,
- ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>
- const& xErrorContext )
-{
- if (nArg < seq.getLength()) {
- T t;
- extract( seq, nArg, t, xErrorContext );
- v.reset( t );
+ template< typename T, typename... Args >
+ inline void unwrapArgsError( const OUString& str, sal_Int32 nArg, T&, Args&... args )
+ {
+ return unwrapArgsError( str, nArg, args... );
}
-}
-
-} // namespace detail
-
-#define COMPHELPER_UNWRAPARGS_extract(z_, n_, unused_) \
- detail::extract( seq, n_, BOOST_PP_CAT(v, n_), xErrorContext );
-#define COMPHELPER_UNWRAPARGS_args(z_, n_, unused_) \
- BOOST_PP_CAT(T, n_) & BOOST_PP_CAT(v, n_)
-/** The following preprocessor repetitions generate functions like
+ inline void unwrapArgs(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&,
+ sal_Int32,
+ const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& )
+ {
+ return;
+ }
- <pre>
- template <typename T0, typename T1, ...>
- inline void unwrapArgs(
- uno::Sequence<uno::Any> const& seq,
- T0 & v0, T1 & v1, ...,
- css::uno::Reference<css::uno::XInterface> const& xErrorContext =
- css::uno::Reference<css::uno::XInterface>() );
- </pre>
- (full namespace qualification ::com::sun::star has been omitted
- for brevity)
+ inline void unwrapArgs(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >&,
+ sal_Int32 )
+ {
+ return;
+ }
- which unwraps the passed sequence's elements, assigning them to the
- referenced values. Specify optional arguments as boost::optional<T>.
- If the length of the sequence is greater than the count of arguments,
- then the latter sequence elements are ignored.
- If too few arguments are given in the sequence and a missing argument is
- no boost::optional<T>, then an lang::IllegalArgumentException is thrown
- with the specified xErrorContext (defaults to null-ref).
+ template< typename T, typename... Args >
+ inline void unwrapArgs(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& seq,
+ sal_Int32 nArg, ::boost::optional< T >& v, Args&... args );
+
+ template< typename T, typename... Args >
+ inline void unwrapArgs(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& seq,
+ sal_Int32 nArg, T& v, Args&... args )
+ {
+ if( seq.getLength() <= nArg )
+ {
+ return unwrapArgsError( OUString( "No such argument available!"),
+ nArg, args... );
+ }
+ if( ! ( seq[nArg] >>= v ) )
+ {
+ OUStringBuffer buf;
+ buf.append( "Cannot extract ANY { " );
+ buf.append( seq[nArg].getValueType().getTypeName() );
+ buf.append( " } to " );
+ buf.append( ::cppu::UnoType<T>::get().getTypeName() );
+ buf.append( static_cast<sal_Unicode>('!') );
+ return unwrapArgsError( buf.makeStringAndClear(), nArg, args... );
+ }
+ return unwrapArgs( seq, ++nArg, args... );
+ }
- The maximum number of service declarations can be set by defining
- COMPHELPER_UNWRAPARGS_MAX_ARGS; its default is 12.
-*/
-#define COMPHELPER_UNWRAPARGS_make(z_, n_, unused_) \
-template < BOOST_PP_ENUM_PARAMS( BOOST_PP_ADD(n_, 1), typename T) > \
-inline void unwrapArgs( \
- ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > const& seq, \
- BOOST_PP_ENUM(BOOST_PP_ADD(n_, 1), COMPHELPER_UNWRAPARGS_args, ~), \
- ::com::sun::star::uno::Reference< \
- ::com::sun::star::uno::XInterface> const& xErrorContext = \
- ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>() ) \
-{ \
- BOOST_PP_REPEAT(BOOST_PP_ADD(n_, 1), COMPHELPER_UNWRAPARGS_extract, ~) \
+ template< typename T, typename... Args >
+ inline void unwrapArgs(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& seq,
+ sal_Int32 nArg, ::boost::optional< T >& v, Args&... args )
+ {
+ if( nArg < seq.getLength() )
+ {
+ T t;
+ unwrapArgs( seq, nArg, t, args... );
+ v = t;
+ } else {
+ unwrapArgs( seq, ++nArg, args... );
+ }
+ }
}
-#ifndef COMPHELPER_UNWRAPARGS_MAX_ARGS
-#define COMPHELPER_UNWRAPARGS_MAX_ARGS 12
-#endif
-
-BOOST_PP_REPEAT(COMPHELPER_UNWRAPARGS_MAX_ARGS, COMPHELPER_UNWRAPARGS_make, ~)
-
-#undef COMPHELPER_UNWRAPARGS_MAX_ARGS
-#undef COMPHELPER_UNWRAPARGS_make
-#undef COMPHELPER_UNWRAPARGS_args
-#undef COMPHELPER_UNWRAPARGS_extract
+template< typename... Args >
+inline void unwrapArgs(
+ const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& seq,
+ Args&... args )
+{
+ return detail::unwrapArgs( seq, 0, args... );
+}
} // namespace comphelper