From 914a00a13c8f3045282e27c8717ae0fd21ad740f Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 19 Dec 2013 16:34:54 +0100 Subject: Clean up macro madness Change-Id: I353a161fdc274a3da5ac965df12379c0d65681a4 --- UnoControls/source/base/registercontrols.cxx | 193 ++++++++++++--------------- 1 file changed, 86 insertions(+), 107 deletions(-) (limited to 'UnoControls') diff --git a/UnoControls/source/base/registercontrols.cxx b/UnoControls/source/base/registercontrols.cxx index 94df3e701ba1..e3ecfa490704 100644 --- a/UnoControls/source/base/registercontrols.cxx +++ b/UnoControls/source/base/registercontrols.cxx @@ -17,126 +17,105 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include -#include +#include + #include #include -#include -#include - -#include - -//============================================================================= -// Add new include line to use new services. -//============================================================================= -#include "framecontrol.hxx" -#include "progressbar.hxx" -#include "progressmonitor.hxx" -#include "statusindicator.hxx" -//============================================================================= - -//______________________________________________________________________________________________________________ -// namespaces -//______________________________________________________________________________________________________________ - -using namespace ::rtl ; -using namespace ::cppu ; -using namespace ::unocontrols ; -using namespace ::com::sun::star::uno ; -using namespace ::com::sun::star::container ; -using namespace ::com::sun::star::lang ; -using namespace ::com::sun::star::registry ; +#include +#include -//______________________________________________________________________________________________________________ -// macros -//______________________________________________________________________________________________________________ +#include +#include +#include +#include -//****************************************************************************************************************************** -#define CREATEINSTANCE(CLASS) \ - \ - static Reference< XInterface > SAL_CALL CLASS##_createInstance ( const Reference< XMultiServiceFactory >& rServiceManager ) throw ( Exception ) \ - { \ - return Reference< XInterface >( *(OWeakObject*)(new CLASS( comphelper::getComponentContext(rServiceManager) )) ); \ - } +namespace { -//****************************************************************************************************************************** -#define CREATEFACTORY_SINGLE(CLASS) \ - \ - /* Create right factory ... */ \ - xFactory = Reference< XSingleServiceFactory > \ - ( \ - cppu::createSingleFactory ( xServiceManager , \ - CLASS::impl_getStaticImplementationName () , \ - CLASS##_createInstance , \ - CLASS::impl_getStaticSupportedServiceNames () ) \ - ) ; \ +css::uno::Reference SAL_CALL FrameControl_createInstance( + css::uno::Reference const & + rServiceManager) + throw (css::uno::Exception) +{ + return static_cast( + new unocontrols::FrameControl( + comphelper::getComponentContext(rServiceManager))); +} -//****************************************************************************************************************************** -#define IF_NAME_CREATECOMPONENTFACTORY_SINGLE(CLASS) \ - \ - if ( CLASS::impl_getStaticImplementationName().equals( OUString::createFromAscii( pImplementationName ) ) ) \ - { \ - CREATEFACTORY_SINGLE ( CLASS ) \ - } +css::uno::Reference SAL_CALL ProgressBar_createInstance( + css::uno::Reference const & + rServiceManager) + throw (css::uno::Exception) +{ + return static_cast( + new unocontrols::ProgressBar( + comphelper::getComponentContext(rServiceManager))); +} -//______________________________________________________________________________________________________________ -// declare functions to create a new instance of service -//______________________________________________________________________________________________________________ +css::uno::Reference SAL_CALL +ProgressMonitor_createInstance( + css::uno::Reference const & + rServiceManager) + throw (css::uno::Exception) +{ + return static_cast( + new unocontrols::ProgressMonitor( + comphelper::getComponentContext(rServiceManager))); +} -//============================================================================= -// Add new macro line to use new services. -// -// !!! ATTENTION !!! -// Write no ";" at end of line! (see macro) -//============================================================================= -CREATEINSTANCE ( FrameControl ) -CREATEINSTANCE ( ProgressBar ) -CREATEINSTANCE ( ProgressMonitor ) -CREATEINSTANCE ( StatusIndicator ) -//============================================================================= +css::uno::Reference SAL_CALL +StatusIndicator_createInstance( + css::uno::Reference const & + rServiceManager) + throw (css::uno::Exception) +{ + return static_cast( + new unocontrols::StatusIndicator( + comphelper::getComponentContext(rServiceManager))); +} -//______________________________________________________________________________________________________________ -// create right component factory -//______________________________________________________________________________________________________________ +} -extern "C" SAL_DLLPUBLIC_EXPORT void* SAL_CALL ctl_component_getFactory( const sal_Char* pImplementationName, - void* pServiceManager , - void* /*pRegistryKey*/ ) +extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL ctl_component_getFactory( + char const * pImplName, void * pServiceManager, SAL_UNUSED_PARAMETER void *) { - // Set default return value for this operation - if it failed. - void* pReturn = NULL ; - - if ( - ( pImplementationName != NULL ) && - ( pServiceManager != NULL ) - ) + css::uno::Reference smgr( + static_cast(pServiceManager)); + css::uno::Reference fac; + if (unocontrols::FrameControl::impl_getStaticImplementationName() + .equalsAscii(pImplName)) { - // Define variables which are used in following macros. - Reference< XSingleServiceFactory > xFactory ; - Reference< XMultiServiceFactory > xServiceManager( reinterpret_cast< XMultiServiceFactory* >( pServiceManager ) ) ; - - //============================================================================= - // Add new macro line to handle new service. - // - // !!! ATTENTION !!! - // Write no ";" at end of line and dont forget "else" ! (see macro) - //============================================================================= - IF_NAME_CREATECOMPONENTFACTORY_SINGLE( FrameControl ) - else IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressBar ) - else IF_NAME_CREATECOMPONENTFACTORY_SINGLE( ProgressMonitor ) - else IF_NAME_CREATECOMPONENTFACTORY_SINGLE( StatusIndicator ) - //============================================================================= - - // Factory is valid - service was found. - if ( xFactory.is() ) - { - xFactory->acquire(); - pReturn = xFactory.get(); - } + fac = cppu::createSingleFactory( + smgr, unocontrols::FrameControl::impl_getStaticImplementationName(), + &FrameControl_createInstance, + unocontrols::FrameControl::impl_getStaticSupportedServiceNames()); + } else if (unocontrols::ProgressBar::impl_getStaticImplementationName() + .equalsAscii(pImplName)) + { + fac = cppu::createSingleFactory( + smgr, unocontrols::ProgressBar::impl_getStaticImplementationName(), + &ProgressBar_createInstance, + unocontrols::ProgressBar::impl_getStaticSupportedServiceNames()); + } else if (unocontrols::ProgressMonitor::impl_getStaticImplementationName() + .equalsAscii(pImplName)) + { + fac = cppu::createSingleFactory( + smgr, + unocontrols::ProgressMonitor::impl_getStaticImplementationName(), + &ProgressMonitor_createInstance, + unocontrols::ProgressMonitor::impl_getStaticSupportedServiceNames()); + } else if (unocontrols::StatusIndicator::impl_getStaticImplementationName() + .equalsAscii(pImplName)) + { + fac = cppu::createSingleFactory( + smgr, + unocontrols::StatusIndicator::impl_getStaticImplementationName(), + &StatusIndicator_createInstance, + unocontrols::StatusIndicator::impl_getStaticSupportedServiceNames()); } - - // Return with result of this operation. - return pReturn ; + if (fac.is()) { + fac->acquire(); + } + return fac.get(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3