Remove demonstrated-useless comphelper::compare

Change-Id: Ifd1b38afb963255b76f0d821eb46e4c6a972128a
This commit is contained in:
Stephan Bergmann 2015-08-21 10:33:44 +02:00
parent 5ff8f80a27
commit fe6c124da7
14 changed files with 15 additions and 405 deletions

View File

@ -11,7 +11,6 @@ $(eval $(call gb_CppunitTest_CppunitTest,comphelper_test))
$(eval $(call gb_CppunitTest_add_exception_objects,comphelper_test, \
comphelper/qa/string/test_string \
comphelper/qa/test_any \
))
$(eval $(call gb_CppunitTest_use_api,comphelper_test, \
@ -27,6 +26,4 @@ $(eval $(call gb_CppunitTest_use_libraries,comphelper_test, \
$(gb_UWINAPI) \
))
$(eval $(call gb_CppunitTest_use_ure,comphelper_test))
# vim: set noet sw=4 ts=4:

View File

@ -1,94 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <com/sun/star/awt/FontDescriptor.hpp>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/util/Date.hpp>
#include <com/sun/star/util/DateTime.hpp>
#include <comphelper/types.hxx>
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <sal/types.h>
// Demonstrate that comphelper::compare works exactly the same as
// css::uno::Any::operator ==:
namespace {
class Test: public CppUnit::TestFixture {
public:
void test();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(test);
CPPUNIT_TEST_SUITE_END();
};
void Test::test() {
css::uno::Any a1, a2;
a1 = css::uno::makeAny<sal_uInt32>(5);
a2 = css::uno::makeAny<sal_Int16>(5);
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<sal_uInt32>(5);
a2 = css::uno::makeAny<sal_Int16>(6);
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<css::awt::FontDescriptor>({
"A", 0, 1, "B", 3, 4, 5, 6.0, 7.0, css::awt::FontSlant_NONE, 8, 9, 10.0,
false, true, 11});
a2 = css::uno::makeAny<css::awt::FontDescriptor>({
"A", 0, 1, "B", 3, 4, 5, 6.0, 7.0, css::awt::FontSlant_NONE, 8, 9, 10.0,
false, true, 11});
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<css::awt::FontDescriptor>({
"A", 0, 1, "B", 3, 4, 5, 6.0, 7.0, css::awt::FontSlant_NONE, 8, 9, 10.0,
false, true, 11});
a2 = css::uno::makeAny<css::awt::FontDescriptor>({
"a", 0, 1, "B", 3, 4, 5, 6.0, 7.0, css::awt::FontSlant_NONE, 8, 9, 10.0,
false, true, 11});
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<css::util::Date>({1, 2, 2003});
a2 = css::uno::makeAny<css::util::Date>({1, 2, 2003});
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<css::util::Date>({1, 2, 2003});
a2 = css::uno::makeAny<css::util::Date>({1, 3, 2003});
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<css::util::Date>({1, 2, 2003});
a2 = css::uno::makeAny<css::util::DateTime>({
0, 0, 0, 0, 1, 2, 2003, false});
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<css::uno::Sequence<sal_Int8>>({0, 1, 2});
a2 = css::uno::makeAny<css::uno::Sequence<sal_Int8>>({0, 1, 2});
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<css::uno::Sequence<sal_Int8>>({0, 1, 2});
a2 = css::uno::makeAny<css::uno::Sequence<sal_Int8>>({0, 1, 3});
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
a1 = css::uno::makeAny<css::uno::Sequence<sal_Int8>>({0, 1, 2});
a2 = css::uno::makeAny<css::uno::Sequence<sal_Int8>>({0, 1});
CPPUNIT_ASSERT_EQUAL(a1 == a2, comphelper::compare(a1, a2));
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -41,36 +41,6 @@ using namespace ::com::sun::star::awt;
using namespace ::com::sun::star::util;
using namespace ::com::sun::star::lang;
bool operator ==(const DateTime& _rLeft, const DateTime& _rRight)
{
return ( _rLeft.NanoSeconds == _rRight.NanoSeconds) &&
( _rLeft.Seconds == _rRight.Seconds) &&
( _rLeft.Minutes == _rRight.Minutes) &&
( _rLeft.Hours == _rRight.Hours) &&
( _rLeft.Day == _rRight.Day) &&
( _rLeft.Month == _rRight.Month) &&
( _rLeft.Year == _rRight.Year) ;
}
bool operator ==(const Date& _rLeft, const Date& _rRight)
{
return ( _rLeft.Day == _rRight.Day) &&
( _rLeft.Month == _rRight.Month) &&
( _rLeft.Year == _rRight.Year) ;
}
bool operator ==(const Time& _rLeft, const Time& _rRight)
{
return ( _rLeft.NanoSeconds == _rRight.NanoSeconds) &&
( _rLeft.Seconds == _rRight.Seconds) &&
( _rLeft.Minutes == _rRight.Minutes) &&
( _rLeft.Hours == _rRight.Hours) ;
}
sal_Int64 getINT64(const Any& _rAny)
{
sal_Int64 nReturn = 0;
@ -162,260 +132,6 @@ bool isAssignableFrom(const Type& _rAssignable, const Type& _rFrom)
return typelib_typedescription_isAssignableFrom(pAssignable, pFrom);
}
template<class TYPE>
bool tryCompare(const void* _pData, const Any& _rValue, bool& _bIdentical, TYPE& _rOut)
{
bool bSuccess = _rValue >>= _rOut;
_bIdentical = bSuccess && (_rOut == *static_cast<const TYPE*>(_pData));
return bSuccess;
}
bool tryCompare(const void* _pData, const Any& _rValue, bool& _bIdentical, sal_Unicode& _rOut)
{
bool bSuccess = ( _rValue.getValueTypeClass() == TypeClass_CHAR );
if ( bSuccess )
_rOut = *static_cast< const sal_Unicode* >( _rValue.getValue() );
_bIdentical = bSuccess && ( _rOut == *static_cast< const sal_Unicode* >( _pData ) );
return bSuccess;
}
bool compare_impl(const Type& _rType, const void* pData, const Any& _rValue)
{
bool bRes = true;
if (_rType.getTypeClass() == TypeClass_ANY)
{
// beides AnyWerte
if (_rValue.getValueType().getTypeClass() == TypeClass_ANY)
bRes = compare_impl(
static_cast<const Any*>(pData)->getValueType(),
static_cast<const Any*>(pData)->getValue(),
*static_cast<const Any*>(_rValue.getValue()));
else
bRes = compare_impl(
static_cast<const Any*>(pData)->getValueType(),
static_cast<const Any*>(pData)->getValue(),
_rValue);
}
else if ( (_rType.getTypeClass() == TypeClass_VOID)
|| (_rValue.getValueType().getTypeClass() == TypeClass_VOID)
)
{
bRes = _rType.getTypeClass() == _rValue.getValueType().getTypeClass();
}
else
{
bool bConversionSuccess = false;
switch (_rType.getTypeClass())
{
case TypeClass_VOID:
bConversionSuccess = true;
bRes = _rValue.getValueType().getTypeClass() == TypeClass_VOID;
break;
case TypeClass_BOOLEAN:
{
bool aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_CHAR:
{
sal_Unicode aDummy(0);
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_STRING:
{
OUString aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_FLOAT:
{
float aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_DOUBLE:
{
double aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_BYTE:
{
sal_Int8 aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_SHORT:
{
sal_Int16 aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_ENUM:
{
sal_Int32 nAsInt32 = 0;
bConversionSuccess = ::cppu::enum2int(nAsInt32, _rValue);
bRes = bConversionSuccess && (nAsInt32== *static_cast<const sal_Int32*>(pData));
break;
}
case TypeClass_LONG:
{
sal_Int32 aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_UNSIGNED_SHORT:
{
sal_uInt16 aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_UNSIGNED_LONG:
{
sal_uInt32 aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_INTERFACE:
{
css::uno::Reference<css::uno::XInterface> aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
case TypeClass_STRUCT:
if (_rType == cppu::UnoType<FontDescriptor>::get())
{
FontDescriptor aTemp;
bConversionSuccess = _rValue >>= aTemp;
if (bConversionSuccess)
{
bRes = *static_cast<FontDescriptor const *>(pData) == aTemp;
}
else
bRes = false;
break;
}
if (_rType == cppu::UnoType<Date>::get())
{
Date aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
if (_rType == cppu::UnoType<Time>::get())
{
Time aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
if (_rType == cppu::UnoType<DateTime>::get())
{
DateTime aDummy;
bConversionSuccess = tryCompare(pData, _rValue, bRes, aDummy);
break;
}
break;
case TypeClass_SEQUENCE:
if (_rType == cppu::UnoType<Sequence<sal_Int8>>::get())
{
Sequence<sal_Int8> aTemp;
bConversionSuccess = _rValue >>= aTemp;
if (bConversionSuccess)
{
const Sequence<sal_Int8>& rLeftSeq = *static_cast<const Sequence<sal_Int8>*>(pData);
const Sequence<sal_Int8>& rRightSeq = aTemp;
bRes = rLeftSeq.getLength() == rRightSeq.getLength() &&
memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()) == 0;
}
}
else if (_rType == cppu::UnoType<Sequence<sal_Int16>>::get())
{
Sequence<sal_Int16> aTemp;
bConversionSuccess = _rValue >>= aTemp;
if (bConversionSuccess)
{
const Sequence<sal_Int16>& rLeftSeq = *static_cast<const Sequence<sal_Int16>*>(pData);
const Sequence<sal_Int16>& rRightSeq = aTemp;
bRes = rLeftSeq.getLength() == rRightSeq.getLength() &&
memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()*sizeof(sal_Int16)) == 0;
}
}
else if (_rType == cppu::UnoType<cppu::UnoSequenceType<cppu::UnoUnsignedShortType>>::get())
{
Sequence<sal_uInt16> aTemp;
bConversionSuccess = _rValue >>= aTemp;
if (bConversionSuccess)
{
const Sequence<sal_uInt16>& rLeftSeq = *static_cast<const Sequence<sal_uInt16>*>(pData);
const Sequence<sal_uInt16>& rRightSeq = aTemp;
bRes = rLeftSeq.getLength() == rRightSeq.getLength() &&
memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()*sizeof(sal_uInt16)) == 0;
}
}
else if (_rType == cppu::UnoType<Sequence<sal_Int32>>::get())
{
Sequence<sal_Int32> aTemp;
bConversionSuccess = _rValue >>= aTemp;
if (bConversionSuccess)
{
const Sequence<sal_Int32>& rLeftSeq = *static_cast<const Sequence<sal_Int32>*>(pData);
const Sequence<sal_Int32>& rRightSeq = aTemp;
bRes = rLeftSeq.getLength() == rRightSeq.getLength() &&
memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()*sizeof(sal_Int32)) == 0;
}
}
else if (_rType == cppu::UnoType<Sequence<sal_uInt32>>::get())
{
Sequence<sal_uInt32> aTemp;
bConversionSuccess = _rValue >>= aTemp;
if (bConversionSuccess)
{
const Sequence<sal_uInt32>& rLeftSeq = *static_cast<const Sequence<sal_uInt32>*>(pData);
const Sequence<sal_uInt32>& rRightSeq = aTemp;
bRes = rLeftSeq.getLength() == rRightSeq.getLength() &&
memcmp(rLeftSeq.getConstArray(), rRightSeq.getConstArray(), rLeftSeq.getLength()*sizeof(sal_uInt32)) == 0;
}
}
else if (_rType == cppu::UnoType<Sequence<OUString>>::get())
{
Sequence< OUString > aTemp;
bConversionSuccess = _rValue >>= aTemp;
if (bConversionSuccess)
{
const Sequence< OUString >& rLeftSeq = *static_cast<const Sequence< OUString>*>(pData);
const Sequence< OUString >& rRightSeq = aTemp;
sal_Int32 nSeqLen = rLeftSeq.getLength();
bRes = ( nSeqLen == rRightSeq.getLength() );
for ( sal_Int32 n = 0; bRes && ( n < nSeqLen ); n++ )
{
const OUString& rS1 = rLeftSeq.getConstArray()[n];
const OUString& rS2 = rRightSeq.getConstArray()[n];
bRes = ( rS1 == rS2 );
}
}
}
break;
default:
bRes = false;
}
bRes = bRes && bConversionSuccess;
}
return bRes;
}
bool compare(const Any& rLeft, const Any& rRight)
{
return compare_impl(rLeft.getValueType(), rLeft.getValue(), rRight);
}
bool operator ==(const FontDescriptor& _rLeft, const FontDescriptor& _rRight)
{
return ( _rLeft.Name.equals( _rRight.Name ) ) &&

View File

@ -813,7 +813,7 @@ sal_Bool ODatabaseSource::convertFastPropertyValue(Any & rConvertedValue, Any &
bModified = checkValue->Name != pInfoIter->Name;
if ( !bModified )
{
bModified = !::comphelper::compare(checkValue->Value,pInfoIter->Value);
bModified = checkValue->Value != pInfoIter->Value;
}
}
}

View File

@ -748,7 +748,7 @@ void ODbDataSourceAdministrationHelper::fillDatasourceInfo(const SfxItemSet& _rS
PropertyValueSet::iterator aOverwrittenSetting = aRelevantSettings.find(aSearchFor);
if (aRelevantSettings.end() != aOverwrittenSetting)
{ // the setting was present in the original sequence, and it is to be overwritten -> replace it
if ( !::comphelper::compare(pInfo->Value,aOverwrittenSetting->Value) )
if ( pInfo->Value != aOverwrittenSetting->Value )
*pInfo = *aOverwrittenSetting;
aRelevantSettings.erase(aOverwrittenSetting);
}

View File

@ -187,7 +187,7 @@ OUString SAL_CALL OCurrencyModel::getServiceName() throw ( ::com::sun::star::uno
bool OCurrencyModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
{
Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
if ( !compare( aControlValue, m_aSaveValue ) )
if ( aControlValue != m_aSaveValue )
{
if ( aControlValue.getValueType().getTypeClass() == TypeClass_VOID )
m_xColumnUpdate->updateNull();

View File

@ -223,7 +223,7 @@ void ODateModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
bool ODateModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
{
Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
if ( !compare( aControlValue, m_aSaveValue ) )
if ( aControlValue != m_aSaveValue )
{
if ( !aControlValue.hasValue() )
m_xColumnUpdate->updateNull();

View File

@ -138,7 +138,7 @@ OUString SAL_CALL ONumericModel::getServiceName() throw ( ::com::sun::star::uno:
bool ONumericModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
{
Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
if ( !compare( aControlValue, m_aSaveValue ) )
if ( aControlValue != m_aSaveValue )
{
if ( !aControlValue.hasValue() )
m_xColumnUpdate->updateNull();

View File

@ -215,7 +215,7 @@ void OTimeModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
bool OTimeModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
{
Any aControlValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
if ( !compare( aControlValue, m_aSaveValue ) )
if ( aControlValue != m_aSaveValue )
{
if ( !aControlValue.hasValue() )
m_xColumnUpdate->updateNull();

View File

@ -36,13 +36,6 @@ namespace com { namespace sun { namespace star { namespace awt {
namespace comphelper
{
/** compare the two given Anys
The comparison is deep, means if one of the Any's contains an Any which contains an Any ..., this is resolved <br/>
Other types recognized currently : FontDescriptor, ::com::sun::star::util::Date/Tim/DateTime, css::uno::Sequence<sal_Int8>
*/
COMPHELPER_DLLPUBLIC bool compare(const css::uno::Any& rLeft, const css::uno::Any& rRight);
/** compare two FontDescriptor's
*/
COMPHELPER_DLLPUBLIC bool operator ==(const css::awt::FontDescriptor& _rLeft, const css::awt::FontDescriptor& _rRight);

View File

@ -35,7 +35,6 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/property.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <comphelper/types.hxx>
#include <connectivity/dbtools.hxx>
#include <com/sun/star/view/PaperFormat.hpp>
@ -4137,7 +4136,7 @@ void OReportController::impl_fillState_nothrow(const OUString& _sProperty,dbaui:
{
aTemp = aTemp2;
}
else if ( !comphelper::compare(aTemp,aTemp2) )
else if ( aTemp != aTemp2 )
break;
}
catch(const beans::UnknownPropertyException&)

View File

@ -246,7 +246,7 @@ static const sal_uInt16 ControlMap[] =
bool CompareBookmark(const Any& aLeft, const Any& aRight)
{
return ::comphelper::compare(aLeft, aRight);
return aLeft == aRight;
}
class FmXGridSourcePropListener : public ::comphelper::OPropertyChangeListener

View File

@ -497,9 +497,9 @@ Reference< XInterface > FmFormObj::ensureModelEnv(const Reference< XInterface >
{ // it is a form
try
{
if ( ::comphelper::compare(xCurrentSourceForm->getPropertyValue(FM_PROP_COMMAND), aSrcCursorSource)
&& ::comphelper::compare(xCurrentSourceForm->getPropertyValue(FM_PROP_COMMANDTYPE), aSrcCursorSourceType)
&& ::comphelper::compare(xCurrentSourceForm->getPropertyValue(FM_PROP_DATASOURCE), aSrcDataSource)
if ( xCurrentSourceForm->getPropertyValue(FM_PROP_COMMAND) == aSrcCursorSource
&& xCurrentSourceForm->getPropertyValue(FM_PROP_COMMANDTYPE) == aSrcCursorSourceType
&& xCurrentSourceForm->getPropertyValue(FM_PROP_DATASOURCE) == aSrcDataSource
)
{
bEqualDSS = true;
@ -528,9 +528,9 @@ Reference< XInterface > FmFormObj::ensureModelEnv(const Reference< XInterface >
{ // it is a form
try
{
if ( ::comphelper::compare(xCurrentDestForm->getPropertyValue(FM_PROP_COMMAND), aSrcCursorSource)
&& ::comphelper::compare(xCurrentDestForm->getPropertyValue(FM_PROP_COMMANDTYPE), aSrcCursorSourceType)
&& ::comphelper::compare(xCurrentDestForm->getPropertyValue(FM_PROP_DATASOURCE), aSrcDataSource)
if ( xCurrentDestForm->getPropertyValue(FM_PROP_COMMAND) == aSrcCursorSource
&& xCurrentDestForm->getPropertyValue(FM_PROP_COMMANDTYPE) == aSrcCursorSourceType
&& xCurrentDestForm->getPropertyValue(FM_PROP_DATASOURCE) == aSrcDataSource
)
{
bEqualDSS = true;

View File

@ -45,7 +45,6 @@
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/resource/XStringResourceResolver.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <comphelper/types.hxx>
#include <functional>
#include <algorithm>
@ -390,7 +389,7 @@ bool DoesDependOnOthers( sal_uInt16 nPropertyId )
bool CompareProperties( const ::com::sun::star::uno::Any& r1, const ::com::sun::star::uno::Any& r2 )
{
return ::comphelper::compare( r1, r2 );
return r1 == r2;
}