From 9d8bac40899b656ca5173fec880102f54e996382 Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Sun, 30 Jun 2019 19:22:37 +0300 Subject: Drop GETVALUE_IMPL/SETVALUE_IMPL macros Replace with PropertyValueSet getValue/appendValue templates Change-Id: I5714e6c4e6daf5ba6a4a9f9b363de3a1541834da Reviewed-on: https://gerrit.libreoffice.org/74930 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- include/ucbhelper/propertyvalueset.hxx | 9 + ucbhelper/source/provider/propertyvalueset.cxx | 241 ++++++++++++------------- 2 files changed, 129 insertions(+), 121 deletions(-) diff --git a/include/ucbhelper/propertyvalueset.hxx b/include/ucbhelper/propertyvalueset.hxx index a0ecaf0df86d..97ee7c6ec889 100644 --- a/include/ucbhelper/propertyvalueset.hxx +++ b/include/ucbhelper/propertyvalueset.hxx @@ -40,6 +40,9 @@ namespace com { namespace sun { namespace star { namespace beans { namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } } +enum class PropsSet; +namespace ucbhelper_impl { struct PropertyValue; } + namespace ucbhelper { class PropertyValues; @@ -69,6 +72,12 @@ private: UCBHELPER_DLLPRIVATE const css::uno::Reference< css::script::XTypeConverter >& getTypeConverter(); + template + T getValue(PropsSet nTypeName, sal_Int32 columnIndex); + + template + void appendValue(const OUString& rPropName, PropsSet nTypeName, const T& rValue); + public: PropertyValueSet( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); diff --git a/ucbhelper/source/provider/propertyvalueset.cxx b/ucbhelper/source/provider/propertyvalueset.cxx index d1adaad4e6f2..486ac962aa34 100644 --- a/ucbhelper/source/provider/propertyvalueset.cxx +++ b/ucbhelper/source/provider/propertyvalueset.cxx @@ -130,101 +130,6 @@ class PropertyValues : public std::vector< ucbhelper_impl::PropertyValue > {}; } // namespace ucbhelper -// Welcome to the macro hell... - - -#define GETVALUE_IMPL( _type_, _type_name_, _member_name_ ) \ - \ - osl::MutexGuard aGuard( m_aMutex ); \ - \ - _type_ aValue {}; /* default ctor */ \ - \ - m_bWasNull = true; \ - \ - if ( ( columnIndex < 1 ) \ - || ( columnIndex > sal_Int32( m_pValues->size() ) ) ) \ - { \ - OSL_FAIL( "PropertyValueSet - index out of range!" ); \ - return aValue; \ - } \ - ucbhelper_impl::PropertyValue& rValue \ - = (*m_pValues)[ columnIndex - 1 ]; \ - \ - if ( rValue.nOrigValue == PropsSet::NONE ) \ - return aValue; \ - \ - if ( rValue.nPropsSet & _type_name_ ) \ - { \ - /* Values is present natively... */ \ - aValue = rValue._member_name_; \ - m_bWasNull = false; \ - return aValue; \ - } \ - \ - if ( !(rValue.nPropsSet & PropsSet::Object) ) \ - { \ - /* Value is not (yet) available as Any. Create it. */ \ - getObject( columnIndex, Reference< XNameAccess >() ); \ - } \ - \ - if ( rValue.nPropsSet & PropsSet::Object ) \ - { \ - /* Value is available as Any. */ \ - \ - if ( rValue.aObject.hasValue() ) \ - { \ - /* Try to convert into native value. */ \ - if ( rValue.aObject >>= aValue ) \ - { \ - rValue._member_name_ = aValue; \ - rValue.nPropsSet |= _type_name_; \ - m_bWasNull = false; \ - } \ - else \ - { \ - /* Last chance. Try type converter service... */ \ - \ - Reference< XTypeConverter > xConverter \ - = getTypeConverter(); \ - if ( xConverter.is() ) \ - { \ - try \ - { \ - Any aConvAny = xConverter->convertTo( \ - rValue.aObject, \ - cppu::UnoType<_type_>::get() ); \ - \ - if ( aConvAny >>= aValue ) \ - { \ - rValue._member_name_ = aValue; \ - rValue.nPropsSet |= _type_name_; \ - m_bWasNull = false; \ - } \ - } \ - catch (const IllegalArgumentException&) \ - { \ - } \ - catch (const CannotConvertException&) \ - { \ - } \ - } \ - } \ - } \ - } \ - return aValue; - -#define SETVALUE_IMPL( _prop_name_, _type_name_, _member_name_, _value_ ) \ - \ - osl::MutexGuard aGuard( m_aMutex ); \ - \ - ucbhelper_impl::PropertyValue aNewValue; \ - aNewValue.sPropertyName = _prop_name_; \ - aNewValue.nPropsSet = _type_name_; \ - aNewValue.nOrigValue = _type_name_; \ - aNewValue._member_name_ = _value_; \ - \ - m_pValues->push_back( aNewValue ); - namespace ucbhelper { @@ -283,6 +188,87 @@ XTYPEPROVIDER_IMPL_3( PropertyValueSet, // XRow methods. +template +T PropertyValueSet::getValue(PropsSet nTypeName, sal_Int32 columnIndex) +{ + osl::MutexGuard aGuard( m_aMutex ); + + T aValue {}; /* default ctor */ + + m_bWasNull = true; + + if ( ( columnIndex < 1 ) || ( columnIndex > sal_Int32( m_pValues->size() ) ) ) + { + OSL_FAIL( "PropertyValueSet - index out of range!" ); + return aValue; + } + ucbhelper_impl::PropertyValue& rValue = (*m_pValues)[ columnIndex - 1 ]; + + if ( rValue.nOrigValue == PropsSet::NONE ) + return aValue; + + if ( rValue.nPropsSet & nTypeName ) + { + /* Values is present natively... */ + aValue = rValue.*_member_name_; + m_bWasNull = false; + return aValue; + } + + if ( !(rValue.nPropsSet & PropsSet::Object) ) + { + /* Value is not (yet) available as Any. Create it. */ + getObject( columnIndex, Reference< XNameAccess >() ); + } + + if ( rValue.nPropsSet & PropsSet::Object ) + { + /* Value is available as Any. */ + + if ( rValue.aObject.hasValue() ) + { + /* Try to convert into native value. */ + if ( rValue.aObject >>= aValue ) + { + rValue.*_member_name_ = aValue; + rValue.nPropsSet |= nTypeName; + m_bWasNull = false; + } + else + { + /* Last chance. Try type converter service... */ + + Reference< XTypeConverter > xConverter = getTypeConverter(); + if ( xConverter.is() ) + { + try + { + Any aConvAny = xConverter->convertTo( + rValue.aObject, + cppu::UnoType::get() ); + + if ( aConvAny >>= aValue ) + { + rValue.*_member_name_ = aValue; + rValue.nPropsSet |= nTypeName; + m_bWasNull = false; + } + } + catch (const IllegalArgumentException&) + { + } + catch (const CannotConvertException&) + { + } + } + } + } + } + + return aValue; +} + + // virtual sal_Bool SAL_CALL PropertyValueSet::wasNull() { @@ -296,56 +282,56 @@ sal_Bool SAL_CALL PropertyValueSet::wasNull() // virtual OUString SAL_CALL PropertyValueSet::getString( sal_Int32 columnIndex ) { - GETVALUE_IMPL( OUString, PropsSet::String, aString ); + return getValue(PropsSet::String, columnIndex); } // virtual sal_Bool SAL_CALL PropertyValueSet::getBoolean( sal_Int32 columnIndex ) { - GETVALUE_IMPL( bool, PropsSet::Boolean, bBoolean ); + return getValue(PropsSet::Boolean, columnIndex); } // virtual sal_Int8 SAL_CALL PropertyValueSet::getByte( sal_Int32 columnIndex ) { - GETVALUE_IMPL( sal_Int8, PropsSet::Byte, nByte ); + return getValue(PropsSet::Byte, columnIndex); } // virtual sal_Int16 SAL_CALL PropertyValueSet::getShort( sal_Int32 columnIndex ) { - GETVALUE_IMPL( sal_Int16, PropsSet::Short, nShort ); + return getValue(PropsSet::Short, columnIndex); } // virtual sal_Int32 SAL_CALL PropertyValueSet::getInt( sal_Int32 columnIndex ) { - GETVALUE_IMPL( sal_Int32, PropsSet::Int, nInt ); + return getValue(PropsSet::Int, columnIndex); } // virtual sal_Int64 SAL_CALL PropertyValueSet::getLong( sal_Int32 columnIndex ) { - GETVALUE_IMPL( sal_Int64, PropsSet::Long, nLong ); + return getValue(PropsSet::Long, columnIndex); } // virtual float SAL_CALL PropertyValueSet::getFloat( sal_Int32 columnIndex ) { - GETVALUE_IMPL( float, PropsSet::Float, nFloat ); + return getValue(PropsSet::Float, columnIndex); } // virtual double SAL_CALL PropertyValueSet::getDouble( sal_Int32 columnIndex ) { - GETVALUE_IMPL( double, PropsSet::Double, nDouble ); + return getValue(PropsSet::Double, columnIndex); } @@ -353,28 +339,28 @@ double SAL_CALL PropertyValueSet::getDouble( sal_Int32 columnIndex ) Sequence< sal_Int8 > SAL_CALL PropertyValueSet::getBytes( sal_Int32 columnIndex ) { - GETVALUE_IMPL( Sequence< sal_Int8 >, PropsSet::Bytes, aBytes ); + return getValue, &ucbhelper_impl::PropertyValue::aBytes>(PropsSet::Bytes, columnIndex); } // virtual Date SAL_CALL PropertyValueSet::getDate( sal_Int32 columnIndex ) { - GETVALUE_IMPL( Date, PropsSet::Date, aDate ); + return getValue(PropsSet::Date, columnIndex); } // virtual Time SAL_CALL PropertyValueSet::getTime( sal_Int32 columnIndex ) { - GETVALUE_IMPL( Time, PropsSet::Time, aTime ); + return getValue(PropsSet::Time, columnIndex); } // virtual DateTime SAL_CALL PropertyValueSet::getTimestamp( sal_Int32 columnIndex ) { - GETVALUE_IMPL( DateTime, PropsSet::Timestamp, aTimestamp ); + return getValue(PropsSet::Timestamp, columnIndex); } @@ -382,8 +368,7 @@ DateTime SAL_CALL PropertyValueSet::getTimestamp( sal_Int32 columnIndex ) Reference< XInputStream > SAL_CALL PropertyValueSet::getBinaryStream( sal_Int32 columnIndex ) { - GETVALUE_IMPL( - Reference< XInputStream >, PropsSet::BinaryStream, xBinaryStream ); + return getValue, &ucbhelper_impl::PropertyValue::xBinaryStream>(PropsSet::BinaryStream, columnIndex); } @@ -391,8 +376,7 @@ PropertyValueSet::getBinaryStream( sal_Int32 columnIndex ) Reference< XInputStream > SAL_CALL PropertyValueSet::getCharacterStream( sal_Int32 columnIndex ) { - GETVALUE_IMPL( - Reference< XInputStream >, PropsSet::CharacterStream, xCharacterStream ); + return getValue, &ucbhelper_impl::PropertyValue::xCharacterStream>(PropsSet::CharacterStream, columnIndex); } @@ -528,28 +512,28 @@ Any SAL_CALL PropertyValueSet::getObject( // virtual Reference< XRef > SAL_CALL PropertyValueSet::getRef( sal_Int32 columnIndex ) { - GETVALUE_IMPL( Reference< XRef >, PropsSet::Ref, xRef ); + return getValue, &ucbhelper_impl::PropertyValue::xRef>(PropsSet::Ref, columnIndex); } // virtual Reference< XBlob > SAL_CALL PropertyValueSet::getBlob( sal_Int32 columnIndex ) { - GETVALUE_IMPL( Reference< XBlob >, PropsSet::Blob, xBlob ); + return getValue, &ucbhelper_impl::PropertyValue::xBlob>(PropsSet::Blob, columnIndex); } // virtual Reference< XClob > SAL_CALL PropertyValueSet::getClob( sal_Int32 columnIndex ) { - GETVALUE_IMPL( Reference< XClob >, PropsSet::Clob, xClob ); + return getValue, &ucbhelper_impl::PropertyValue::xClob>(PropsSet::Clob, columnIndex); } // virtual Reference< XArray > SAL_CALL PropertyValueSet::getArray( sal_Int32 columnIndex ) { - GETVALUE_IMPL( Reference< XArray >, PropsSet::Array, xArray ); + return getValue, &ucbhelper_impl::PropertyValue::xArray>(PropsSet::Array, columnIndex); } @@ -594,44 +578,59 @@ const Reference< XTypeConverter >& PropertyValueSet::getTypeConverter() } +template +void PropertyValueSet::appendValue(const OUString& rPropName, PropsSet nTypeName, const T& rValue) +{ + osl::MutexGuard aGuard( m_aMutex ); + + ucbhelper_impl::PropertyValue aNewValue; + aNewValue.sPropertyName = rPropName; + aNewValue.nPropsSet = nTypeName; + aNewValue.nOrigValue = nTypeName; + aNewValue.*_member_name_ = rValue; + + m_pValues->push_back( aNewValue ); +} + + void PropertyValueSet::appendString( const OUString& rPropName, const OUString& rValue ) { - SETVALUE_IMPL( rPropName, PropsSet::String, aString, rValue ); + appendValue(rPropName, PropsSet::String, rValue); } void PropertyValueSet::appendBoolean( const OUString& rPropName, bool bValue ) { - SETVALUE_IMPL( rPropName, PropsSet::Boolean, bBoolean, bValue ); + appendValue(rPropName, PropsSet::Boolean, bValue); } void PropertyValueSet::appendLong( const OUString& rPropName, sal_Int64 nValue ) { - SETVALUE_IMPL( rPropName, PropsSet::Long, nLong, nValue ); + appendValue(rPropName, PropsSet::Long, nValue); } void PropertyValueSet::appendTimestamp( const OUString& rPropName, const DateTime& rValue ) { - SETVALUE_IMPL( rPropName, PropsSet::Timestamp, aTimestamp, rValue ); + appendValue(rPropName, PropsSet::Timestamp, rValue); } void PropertyValueSet::appendObject( const OUString& rPropName, const Any& rValue ) { - SETVALUE_IMPL( rPropName, PropsSet::Object, aObject, rValue ); + appendValue(rPropName, PropsSet::Object, rValue); } void PropertyValueSet::appendVoid( const OUString& rPropName ) { - SETVALUE_IMPL( rPropName, PropsSet::NONE, aObject, Any() ); + appendValue(rPropName, PropsSet::NONE, Any()); } -- cgit v1.2.3