Kaydet (Commit) b8793748 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

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
üst e3990370
......@@ -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: */
......@@ -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: */
......@@ -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: */
......@@ -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: */
......@@ -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();
......
......@@ -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
......
......@@ -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: */
......@@ -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"
......
......@@ -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"
......
......@@ -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: */
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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
......
......@@ -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;
}
}
......
......@@ -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"
......
......@@ -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: */
......@@ -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: */
......@@ -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;
}
......
......@@ -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: */
......@@ -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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment