OPropertySet doesn't need a pimpl

also inline some of the standalone lambda/functor classes

Change-Id: I0a19a1d3cb7f5b3d02348f1ab57bae08b3ab089a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119379
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
diff --git a/chart2/IwyuFilter_chart2.yaml b/chart2/IwyuFilter_chart2.yaml
index e18c8e3..7d037d9 100644
--- a/chart2/IwyuFilter_chart2.yaml
+++ b/chart2/IwyuFilter_chart2.yaml
@@ -364,9 +364,6 @@ excludelist:
    - com/sun/star/util/XCloneable.hpp
    - com/sun/star/util/XModifyBroadcaster.hpp
    - com/sun/star/util/XModifyListener.hpp
    chart2/source/tools/ImplOPropertySet.cxx:
    # Needed for template
    - com/sun/star/style/XStyle.hpp
    chart2/source/tools/LegendHelper.cxx:
    # Actually used
    - com/sun/star/uno/XComponentContext.hpp
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk
index 3882c37..73945d7 100644
--- a/chart2/Library_chartcore.mk
+++ b/chart2/Library_chartcore.mk
@@ -193,7 +193,6 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\
    chart2/source/tools/ExponentialRegressionCurveCalculator \
    chart2/source/tools/FillProperties \
    chart2/source/tools/FormattedStringHelper \
    chart2/source/tools/ImplOPropertySet \
    chart2/source/tools/InternalData \
    chart2/source/tools/InternalDataProvider \
    chart2/source/tools/LabeledDataSequence \
diff --git a/chart2/source/inc/OPropertySet.hxx b/chart2/source/inc/OPropertySet.hxx
index aa0bf91..52cf2e7 100644
--- a/chart2/source/inc/OPropertySet.hxx
+++ b/chart2/source/inc/OPropertySet.hxx
@@ -27,14 +27,11 @@
#include <com/sun/star/beans/XMultiPropertyStates.hpp>
#include <com/sun/star/style/XStyleSupplier.hpp>

#include <memory>
#include <map>

namespace property
{

namespace impl
{ class ImplOPropertySet; }

class OPropertySet :
    public ::cppu::OBroadcastHelper,
    // includes beans::XPropertySet, XMultiPropertySet and XFastPropertySet
@@ -190,12 +187,42 @@ protected:
    // using setFastPropertyValue

private:
    /** supports states DIRECT_VALUE and DEFAULT_VALUE
     */
    css::beans::PropertyState
        GetPropertyStateByHandle( sal_Int32 nHandle ) const;

    css::uno::Sequence< css::beans::PropertyState >
        GetPropertyStatesByHandle( const std::vector< sal_Int32 > & aHandles ) const;

    void SetPropertyToDefault( sal_Int32 nHandle );
    void SetPropertiesToDefault( const std::vector< sal_Int32 > & aHandles );
    void SetAllPropertiesToDefault();

    /** @param rValue is set to the value for the property given in nHandle.  If
               the property is not set, the style chain is searched for any
               instance set there.  If there was no value found either in the
               property set itself or any of its styles, rValue remains
               unchanged and false is returned.

        @return false if the property is default, true otherwise.
     */
    bool GetPropertyValueByHandle(
        css::uno::Any & rValue,
        sal_Int32 nHandle ) const;

    void SetPropertyValueByHandle( sal_Int32 nHandle,
                                   const css::uno::Any & rValue );

    bool SetStyle( const css::uno::Reference< css::style::XStyle > & xStyle );

    /// reference to mutex of class deriving from here
    ::osl::Mutex &   m_rMutex;

    /// pImpl idiom implementation
    std::unique_ptr< impl::ImplOPropertySet > m_pImplProperties;
    bool m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault;
    typedef std::map< sal_Int32, css::uno::Any > tPropertyMap;
    tPropertyMap    m_aProperties;
    css::uno::Reference< css::style::XStyle > m_xStyle;
};

} //  namespace property
diff --git a/chart2/source/tools/ImplOPropertySet.cxx b/chart2/source/tools/ImplOPropertySet.cxx
deleted file mode 100644
index 537adef..0000000
--- a/chart2/source/tools/ImplOPropertySet.cxx
+++ /dev/null
@@ -1,176 +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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "ImplOPropertySet.hxx"
#include <CloneHelper.hxx>

#include <algorithm>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/style/XStyle.hpp>

using namespace ::com::sun::star;

using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::Any;

namespace
{

struct lcl_getPropertyStateByHandle
{
    explicit lcl_getPropertyStateByHandle(
        const ::property::impl::ImplOPropertySet::tPropertyMap & rMap )
            : m_rMap( rMap )
    {}

    beans::PropertyState operator() ( sal_Int32 nHandle )
    {
        if( m_rMap.end() == m_rMap.find( nHandle ))
            return beans::PropertyState_DEFAULT_VALUE;
        return beans::PropertyState_DIRECT_VALUE;
    }

private:
    const ::property::impl::ImplOPropertySet::tPropertyMap & m_rMap;
};

template< typename K, typename V >
struct lcl_eraseMapEntry
{
    explicit lcl_eraseMapEntry( std::map< K, V > & rMap )
            : m_rMap( rMap )
    {}

    void operator() ( const K & aKey )
    {
        m_rMap.erase( aKey );
    }

private:
    std::map< K, V > m_rMap;
};

struct lcl_replaceInterfacePropertiesByClones
{
    void operator() ( ::property::impl::ImplOPropertySet::tPropertyMap::value_type & rProp )
    {
        if( rProp.second.hasValue() &&
            rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE )
        {
            Reference< util::XCloneable > xCloneable;
            if( rProp.second >>= xCloneable )
                rProp.second <<= xCloneable->createClone();
        }
    }
};

} //  anonymous namespace

namespace property::impl
{

ImplOPropertySet::ImplOPropertySet()
{}

ImplOPropertySet::ImplOPropertySet( const ImplOPropertySet & rOther )
{
    m_aProperties = rOther.m_aProperties;

    // clone interface properties
    std::for_each( m_aProperties.begin(), m_aProperties.end(),
                     lcl_replaceInterfacePropertiesByClones());

    m_xStyle.set( ::chart::CloneHelper::CreateRefClone< style::XStyle >()( rOther.m_xStyle ));
}

beans::PropertyState ImplOPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
{
    return lcl_getPropertyStateByHandle( m_aProperties ) ( nHandle );
}

Sequence< beans::PropertyState > ImplOPropertySet::GetPropertyStatesByHandle(
    const std::vector< sal_Int32 > & aHandles ) const
{
    Sequence< beans::PropertyState > aResult( aHandles.size());

    std::transform( aHandles.begin(), aHandles.end(),
                      aResult.getArray(),
                      lcl_getPropertyStateByHandle( m_aProperties ));

    return aResult;
}

void ImplOPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
{
    tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );

    if( m_aProperties.end() != aFoundIter )
    {
        m_aProperties.erase( aFoundIter );
    }
}

void ImplOPropertySet::SetPropertiesToDefault(
    const std::vector< sal_Int32 > & aHandles )
{
    std::for_each( aHandles.begin(), aHandles.end(),
                     lcl_eraseMapEntry< sal_Int32, Any >( m_aProperties ) );
}

void ImplOPropertySet::SetAllPropertiesToDefault()
{
    m_aProperties.clear();
}

bool ImplOPropertySet::GetPropertyValueByHandle(
    Any & rValue,
    sal_Int32 nHandle ) const
{
    bool bResult = false;

    tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );

    if( m_aProperties.end() != aFoundIter )
    {
        rValue = (*aFoundIter).second;
        bResult = true;
    }

    return bResult;
}

void ImplOPropertySet::SetPropertyValueByHandle(
    sal_Int32 nHandle, const Any & rValue )
{
    m_aProperties[ nHandle ] = rValue;
}

bool ImplOPropertySet::SetStyle( const Reference< style::XStyle > & xStyle )
{
    if( ! xStyle.is())
        return false;

    m_xStyle = xStyle;
    return true;
}

} //  namespace property::impl

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/tools/ImplOPropertySet.hxx b/chart2/source/tools/ImplOPropertySet.hxx
deleted file mode 100644
index 5a6bc54..0000000
--- a/chart2/source/tools/ImplOPropertySet.hxx
+++ /dev/null
@@ -1,82 +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/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#pragma once

#include <com/sun/star/beans/PropertyState.hpp>
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/Any.hxx>

#include <map>
#include <vector>

namespace com::sun::star::style { class XStyle; }

namespace property::impl
{

class ImplOPropertySet
{
public:
    ImplOPropertySet();
    explicit ImplOPropertySet( const ImplOPropertySet & rOther );

    /** supports states DIRECT_VALUE and DEFAULT_VALUE
     */
    css::beans::PropertyState
        GetPropertyStateByHandle( sal_Int32 nHandle ) const;

    css::uno::Sequence< css::beans::PropertyState >
        GetPropertyStatesByHandle( const std::vector< sal_Int32 > & aHandles ) const;

    void SetPropertyToDefault( sal_Int32 nHandle );
    void SetPropertiesToDefault( const std::vector< sal_Int32 > & aHandles );
    void SetAllPropertiesToDefault();

    /** @param rValue is set to the value for the property given in nHandle.  If
               the property is not set, the style chain is searched for any
               instance set there.  If there was no value found either in the
               property set itself or any of its styles, rValue remains
               unchanged and false is returned.

        @return false if the property is default, true otherwise.
     */
    bool GetPropertyValueByHandle(
        css::uno::Any & rValue,
        sal_Int32 nHandle ) const;

    void SetPropertyValueByHandle( sal_Int32 nHandle,
                                   const css::uno::Any & rValue );

    bool SetStyle( const css::uno::Reference< css::style::XStyle > & xStyle );
    const css::uno::Reference< css::style::XStyle >&
        GetStyle() const { return m_xStyle;}

    typedef
        std::map< sal_Int32, css::uno::Any >
        tPropertyMap;

private:
    tPropertyMap    m_aProperties;
    css::uno::Reference< css::style::XStyle >
        m_xStyle;
};

} //  namespace chart::impl

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/chart2/source/tools/OPropertySet.cxx b/chart2/source/tools/OPropertySet.cxx
index 252cfb6..3eb99ca 100644
--- a/chart2/source/tools/OPropertySet.cxx
+++ b/chart2/source/tools/OPropertySet.cxx
@@ -18,9 +18,12 @@
 */

#include <OPropertySet.hxx>
#include "ImplOPropertySet.hxx"
#include <CloneHelper.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/style/XStyle.hpp>

#include <algorithm>
#include <vector>
#include <memory>

@@ -43,7 +46,6 @@ OPropertySet::OPropertySet( ::osl::Mutex & par_rMutex ) :
        // the following causes a warning; there seems to be no way to avoid it
        OPropertySetHelper( static_cast< OBroadcastHelper & >( *this )),
        m_rMutex( par_rMutex ),
        m_pImplProperties( new impl::ImplOPropertySet() ),
        m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault(false)
{
}
@@ -56,8 +58,22 @@ OPropertySet::OPropertySet( const OPropertySet & rOther, ::osl::Mutex & par_rMut
        m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault(false)
{
    MutexGuard aGuard( m_rMutex );
    if (rOther.m_pImplProperties)
        m_pImplProperties.reset(new impl::ImplOPropertySet(*rOther.m_pImplProperties));

    m_aProperties = rOther.m_aProperties;

    // clone interface properties
    for(auto& rProp : m_aProperties)
    {
        if( rProp.second.hasValue() &&
            rProp.second.getValueType().getTypeClass() == uno::TypeClass_INTERFACE )
        {
            Reference< util::XCloneable > xCloneable;
            if( rProp.second >>= xCloneable )
                rProp.second <<= xCloneable->createClone();
        }
    }

    m_xStyle.set( ::chart::CloneHelper::CreateRefClone< style::XStyle >()( rOther.m_xStyle ));
}

void OPropertySet::SetNewValuesExplicitlyEvenIfTheyEqualDefault()
@@ -109,7 +125,7 @@ beans::PropertyState SAL_CALL
{
    cppu::IPropertyArrayHelper & rPH = getInfoHelper();

    return m_pImplProperties->GetPropertyStateByHandle(
    return GetPropertyStateByHandle(
        rPH.getHandleByName( PropertyName ));
}

@@ -124,7 +140,7 @@ Sequence< beans::PropertyState > SAL_CALL
    std::vector< sal_Int32 > aHandles( pHandles.get(), pHandles.get() + aPropertyName.getLength());
    pHandles.reset();

    return m_pImplProperties->GetPropertyStatesByHandle( aHandles );
    return GetPropertyStatesByHandle( aHandles );
}

void SAL_CALL
@@ -132,7 +148,7 @@ void SAL_CALL
{
    cppu::IPropertyArrayHelper & rPH = getInfoHelper();

    m_pImplProperties->SetPropertyToDefault( rPH.getHandleByName( PropertyName ));
    SetPropertyToDefault( rPH.getHandleByName( PropertyName ));
    firePropertyChangeEvent();
}

@@ -152,7 +168,7 @@ Any SAL_CALL
void SAL_CALL
    OPropertySet::setAllPropertiesToDefault()
{
    m_pImplProperties->SetAllPropertiesToDefault();
    SetAllPropertiesToDefault();
    firePropertyChangeEvent();
}

@@ -167,7 +183,7 @@ void SAL_CALL
    std::vector< sal_Int32 > aHandles( pHandles.get(), pHandles.get() + aPropertyNames.getLength());
    pHandles.reset();

    m_pImplProperties->SetPropertiesToDefault( aHandles );
    SetPropertiesToDefault( aHandles );
}

Sequence< Any > SAL_CALL
@@ -246,22 +262,22 @@ void SAL_CALL OPropertySet::setFastPropertyValue_NoBroadcast
    {
        aDefault.clear();
    }
    m_pImplProperties->SetPropertyValueByHandle( nHandle, rValue );
    SetPropertyValueByHandle( nHandle, rValue );
    if( !m_bSetNewValuesExplicitlyEvenIfTheyEqualDefault && aDefault.hasValue() && aDefault == rValue ) //#i98893# don't export defaults to file
        m_pImplProperties->SetPropertyToDefault( nHandle );
        SetPropertyToDefault( nHandle );
    else
        m_pImplProperties->SetPropertyValueByHandle( nHandle, rValue );
        SetPropertyValueByHandle( nHandle, rValue );
}

void SAL_CALL OPropertySet::getFastPropertyValue
    ( Any& rValue,
      sal_Int32 nHandle ) const
{
    if(  m_pImplProperties->GetPropertyValueByHandle( rValue, nHandle ))
    if(  GetPropertyValueByHandle( rValue, nHandle ))
        return;

    // property was not set -> try style
    uno::Reference< beans::XFastPropertySet > xStylePropSet( m_pImplProperties->GetStyle(), uno::UNO_QUERY );
    uno::Reference< beans::XFastPropertySet > xStylePropSet( m_xStyle, uno::UNO_QUERY );
    if( xStylePropSet.is() )
    {
#ifdef DBG_UTIL
@@ -338,12 +354,12 @@ void OPropertySet::firePropertyChangeEvent()
// ____ XStyleSupplier ____
Reference< style::XStyle > SAL_CALL OPropertySet::getStyle()
{
    return m_pImplProperties->GetStyle();
    return m_xStyle;
}

void SAL_CALL OPropertySet::setStyle( const Reference< style::XStyle >& xStyle )
{
    if( ! m_pImplProperties->SetStyle( xStyle ))
    if( ! SetStyle( xStyle ))
        throw lang::IllegalArgumentException(
            "Empty Style",
            static_cast< beans::XPropertySet * >( this ),
@@ -367,6 +383,80 @@ void SAL_CALL OPropertySet::setFastPropertyValue( sal_Int32 nHandle, const Any& 
    firePropertyChangeEvent();
}

beans::PropertyState OPropertySet::GetPropertyStateByHandle( sal_Int32 nHandle ) const
{
    if( m_aProperties.end() == m_aProperties.find( nHandle ))
        return beans::PropertyState_DEFAULT_VALUE;
    return beans::PropertyState_DIRECT_VALUE;
}

Sequence< beans::PropertyState > OPropertySet::GetPropertyStatesByHandle(
    const std::vector< sal_Int32 > & aHandles ) const
{
    Sequence< beans::PropertyState > aResult( aHandles.size());

    std::transform( aHandles.begin(), aHandles.end(),
                      aResult.getArray(),
                      [this](sal_Int32 nHandle) { return GetPropertyStateByHandle(nHandle); });

    return aResult;
}

void OPropertySet::SetPropertyToDefault( sal_Int32 nHandle )
{
    tPropertyMap::iterator aFoundIter( m_aProperties.find( nHandle ) );

    if( m_aProperties.end() != aFoundIter )
    {
        m_aProperties.erase( aFoundIter );
    }
}

void OPropertySet::SetPropertiesToDefault(
    const std::vector< sal_Int32 > & aHandles )
{
    for(auto nHandle : aHandles)
        m_aProperties.erase(nHandle);
}

void OPropertySet::SetAllPropertiesToDefault()
{
    m_aProperties.clear();
}

bool OPropertySet::GetPropertyValueByHandle(
    Any & rValue,
    sal_Int32 nHandle ) const
{
    bool bResult = false;

    tPropertyMap::const_iterator aFoundIter( m_aProperties.find( nHandle ) );

    if( m_aProperties.end() != aFoundIter )
    {
        rValue = (*aFoundIter).second;
        bResult = true;
    }

    return bResult;
}

void OPropertySet::SetPropertyValueByHandle(
    sal_Int32 nHandle, const Any & rValue )
{
    m_aProperties[ nHandle ] = rValue;
}

bool OPropertySet::SetStyle( const Reference< style::XStyle > & xStyle )
{
    if( ! xStyle.is())
        return false;

    m_xStyle = xStyle;
    return true;
}


} //  namespace property

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/solenv/clang-format/excludelist b/solenv/clang-format/excludelist
index bbc8023..4a73ed2 100644
--- a/solenv/clang-format/excludelist
+++ b/solenv/clang-format/excludelist
@@ -1178,8 +1178,6 @@ chart2/source/tools/ExplicitCategoriesProvider.cxx
chart2/source/tools/ExponentialRegressionCurveCalculator.cxx
chart2/source/tools/FillProperties.cxx
chart2/source/tools/FormattedStringHelper.cxx
chart2/source/tools/ImplOPropertySet.cxx
chart2/source/tools/ImplOPropertySet.hxx
chart2/source/tools/InternalData.cxx
chart2/source/tools/InternalDataProvider.cxx
chart2/source/tools/LabeledDataSequence.cxx