[Libreoffice-commits] core.git: comphelper/source include/comphelper

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 10 10:18:17 UTC 2021


 comphelper/source/property/propertysetinfo.cxx |  137 +++++++------------------
 include/comphelper/propertysetinfo.hxx         |   17 +--
 2 files changed, 52 insertions(+), 102 deletions(-)

New commits:
commit d5c8684c05e33e87033d595c98fb50acd42d56a8
Author:     Noel Grandin <noelgrandin at gmail.com>
AuthorDate: Mon Aug 9 18:35:35 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Aug 10 12:17:36 2021 +0200

    flatten PropertySetInfo a little
    
    Change-Id: I46bc0dc2da9b52d5a2cb1e415328ab1f13a96ff3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120216
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/comphelper/source/property/propertysetinfo.cxx b/comphelper/source/property/propertysetinfo.cxx
index fd68b529392a..f21afe3951cd 100644
--- a/comphelper/source/property/propertysetinfo.cxx
+++ b/comphelper/source/property/propertysetinfo.cxx
@@ -29,35 +29,26 @@ using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::lang;
 
-namespace comphelper
+void PropertySetInfo::addImpl(PropertyMapEntry const * pMap) noexcept
 {
-class PropertyMapImpl final
-{
-public:
-    PropertyMapImpl() noexcept;
-
-    void add(PropertyMapEntry const * pMap) noexcept;
-    void remove( const OUString& aName ) noexcept;
-
-    std::vector< Property > const & getProperties() noexcept;
+    while (!pMap->maName.isEmpty())
+    {
+        // check for duplicates
+        assert(maPropertyMap.find(pMap->maName) == maPropertyMap.end());
 
-    const PropertyMap& getPropertyMap() const noexcept { return maPropertyMap;}
+        maPropertyMap[pMap->maName] = pMap;
 
-        /// @throws UnknownPropertyException
-    Property getPropertyByName( const OUString& aName );
-    bool hasPropertyByName( const OUString& aName ) noexcept;
+        maProperties.clear();
 
-private:
-    PropertyMap maPropertyMap;
-    std::vector< Property > maProperties;
-};
+        ++pMap;
+    }
 }
 
-PropertyMapImpl::PropertyMapImpl() noexcept
+PropertySetInfo::PropertySetInfo() noexcept
 {
 }
 
-void PropertyMapImpl::add(PropertyMapEntry const * pMap) noexcept
+PropertySetInfo::PropertySetInfo( PropertyMapEntry const * pMap ) noexcept
 {
     while (!pMap->maName.isEmpty())
     {
@@ -66,20 +57,44 @@ void PropertyMapImpl::add(PropertyMapEntry const * pMap) noexcept
 
         maPropertyMap[pMap->maName] = pMap;
 
-        maProperties.clear();
+        ++pMap;
+    }
+}
 
-        pMap = &pMap[1];
+PropertySetInfo::PropertySetInfo(uno::Sequence<beans::Property> const& rProps) noexcept
+{
+    PropertyMapEntry * pEntries(new PropertyMapEntry[rProps.getLength() + 1]);
+    PropertyMapEntry * pEntry(&pEntries[0]);
+    for (auto const& it : rProps)
+    {
+        pEntry->maName = it.Name;
+        pEntry->mnHandle = it.Handle;
+        pEntry->maType = it.Type;
+        pEntry->mnAttributes = it.Attributes;
+        pEntry->mnMemberId = 0;
+        ++pEntry;
     }
+    pEntry->maName = OUString();
+
+    addImpl(pEntries);
+}
+
+PropertySetInfo::~PropertySetInfo() noexcept
+{
 }
 
-void PropertyMapImpl::remove( const OUString& aName ) noexcept
+void PropertySetInfo::add( PropertyMapEntry const * pMap ) noexcept
 {
-    maPropertyMap.erase( aName );
+    addImpl( pMap );
+}
 
+void PropertySetInfo::remove( const OUString& aName ) noexcept
+{
+    maPropertyMap.erase( aName );
     maProperties.clear();
 }
 
-std::vector< Property > const & PropertyMapImpl::getProperties() noexcept
+Sequence< css::beans::Property > SAL_CALL PropertySetInfo::getProperties()
 {
     // maybe we have to generate the properties after
     // a change in the property map or at first call
@@ -101,12 +116,10 @@ std::vector< Property > const & PropertyMapImpl::getProperties() noexcept
             ++propIter;
         }
     }
-
-    return maProperties;
+    return comphelper::containerToSequence(maProperties);
 }
 
-
-Property PropertyMapImpl::getPropertyByName( const OUString& aName )
+Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName )
 {
     PropertyMap::iterator aIter = maPropertyMap.find( aName );
 
@@ -118,73 +131,9 @@ Property PropertyMapImpl::getPropertyByName( const OUString& aName )
     return Property( aName, pEntry->mnHandle, pEntry->maType, pEntry->mnAttributes );
 }
 
-bool PropertyMapImpl::hasPropertyByName( const OUString& aName ) noexcept
+sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& aName )
 {
     return maPropertyMap.find( aName ) != maPropertyMap.end();
 }
 
-
-PropertySetInfo::PropertySetInfo() noexcept
-    : mpImpl(new PropertyMapImpl)
-{
-}
-
-PropertySetInfo::PropertySetInfo( PropertyMapEntry const * pMap ) noexcept
-    : mpImpl(new PropertyMapImpl)
-{
-    mpImpl->add( pMap );
-}
-
-PropertySetInfo::PropertySetInfo(uno::Sequence<beans::Property> const& rProps) noexcept
-    : mpImpl(new PropertyMapImpl)
-{
-    PropertyMapEntry * pEntries(new PropertyMapEntry[rProps.getLength() + 1]);
-    PropertyMapEntry * pEntry(&pEntries[0]);
-    for (auto const& it : rProps)
-    {
-        pEntry->maName = it.Name;
-        pEntry->mnHandle = it.Handle;
-        pEntry->maType = it.Type;
-        pEntry->mnAttributes = it.Attributes;
-        pEntry->mnMemberId = 0;
-        ++pEntry;
-    }
-    pEntry->maName = OUString();
-    mpImpl->add(pEntries);
-}
-
-PropertySetInfo::~PropertySetInfo() noexcept
-{
-}
-
-void PropertySetInfo::add( PropertyMapEntry const * pMap ) noexcept
-{
-    mpImpl->add( pMap );
-}
-
-void PropertySetInfo::remove( const OUString& aName ) noexcept
-{
-    mpImpl->remove( aName );
-}
-
-Sequence< css::beans::Property > SAL_CALL PropertySetInfo::getProperties()
-{
-    return comphelper::containerToSequence(mpImpl->getProperties());
-}
-
-Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName )
-{
-    return mpImpl->getPropertyByName( aName );
-}
-
-sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& Name )
-{
-    return mpImpl->hasPropertyByName( Name );
-}
-
-const PropertyMap& PropertySetInfo::getPropertyMap() const noexcept
-{
-    return mpImpl->getPropertyMap();
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/comphelper/propertysetinfo.hxx b/include/comphelper/propertysetinfo.hxx
index 518b83375a3f..34717fcc6c2d 100644
--- a/include/comphelper/propertysetinfo.hxx
+++ b/include/comphelper/propertysetinfo.hxx
@@ -22,13 +22,12 @@
 
 #include <sal/config.h>
 
-#include <map>
-
 #include <com/sun/star/beans/XPropertySetInfo.hpp>
 #include <cppuhelper/implbase.hxx>
 #include <comphelper/comphelperdllapi.h>
 #include <o3tl/typed_flags_set.hxx>
-#include <memory>
+#include <map>
+#include <vector>
 
 enum class PropertyMoreFlags : sal_uInt8 {
     NONE            = 0x00,
@@ -77,8 +76,6 @@ struct PropertyMapEntry
 
 typedef std::map<OUString, PropertyMapEntry const *> PropertyMap;
 
-class PropertyMapImpl;
-
 // don't export to avoid duplicate WeakImplHelper definitions with MSVC
 class SAL_DLLPUBLIC_TEMPLATE PropertySetInfo_BASE
     : public ::cppu::WeakImplHelper< css::beans::XPropertySetInfo >
@@ -90,8 +87,6 @@ class SAL_DLLPUBLIC_TEMPLATE PropertySetInfo_BASE
 class COMPHELPER_DLLPUBLIC PropertySetInfo final
     : public PropertySetInfo_BASE
 {
-private:
-    std::unique_ptr<PropertyMapImpl> mpImpl;
 public:
     PropertySetInfo() noexcept;
     PropertySetInfo( PropertyMapEntry const * pMap ) noexcept;
@@ -101,7 +96,7 @@ public:
     /** returns a stl map with all PropertyMapEntry pointer.<p>
         The key is the property name.
     */
-    const PropertyMap& getPropertyMap() const noexcept;
+    const PropertyMap& getPropertyMap() const noexcept { return maPropertyMap; }
 
     /** adds an array of PropertyMapEntry to this instance.<p>
         The end is marked with a PropertyMapEntry where mpName equals NULL</p>
@@ -114,6 +109,12 @@ public:
     virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties() override;
     virtual css::beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override;
     virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override;
+
+private:
+    void addImpl(PropertyMapEntry const * pMap) noexcept;
+
+    PropertyMap maPropertyMap;
+    std::vector< css::beans::Property > maProperties;
 };
 
 }


More information about the Libreoffice-commits mailing list