diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2015-11-20 13:39:52 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2015-11-20 13:39:52 +0100 |
commit | b8793748b0eaaa3fe405587fcb2a3021adab833b (patch) | |
tree | 39b683691a8b8089831939a3a84ba1d62d614cb5 | |
parent | e3990370f832c8a69d1b6b22ec315dc0616d5535 (diff) |
Seems more natural to pass a homogenous list by initializer_list
...than by template parameter pack (even if that requires using ServiceDecl*, as
initializer_list cannot take reference types)
Change-Id: Ia986201b52d8daedfe925f132ebc79bc2c0ba378
20 files changed, 62 insertions, 118 deletions
diff --git a/canvas/source/cairo/cairo_services.cxx b/canvas/source/cairo/cairo_services.cxx index 2503531daf94..9cd28b11418e 100644 --- a/canvas/source/cairo/cairo_services.cxx +++ b/canvas/source/cairo/cairo_services.cxx @@ -40,6 +40,8 @@ using namespace ::com::sun::star; # error "The cairo canvas should not be enabled on Windows or Mac cf fdo#46901" #endif +namespace sdecl = comphelper::service_decl; + namespace cairocanvas { static uno::Reference<uno::XInterface> initCanvas( Canvas* pCanvas ) @@ -49,7 +51,6 @@ namespace cairocanvas return xRet; } - namespace sdecl = comphelper::service_decl; sdecl::class_< Canvas, sdecl::with_args<true> > serviceImpl1(&initCanvas); const sdecl::ServiceDecl cairoCanvasDecl( serviceImpl1, @@ -76,7 +77,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL cairocanvas_component_getFactory( sal_Char const* pImplName, void*, void* ) { - return component_getFactoryHelper( pImplName, cairocanvas::cairoCanvasDecl, cairocanvas::cairoSpriteCanvasDecl ); + return sdecl::component_getFactoryHelper( pImplName, {&cairocanvas::cairoCanvasDecl, &cairocanvas::cairoSpriteCanvasDecl} ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/source/opengl/ogl_spritecanvas.cxx b/canvas/source/opengl/ogl_spritecanvas.cxx index ed4d3144ee68..7e6bc04c7204 100644 --- a/canvas/source/opengl/ogl_spritecanvas.cxx +++ b/canvas/source/opengl/ogl_spritecanvas.cxx @@ -29,6 +29,8 @@ using namespace ::com::sun::star; +namespace sdecl = comphelper::service_decl; + namespace oglcanvas { SpriteCanvas::SpriteCanvas( const uno::Sequence< uno::Any >& aArguments, @@ -173,7 +175,6 @@ namespace oglcanvas return xRet; } - namespace sdecl = comphelper::service_decl; sdecl::class_<SpriteCanvas, sdecl::with_args<true> > serviceImpl(&initCanvas); const sdecl::ServiceDecl oglSpriteCanvasDecl( serviceImpl, @@ -186,7 +187,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL oglcanvas_component_getFactory( sal_Char const* pImplName, void*, void* ) { - return component_getFactoryHelper( pImplName, oglcanvas::oglSpriteCanvasDecl ); + return sdecl::component_getFactoryHelper( pImplName, {&oglcanvas::oglSpriteCanvasDecl} ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/source/simplecanvas/simplecanvasimpl.cxx b/canvas/source/simplecanvas/simplecanvasimpl.cxx index e6308a8accb4..6ff146b43b0c 100644 --- a/canvas/source/simplecanvas/simplecanvasimpl.cxx +++ b/canvas/source/simplecanvas/simplecanvasimpl.cxx @@ -381,7 +381,7 @@ namespace extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL simplecanvas_component_getFactory( sal_Char const* pImplName, void*, void* ) { - return component_getFactoryHelper( pImplName, simpleCanvasDecl ); + return sdecl::component_getFactoryHelper( pImplName, {&simpleCanvasDecl} ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/canvas/source/vcl/services.cxx b/canvas/source/vcl/services.cxx index 283b1a9b35ad..001160c90f48 100644 --- a/canvas/source/vcl/services.cxx +++ b/canvas/source/vcl/services.cxx @@ -41,10 +41,10 @@ using namespace ::com::sun::star; +namespace sdecl = comphelper::service_decl; + namespace vclcanvas { - namespace sdecl = comphelper::service_decl; - static uno::Reference<uno::XInterface> initCanvas( Canvas* pCanvas ) { uno::Reference<uno::XInterface> xRet(static_cast<cppu::OWeakObject*>(pCanvas)); @@ -77,7 +77,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL vclcanvas_component_getFactory( sal_Char const* pImplName, void*, void* ) { - return component_getFactoryHelper( pImplName, vclcanvas::vclCanvasDecl, vclcanvas::vclSpriteCanvasDecl ); + return sdecl::component_getFactoryHelper( pImplName, {&vclcanvas::vclCanvasDecl, &vclcanvas::vclSpriteCanvasDecl} ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/qa/unit/variadictemplates.cxx b/comphelper/qa/unit/variadictemplates.cxx index 78f3bd7c3a42..4b45f1767606 100644 --- a/comphelper/qa/unit/variadictemplates.cxx +++ b/comphelper/qa/unit/variadictemplates.cxx @@ -10,7 +10,6 @@ #include <boost/optional.hpp> #include <sal/types.h> #include <comphelper/unwrapargs.hxx> -#include <comphelper/servicedecl.hxx> #include "cppunit/TestAssert.h" #include "cppunit/TestFixture.h" #include "cppunit/extensions/HelperMacros.h" @@ -22,11 +21,9 @@ class VariadicTemplatesTest : public CppUnit::TestFixture { public: void testUnwrapArgs(); - void testServiceDecl(); CPPUNIT_TEST_SUITE(VariadicTemplatesTest); CPPUNIT_TEST(testUnwrapArgs); - CPPUNIT_TEST(testServiceDecl); CPPUNIT_TEST_SUITE_END(); }; @@ -90,19 +87,6 @@ inline void unwrapArgsBaseline( ::detail::extract( seq, 4, v4, xErrorContext ); } -struct DummyStruct { - sal_uInt32 m_x; - - DummyStruct( sal_uInt32 x ): m_x( x ) { } - DummyStruct() : m_x( 0 ) { } - - void* getFactory( const char* ) const { - if( m_x == 42 ) - return new int( m_x ); - return nullptr; - } -}; - } void VariadicTemplatesTest::testUnwrapArgs() { @@ -193,40 +177,6 @@ void VariadicTemplatesTest::testUnwrapArgs() { } } -void VariadicTemplatesTest::testServiceDecl() { - DummyStruct dummy1( 42 ); - DummyStruct dummy2; - DummyStruct dummy3; - void* pRet = ::comphelper::service_decl::component_getFactoryHelper( "test", - dummy3, - dummy2, - dummy1 ); - - CPPUNIT_ASSERT_MESSAGE( "pRet != 0", - pRet != nullptr ); - - sal_uInt32* pnRet = static_cast< sal_uInt32* >( pRet ); - - CPPUNIT_ASSERT_MESSAGE( "*pnRet == 42", - *pnRet == 42 ); - delete pnRet; - - pRet = ::comphelper::service_decl::component_getFactoryHelper( "test", - dummy1, - dummy2, - dummy2 ); - - CPPUNIT_ASSERT_MESSAGE( "pRet != nullptr", - pRet != nullptr ); - - pnRet = static_cast< sal_uInt32* >( pRet ); - - CPPUNIT_ASSERT_MESSAGE( "*pnRet == 42", - *pnRet == 42 ); - - delete pnRet; -} - CPPUNIT_TEST_SUITE_REGISTRATION(VariadicTemplatesTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/comphelper/source/misc/servicedecl.cxx b/comphelper/source/misc/servicedecl.cxx index a7194ccf18fe..78bd811e0cdc 100644 --- a/comphelper/source/misc/servicedecl.cxx +++ b/comphelper/source/misc/servicedecl.cxx @@ -25,6 +25,7 @@ #include <cppuhelper/implbase.hxx> #include <comphelper/sequence.hxx> #include <com/sun/star/lang/XSingleComponentFactory.hpp> +#include <cassert> #include <vector> #include <boost/noncopyable.hpp> @@ -151,6 +152,19 @@ OUString ServiceDecl::getImplementationName() const return OUString::createFromAscii(m_pImplName); } +void* component_getFactoryHelper( const sal_Char* pImplName, + std::initializer_list<ServiceDecl const *> args ) +{ + for (auto const i: args) { + assert(i != nullptr); + void * fac = i->getFactory(pImplName); + if (fac != nullptr) { + return fac; + } + } + return nullptr; +} + } // namespace service_decl } // namespace comphelper diff --git a/cppcanvas/source/uno/uno_mtfrenderer.cxx b/cppcanvas/source/uno/uno_mtfrenderer.cxx index 576a22f4f612..6d2c311510c0 100644 --- a/cppcanvas/source/uno/uno_mtfrenderer.cxx +++ b/cppcanvas/source/uno/uno_mtfrenderer.cxx @@ -56,7 +56,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL mtfrenderer_component_getFactory( sal_Char const* pImplName, void*, void* ) { - return component_getFactoryHelper( pImplName, MtfRendererDecl ); + return sdecl::component_getFactoryHelper( pImplName, {&MtfRendererDecl} ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/desktop/source/deployment/dp_services.cxx b/desktop/source/deployment/dp_services.cxx index 82b633b61206..b20a2667f146 100644 --- a/desktop/source/deployment/dp_services.cxx +++ b/desktop/source/deployment/dp_services.cxx @@ -73,18 +73,18 @@ extern "C" { SAL_DLLPUBLIC_EXPORT void * SAL_CALL deployment_component_getFactory( sal_Char const * pImplName, void *, void *) { - return component_getFactoryHelper( + return sdecl::component_getFactoryHelper( pImplName, - dp_registry::backend::configuration::serviceDecl, - dp_registry::backend::component::serviceDecl, - dp_registry::backend::help::serviceDecl, - dp_registry::backend::script::serviceDecl, - dp_registry::backend::sfwk::serviceDecl, - dp_registry::backend::executable::serviceDecl, - dp_manager::factory::serviceDecl, - dp_log::serviceDecl, - dp_info::serviceDecl, - dp_manager::serviceDecl); + {&dp_registry::backend::configuration::serviceDecl, + &dp_registry::backend::component::serviceDecl, + &dp_registry::backend::help::serviceDecl, + &dp_registry::backend::script::serviceDecl, + &dp_registry::backend::sfwk::serviceDecl, + &dp_registry::backend::executable::serviceDecl, + &dp_manager::factory::serviceDecl, + &dp_log::serviceDecl, + &dp_info::serviceDecl, + &dp_manager::serviceDecl}); } } // extern "C" diff --git a/desktop/source/deployment/gui/dp_gui_service.cxx b/desktop/source/deployment/gui/dp_gui_service.cxx index e60e0017def1..60686a6d9060 100644 --- a/desktop/source/deployment/gui/dp_gui_service.cxx +++ b/desktop/source/deployment/gui/dp_gui_service.cxx @@ -45,6 +45,7 @@ using namespace ::dp_misc; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; +namespace sdecl = comphelper::service_decl; namespace dp_gui { @@ -303,7 +304,6 @@ void ServiceImpl::trigger( OUString const &rEvent ) throw (RuntimeException, std startExecuteModal( Reference< ui::dialogs::XDialogClosedListener >() ); } -namespace sdecl = comphelper::service_decl; sdecl::class_<ServiceImpl, sdecl::with_args<true> > serviceSI; sdecl::ServiceDecl const serviceDecl( serviceSI, @@ -328,8 +328,9 @@ extern "C" { SAL_DLLPUBLIC_EXPORT void * SAL_CALL deploymentgui_component_getFactory( sal_Char const * pImplName, void *, void *) { - return component_getFactoryHelper( - pImplName, dp_gui::serviceDecl, dp_gui::licenseDecl, dp_gui::updateDecl ); + return sdecl::component_getFactoryHelper( + pImplName, + {&dp_gui::serviceDecl, &dp_gui::licenseDecl, &dp_gui::updateDecl}); } } // extern "C" diff --git a/extensions/source/resource/resourceservices.cxx b/extensions/source/resource/resourceservices.cxx index 3a8206dc08c1..fea575e0ad3c 100644 --- a/extensions/source/resource/resourceservices.cxx +++ b/extensions/source/resource/resourceservices.cxx @@ -32,8 +32,8 @@ const sdecl::ServiceDecl OpenOfficeResourceLoaderDecl( extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL res_component_getFactory( sal_Char const* pImplName, void*, void*) { - return component_getFactoryHelper( pImplName, - ResourceIndexAccessDecl, OpenOfficeResourceLoaderDecl ); + return sdecl::component_getFactoryHelper( pImplName, + {&ResourceIndexAccessDecl, &OpenOfficeResourceLoaderDecl} ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/filter/source/graphic/Services.cxx b/filter/source/graphic/Services.cxx index c8073888c58f..13d0969168b6 100644 --- a/filter/source/graphic/Services.cxx +++ b/filter/source/graphic/Services.cxx @@ -42,11 +42,11 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL graphicfilter_component_getFactor { if ( rtl_str_compare (pImplementationName, GRAPHIC_EXPORT_FILTER_SERVICE) == 0 ) { - return component_getFactoryHelper( pImplementationName, graphicExportFilter ); + return comphelper::service_decl::component_getFactoryHelper( pImplementationName, {&graphicExportFilter} ); } else if ( rtl_str_compare (pImplementationName, GRAPHIC_EXPORT_DIALOG_SERVICE) == 0 ) { - return component_getFactoryHelper( pImplementationName, graphicExportDialog ); + return comphelper::service_decl::component_getFactoryHelper( pImplementationName, {&graphicExportDialog} ); } return nullptr; } diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx index 16595cf93140..9303b8fcd657 100644 --- a/filter/source/svg/svgfilter.cxx +++ b/filter/source/svg/svgfilter.cxx @@ -413,11 +413,11 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL svgfilter_component_getFactory( { if ( rtl_str_compare (pImplName, SVG_FILTER_IMPL_NAME) == 0 ) { - return component_getFactoryHelper( pImplName, svgFilter ); + return sdecl::component_getFactoryHelper( pImplName, {&svgFilter} ); } else if ( rtl_str_compare (pImplName, SVG_WRITER_IMPL_NAME) == 0 ) { - return component_getFactoryHelper( pImplName, svgWriter ); + return sdecl::component_getFactoryHelper( pImplName, {&svgWriter} ); } return nullptr; } diff --git a/include/comphelper/servicedecl.hxx b/include/comphelper/servicedecl.hxx index 4447364d005a..077d38e714f4 100644 --- a/include/comphelper/servicedecl.hxx +++ b/include/comphelper/servicedecl.hxx @@ -26,6 +26,7 @@ #include <uno/environment.h> #include <functional> +#include <initializer_list> namespace comphelper { namespace service_decl { @@ -332,33 +333,9 @@ struct inheritingClass_ : public serviceimpl_base< detail::InheritingServiceImpl explicit inheritingClass_( PostProcessFuncT const& postProcessFunc ) : baseT( postProcessFunc ) {} }; -// component_... helpers with arbitrary service declarations: - -template< typename T > -inline void* component_getFactoryHelper( const sal_Char* pImplName, void* pRet, - const T& s ) -{ - if( pRet == nullptr ) - return s.getFactory( pImplName ); - return pRet; -} - -template< typename T, typename... Args > -inline void* component_getFactoryHelper( const sal_Char* pImplName, void* pRet, - const T& s, const Args&... args ) -{ - if( pRet == nullptr ) - return component_getFactoryHelper( pImplName, s.getFactory( pImplName ), args... ); - return pRet; -} - -template< typename... Args > -inline void* component_getFactoryHelper( const sal_Char* pImplName, - const Args&... args ) -{ - void* pRet = nullptr; - return component_getFactoryHelper( pImplName, pRet, args... ); -} +COMPHELPER_DLLPUBLIC +void* component_getFactoryHelper( const sal_Char* pImplName, + std::initializer_list<ServiceDecl const *> args ); } // namespace service_decl } // namespace comphelper diff --git a/sc/source/ui/vba/service.cxx b/sc/source/ui/vba/service.cxx index cbe2e2511c9f..9c52d0915e94 100644 --- a/sc/source/ui/vba/service.cxx +++ b/sc/source/ui/vba/service.cxx @@ -57,8 +57,8 @@ extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL vbaobj_component_getFactory( const sal_Char * pImplName, void *, void *) { - void* pRet = component_getFactoryHelper( - pImplName, range::serviceDecl, workbook::serviceDecl, worksheet::serviceDecl, window::serviceDecl, hyperlink::serviceDecl, application::serviceDecl ); + void* pRet = sdecl::component_getFactoryHelper( + pImplName, {&range::serviceDecl, &workbook::serviceDecl, &worksheet::serviceDecl, &window::serviceDecl, &hyperlink::serviceDecl, &application::serviceDecl} ); return pRet; } } diff --git a/shell/source/sessioninstall/services.cxx b/shell/source/sessioninstall/services.cxx index bc27deb7bf84..e625151efcaf 100644 --- a/shell/source/sessioninstall/services.cxx +++ b/shell/source/sessioninstall/services.cxx @@ -24,7 +24,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL losessioninstall_component_getFactory( sal_Char const* pImplName, void*, void* ) { - return component_getFactoryHelper( pImplName, SyncDbusSessionHelperServiceDecl ); + return sdecl::component_getFactoryHelper( pImplName, {&SyncDbusSessionHelperServiceDecl} ); } extern "C" diff --git a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx index 4244d9c0b1ca..653577d5e76e 100644 --- a/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx +++ b/slideshow/source/engine/OGLTrans/generic/OGLTrans_TransitionerImpl.cxx @@ -1569,7 +1569,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL ogltrans_component_getFactory( sal_Char const* pImplName, void*, void* ) { - return component_getFactoryHelper( pImplName, OGLTransitionFactoryDecl ); + return sdecl::component_getFactoryHelper( pImplName, {&OGLTransitionFactoryDecl} ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/slideshow/source/engine/slideshowimpl.cxx b/slideshow/source/engine/slideshowimpl.cxx index 943c5400d17c..df655d8760d7 100644 --- a/slideshow/source/engine/slideshowimpl.cxx +++ b/slideshow/source/engine/slideshowimpl.cxx @@ -2422,7 +2422,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL slideshow_component_getFactory( sal_Char const* pImplName, void*, void* ) { - return component_getFactoryHelper( pImplName, slideShowDecl ); + return sdecl::component_getFactoryHelper( pImplName, {&slideShowDecl} ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/vba/service.cxx b/sw/source/ui/vba/service.cxx index a23f1a77e388..d39ab2bf2749 100644 --- a/sw/source/ui/vba/service.cxx +++ b/sw/source/ui/vba/service.cxx @@ -52,9 +52,9 @@ extern sdecl::ServiceDecl const serviceDecl; extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL vbaswobj_component_getFactory( const sal_Char * pImplName, void *, void *) { - void* pRet = component_getFactoryHelper(pImplName, - globals::serviceDecl, ::document::serviceDecl, - wrapformat::serviceDecl, vbaeventshelper::serviceDecl ); + void* pRet = sdecl::component_getFactoryHelper(pImplName, + {&globals::serviceDecl, &::document::serviceDecl, + &wrapformat::serviceDecl, &vbaeventshelper::serviceDecl} ); OSL_TRACE("Ret is 0x%p", pRet); return pRet; } diff --git a/unotools/source/misc/unotoolsservices.cxx b/unotools/source/misc/unotoolsservices.cxx index 2455ed065932..e7e62e681eb0 100644 --- a/unotools/source/misc/unotoolsservices.cxx +++ b/unotools/source/misc/unotoolsservices.cxx @@ -20,8 +20,8 @@ extern sdecl::ServiceDecl const ServiceDocumenterDecl; extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL utl_component_getFactory( sal_Char const* pImplName, void*, void*) { - return component_getFactoryHelper( pImplName, - OTempFileServiceDecl, ServiceDocumenterDecl); + return sdecl::component_getFactoryHelper( pImplName, + {&OTempFileServiceDecl, &ServiceDocumenterDecl}); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vbahelper/source/msforms/service.cxx b/vbahelper/source/msforms/service.cxx index 7320f16523dc..12c6f9b4ad91 100644 --- a/vbahelper/source/msforms/service.cxx +++ b/vbahelper/source/msforms/service.cxx @@ -44,8 +44,8 @@ extern "C" const sal_Char * pImplName, void *, void *) { SAL_INFO("vbahelper", "In component_getFactory for " << pImplName ); - void* pRet = component_getFactoryHelper( - pImplName, controlprovider::serviceDecl, userform::serviceDecl ); + void* pRet = sdecl::component_getFactoryHelper( + pImplName, {&controlprovider::serviceDecl, &userform::serviceDecl} ); SAL_INFO("vbahelper", "Ret is 0x" << std::hex << pRet); return pRet; } |