From d32dfd9e955cdc893aa21ab8e870d217d1628ad3 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 28 May 2021 14:43:02 +0200 Subject: std::unique->std::optional rather than having a pointer to a pointer (which is what Sequence is) Change-Id: Ieb7b9995f6a25022fe2401adc3c38124edb83506 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116376 Tested-by: Jenkins Reviewed-by: Noel Grandin --- stoc/source/corereflection/base.hxx | 6 ++-- stoc/source/corereflection/crcomp.cxx | 13 ++++---- stoc/source/corereflection/crenum.cxx | 15 +++++----- stoc/source/corereflection/criface.cxx | 55 ++++++++++++++++------------------ 4 files changed, 42 insertions(+), 47 deletions(-) (limited to 'stoc') diff --git a/stoc/source/corereflection/base.hxx b/stoc/source/corereflection/base.hxx index e322f87aa62e..16d42213ddcd 100644 --- a/stoc/source/corereflection/base.hxx +++ b/stoc/source/corereflection/base.hxx @@ -231,8 +231,8 @@ class CompoundIdlClassImpl { css::uno::Reference< css::reflection::XIdlClass > _xSuperClass; - std::unique_ptr< css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > > - _pFields; + std::optional< css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > > + m_xFields; OUString2Field _aName2Field; public: @@ -294,7 +294,7 @@ public: class EnumIdlClassImpl : public IdlClassImpl { - std::unique_ptr< css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > > _pFields; + std::optional< css::uno::Sequence< css::uno::Reference< css::reflection::XIdlField > > > m_xFields; OUString2Field _aName2Field; public: diff --git a/stoc/source/corereflection/crcomp.cxx b/stoc/source/corereflection/crcomp.cxx index ae15991ad017..51cf4a6f02e4 100644 --- a/stoc/source/corereflection/crcomp.cxx +++ b/stoc/source/corereflection/crcomp.cxx @@ -302,7 +302,7 @@ Sequence< Reference< XIdlClass > > CompoundIdlClassImpl::getSuperclasses() Reference< XIdlField > CompoundIdlClassImpl::getField( const OUString & rName ) { - if (! _pFields) + if (! m_xFields) getFields(); // init fields const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) ); @@ -315,16 +315,15 @@ Reference< XIdlField > CompoundIdlClassImpl::getField( const OUString & rName ) Sequence< Reference< XIdlField > > CompoundIdlClassImpl::getFields() { ::osl::MutexGuard aGuard( getMutexAccess() ); - if (! _pFields) + if (! m_xFields) { sal_Int32 nAll = 0; typelib_CompoundTypeDescription * pCompTypeDescr = getTypeDescr(); for ( ; pCompTypeDescr; pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription ) nAll += pCompTypeDescr->nMembers; - Sequence< Reference< XIdlField > > * pFields = - new Sequence< Reference< XIdlField > >( nAll ); - Reference< XIdlField > * pSeq = pFields->getArray(); + Sequence< Reference< XIdlField > > aFields( nAll ); + Reference< XIdlField > * pSeq = aFields.getArray(); for ( pCompTypeDescr = getTypeDescr(); pCompTypeDescr; pCompTypeDescr = pCompTypeDescr->pBaseTypeDescription ) @@ -348,9 +347,9 @@ Sequence< Reference< XIdlField > > CompoundIdlClassImpl::getFields() } } - _pFields.reset( pFields ); + m_xFields = std::move( aFields ); } - return *_pFields; + return *m_xFields; } } diff --git a/stoc/source/corereflection/crenum.cxx b/stoc/source/corereflection/crenum.cxx index ea441fc975fd..dae3449d3b2c 100644 --- a/stoc/source/corereflection/crenum.cxx +++ b/stoc/source/corereflection/crenum.cxx @@ -159,7 +159,7 @@ EnumIdlClassImpl::~EnumIdlClassImpl() Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName ) { - if (! _pFields) + if (! m_xFields) getFields(); // init members const OUString2Field::const_iterator iFind( _aName2Field.find( rName ) ); @@ -171,15 +171,14 @@ Reference< XIdlField > EnumIdlClassImpl::getField( const OUString & rName ) Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields() { - if (! _pFields) + if (! m_xFields) { ::osl::MutexGuard aGuard( getMutexAccess() ); - if (! _pFields) + if (! m_xFields) { sal_Int32 nFields = getTypeDescr()->nEnumValues; - Sequence< Reference< XIdlField > > * pFields = - new Sequence< Reference< XIdlField > >( nFields ); - Reference< XIdlField > * pSeq = pFields->getArray(); + Sequence< Reference< XIdlField > > aFields( nFields ); + Reference< XIdlField > * pSeq = aFields.getArray(); while (nFields--) { @@ -188,10 +187,10 @@ Sequence< Reference< XIdlField > > EnumIdlClassImpl::getFields() getReflection(), aName, IdlClassImpl::getTypeDescr(), getTypeDescr()->pEnumValues[nFields] ); } - _pFields.reset( pFields ); + m_xFields = std::move( aFields ); } } - return *_pFields; + return *m_xFields; } void EnumIdlClassImpl::createObject( Any & rObj ) diff --git a/stoc/source/corereflection/criface.cxx b/stoc/source/corereflection/criface.cxx index 07aca5fdb438..de8f9380a2f7 100644 --- a/stoc/source/corereflection/criface.cxx +++ b/stoc/source/corereflection/criface.cxx @@ -322,9 +322,9 @@ class IdlInterfaceMethodImpl : public IdlMemberImpl , public XIdlMethod { - std::unique_ptr >> _pExceptionTypes; - std::unique_ptr >> _pParamTypes; - std::unique_ptr> _pParamInfos; + std::optional >> m_xExceptionTypes; + std::optional >> m_xParamTypes; + std::optional> m_xParamInfos; public: typelib_InterfaceMethodTypeDescription * getMethodTypeDescr() const @@ -424,15 +424,14 @@ Reference< XIdlClass > SAL_CALL IdlInterfaceMethodImpl::getReturnType() Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes() { - if (! _pExceptionTypes) + if (! m_xExceptionTypes) { ::osl::MutexGuard aGuard( getMutexAccess() ); - if (! _pExceptionTypes) + if (! m_xExceptionTypes) { sal_Int32 nExc = getMethodTypeDescr()->nExceptions; - std::unique_ptr >> pTempExceptionTypes( - new Sequence< Reference< XIdlClass > >( nExc )); - Reference< XIdlClass > * pExceptionTypes = pTempExceptionTypes->getArray(); + Sequence< Reference< XIdlClass > > aTempExceptionTypes( nExc ); + Reference< XIdlClass > * pExceptionTypes = aTempExceptionTypes.getArray(); typelib_TypeDescriptionReference ** ppExc = getMethodTypeDescr()->ppExceptions; @@ -441,23 +440,22 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getExceptionTypes() while (nExc--) pExceptionTypes[nExc] = pRefl->forType( ppExc[nExc] ); - _pExceptionTypes = std::move(pTempExceptionTypes); + m_xExceptionTypes = std::move(aTempExceptionTypes); } } - return *_pExceptionTypes; + return *m_xExceptionTypes; } Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes() { - if (! _pParamTypes) + if (! m_xParamTypes) { ::osl::MutexGuard aGuard( getMutexAccess() ); - if (! _pParamTypes) + if (! m_xParamTypes) { sal_Int32 nParams = getMethodTypeDescr()->nParams; - std::unique_ptr > > pTempParamTypes( - new Sequence< Reference< XIdlClass > >( nParams )); - Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray(); + Sequence< Reference< XIdlClass > > aTempParamTypes( nParams ); + Reference< XIdlClass > * pParamTypes = aTempParamTypes.getArray(); typelib_MethodParameter * pTypelibParams = getMethodTypeDescr()->pParams; @@ -466,29 +464,29 @@ Sequence< Reference< XIdlClass > > IdlInterfaceMethodImpl::getParameterTypes() while (nParams--) pParamTypes[nParams] = pRefl->forType( pTypelibParams[nParams].pTypeRef ); - _pParamTypes = std::move(pTempParamTypes); + m_xParamTypes = std::move(aTempParamTypes); } } - return *_pParamTypes; + return *m_xParamTypes; } Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos() { - if (! _pParamInfos) + if (! m_xParamInfos) { ::osl::MutexGuard aGuard( getMutexAccess() ); - if (! _pParamInfos) + if (! m_xParamInfos) { sal_Int32 nParams = getMethodTypeDescr()->nParams; - std::unique_ptr > pTempParamInfos( new Sequence< ParamInfo >( nParams ) ); - ParamInfo * pParamInfos = pTempParamInfos->getArray(); + Sequence< ParamInfo > aTempParamInfos( nParams ); + ParamInfo * pParamInfos = aTempParamInfos.getArray(); typelib_MethodParameter * pTypelibParams = getMethodTypeDescr()->pParams; - if (_pParamTypes) // use param types + if (m_xParamTypes) // use param types { - const Reference< XIdlClass > * pParamTypes = _pParamTypes->getConstArray(); + const Reference< XIdlClass > * pParamTypes = m_xParamTypes->getConstArray(); while (nParams--) { @@ -504,9 +502,8 @@ Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos() } else // make also param types sequence if not already initialized { - std::unique_ptr > > pTempParamTypes( - new Sequence< Reference< XIdlClass > >( nParams )); - Reference< XIdlClass > * pParamTypes = pTempParamTypes->getArray(); + Sequence< Reference< XIdlClass > > aTempParamTypes( nParams ); + Reference< XIdlClass > * pParamTypes = aTempParamTypes.getArray(); IdlReflectionServiceImpl * pRefl = getReflection(); @@ -522,13 +519,13 @@ Sequence< ParamInfo > IdlInterfaceMethodImpl::getParameterInfos() rInfo.aType = pParamTypes[nParams] = pRefl->forType( rParam.pTypeRef ); } - _pParamTypes = std::move(pTempParamTypes); + m_xParamTypes = std::move(aTempParamTypes); } - _pParamInfos = std::move(pTempParamInfos); + m_xParamInfos = std::move(aTempParamInfos); } } - return *_pParamInfos; + return *m_xParamInfos; } MethodMode SAL_CALL IdlInterfaceMethodImpl::getMode() -- cgit v1.2.3