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 /comphelper | |
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
Diffstat (limited to 'comphelper')
-rw-r--r-- | comphelper/qa/unit/variadictemplates.cxx | 50 | ||||
-rw-r--r-- | comphelper/source/misc/servicedecl.cxx | 14 |
2 files changed, 14 insertions, 50 deletions
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 |