[Libreoffice-commits] core.git: cui/source include/svl sfx2/source svl/source sw/source

Jochen Nitschke j.nitschke+logerrit at ok.de
Fri Jan 27 15:59:08 UTC 2017


 cui/source/dialogs/srchxtra.cxx   |    4 ++--
 include/svl/poolitem.hxx          |    4 +++-
 sfx2/source/control/bindings.cxx  |    4 ++--
 svl/source/items/itemset.cxx      |   24 ++++++++++++------------
 sw/source/core/txtnode/thints.cxx |   10 +++++-----
 5 files changed, 24 insertions(+), 22 deletions(-)

New commits:
commit 70dee11c2e15e90fbd41bf331e67c1d28e094e35
Author: Jochen Nitschke <j.nitschke+logerrit at ok.de>
Date:   Fri Jan 27 14:50:50 2017 +0100

    use a define for invalid SfxPoolItem
    
    and use helper function IsInvalidItem() more
    
    Change-Id: Ifd651a336a7bd4ef4f945219d765afb827465438
    Reviewed-on: https://gerrit.libreoffice.org/33611
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Reviewed-by: Jochen Nitschke <j.nitschke+logerrit at ok.de>
    Tested-by: Jochen Nitschke <j.nitschke+logerrit at ok.de>

diff --git a/cui/source/dialogs/srchxtra.cxx b/cui/source/dialogs/srchxtra.cxx
index d6e0578..23342dd 100644
--- a/cui/source/dialogs/srchxtra.cxx
+++ b/cui/source/dialogs/srchxtra.cxx
@@ -196,7 +196,7 @@ void SvxSearchAttributeDialog::dispose()
 IMPL_LINK_NOARG(SvxSearchAttributeDialog, OKHdl, Button*, void)
 {
     SearchAttrItem aInvalidItem;
-    aInvalidItem.pItem = reinterpret_cast<SfxPoolItem*>(-1);
+    aInvalidItem.pItem = INVALID_POOL_ITEM;
 
     for ( sal_uLong i = 0; i < m_pAttrLB->GetEntryCount(); ++i )
     {
@@ -213,7 +213,7 @@ IMPL_LINK_NOARG(SvxSearchAttributeDialog, OKHdl, Button*, void)
                 {
                     if( !IsInvalidItem( rItem.pItem ) )
                         delete rItem.pItem;
-                    rItem.pItem = reinterpret_cast<SfxPoolItem*>(-1);
+                    rItem.pItem = INVALID_POOL_ITEM;
                 }
                 else if( IsInvalidItem( rItem.pItem ) )
                     rItem.pItem = nullptr;
diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx
index fa2fbd1..54571a6 100644
--- a/include/svl/poolitem.hxx
+++ b/include/svl/poolitem.hxx
@@ -108,6 +108,8 @@ enum class SfxItemState {
     SET      = 0x0030
 };
 
+#define INVALID_POOL_ITEM reinterpret_cast<SfxPoolItem*>(-1)
+
 class SvXMLUnitConverter;
 class SfxItemPool;
 class SfxItemSet;
@@ -227,7 +229,7 @@ inline bool IsPooledItem( const SfxPoolItem *pItem )
 
 inline bool IsInvalidItem(const SfxPoolItem *pItem)
 {
-    return pItem == reinterpret_cast<SfxPoolItem *>(-1);
+    return pItem == INVALID_POOL_ITEM;
 }
 
 class SVL_DLLPUBLIC SfxVoidItem final: public SfxPoolItem
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index f9a91c8..c72f303 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -1357,7 +1357,7 @@ void SfxBindings::UpdateControllers_Impl
         if ( SfxItemState::DONTCARE == eState )
         {
             // ambiguous
-            pCache->SetState( SfxItemState::DONTCARE, reinterpret_cast<SfxPoolItem *>(-1) );
+            pCache->SetState( SfxItemState::DONTCARE, INVALID_POOL_ITEM );
         }
         else if ( SfxItemState::DEFAULT == eState &&
                   SfxItemPool::IsSlot(rFound.nWhichId) )
@@ -1427,7 +1427,7 @@ void SfxBindings::UpdateControllers_Impl
                 else
                 {
                     // ambiguous
-                    pEnumCache->SetState( SfxItemState::DONTCARE, reinterpret_cast<SfxPoolItem *>(-1) );
+                    pEnumCache->SetState( SfxItemState::DONTCARE, INVALID_POOL_ITEM );
                 }
             }
 
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 9e44a8b..a4ed73c 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -436,7 +436,7 @@ SfxItemState SfxItemSet::GetItemState( sal_uInt16 nWhich,
                         break; // Keep searching in the parents!
                     }
 
-                    if ( reinterpret_cast<SfxPoolItem*>(-1) == *ppFnd )
+                    if ( IsInvalidItem(*ppFnd) )
                         // Different ones are present
                         return SfxItemState::DONTCARE;
 
@@ -779,7 +779,7 @@ void SfxItemSet::SetRanges( const sal_uInt16 *pNewRanges )
                 else if ( SfxItemState::DONTCARE == eState )
                 {
                     ++nNewCount;
-                    aNewItems[n] = reinterpret_cast<SfxPoolItem*>(-1);
+                    aNewItems[n] = INVALID_POOL_ITEM;
                 }
                 else
                 {
@@ -908,7 +908,7 @@ const SfxPoolItem& SfxItemSet::Get( sal_uInt16 nWhich, bool bSrchInParent) const
                     ppFnd += nWhich - *pPtr;
                     if( *ppFnd )
                     {
-                        if( reinterpret_cast<SfxPoolItem*>(-1) == *ppFnd ) {
+                        if( IsInvalidItem(*ppFnd) ) {
                             //FIXME: The following code is duplicated further down
                             SAL_WARN_IF(!m_pPool, "svl.items", "no Pool, but status is ambiguous, with ID/pos " << nWhich);
                             //!((SfxAllItemSet *)this)->aDefault.SetWhich(nWhich);
@@ -1192,12 +1192,12 @@ static void MergeItem_Impl( SfxItemPool *_pPool, sal_uInt16 &rCount,
     {
         if ( IsInvalidItem(pFnd2) )
             // Decision table: default, dontcare, doesn't matter, doesn't matter
-            *ppFnd1 = reinterpret_cast<SfxPoolItem*>(-1);
+            *ppFnd1 = INVALID_POOL_ITEM;
 
         else if ( pFnd2 && !bIgnoreDefaults &&
                   _pPool->GetDefaultItem(pFnd2->Which()) != *pFnd2 )
             // Decision table: default, set, !=, sal_False
-            *ppFnd1 = reinterpret_cast<SfxPoolItem*>(-1);
+            *ppFnd1 = INVALID_POOL_ITEM;
 
         else if ( pFnd2 && bIgnoreDefaults )
             // Decision table: default, set, doesn't matter, sal_True
@@ -1218,7 +1218,7 @@ static void MergeItem_Impl( SfxItemPool *_pPool, sal_uInt16 &rCount,
             {
                 // Decision table: set, default, !=, sal_False
                 _pPool->Remove( **ppFnd1 );
-                *ppFnd1 = reinterpret_cast<SfxPoolItem*>(-1);
+                *ppFnd1 = INVALID_POOL_ITEM;
             }
         }
         else if ( IsInvalidItem(pFnd2) )
@@ -1230,7 +1230,7 @@ static void MergeItem_Impl( SfxItemPool *_pPool, sal_uInt16 &rCount,
                 // Decision table: set, dontcare, doesn't matter, sal_False
                 // or:             set, dontcare, !=, sal_True
                 _pPool->Remove( **ppFnd1 );
-                *ppFnd1 = reinterpret_cast<SfxPoolItem*>(-1);
+                *ppFnd1 = INVALID_POOL_ITEM;
             }
         }
         else
@@ -1240,7 +1240,7 @@ static void MergeItem_Impl( SfxItemPool *_pPool, sal_uInt16 &rCount,
             {
                 // Decision table: set, set, !=, doesn't matter
                 _pPool->Remove( **ppFnd1 );
-                *ppFnd1 = reinterpret_cast<SfxPoolItem*>(-1);
+                *ppFnd1 = INVALID_POOL_ITEM;
             }
         }
     }
@@ -1330,15 +1330,15 @@ void SfxItemSet::InvalidateItem( sal_uInt16 nWhich )
 
             if( *ppFnd ) // Set for me
             {
-                if( reinterpret_cast<SfxPoolItem*>(-1) != *ppFnd ) // Not yet dontcare!
+                if( !IsInvalidItem(*ppFnd) )
                 {
                     m_pPool->Remove( **ppFnd );
-                    *ppFnd = reinterpret_cast<SfxPoolItem*>(-1);
+                    *ppFnd = INVALID_POOL_ITEM;
                 }
             }
             else
             {
-                *ppFnd = reinterpret_cast<SfxPoolItem*>(-1);
+                *ppFnd = INVALID_POOL_ITEM;
                 ++m_nCount;
             }
             break;
@@ -1825,7 +1825,7 @@ const SfxPoolItem* SfxAllItemSet::Put( const SfxPoolItem& rItem, sal_uInt16 nWhi
     // Remember old Item
     bool bIncrementCount = false;
     const SfxPoolItem* pOld = *( m_pItems + nPos );
-    if ( reinterpret_cast< SfxPoolItem* >( -1 ) == pOld ) // state "dontcare"
+    if ( IsInvalidItem(pOld) ) // state "dontcare"
         pOld = nullptr;
     if ( !pOld )
     {
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index 53a439c..66b4490 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1908,7 +1908,7 @@ bool SwTextNode::SetAttr(
 
     do
     {
-        if ( pItem && (reinterpret_cast<SfxPoolItem*>(-1) != pItem))
+        if ( pItem && !IsInvalidItem(pItem) )
         {
             const sal_uInt16 nWhich = pItem->Which();
             OSL_ENSURE( isCHRATR(nWhich) || isTXTATR(nWhich),
@@ -2201,7 +2201,7 @@ bool SwTextNode::GetAttr( SfxItemSet& rSet, sal_Int32 nStt, sal_Int32 nEnd,
                                     if( nAttrStart > nStt )
                                     {
                                         rSet.InvalidateItem( nHintWhich );
-                                        pPrev->mpItem = reinterpret_cast<SfxPoolItem*>(-1);
+                                        pPrev->mpItem = INVALID_POOL_ITEM;
                                     }
                                     else
                                     {
@@ -2210,7 +2210,7 @@ bool SwTextNode::GetAttr( SfxItemSet& rSet, sal_Int32 nStt, sal_Int32 nEnd,
                                     }
                                 }
                             }
-                            else if( reinterpret_cast<SfxPoolItem*>(-1) != pPrev->mpItem )
+                            else if( !IsInvalidItem(pPrev->mpItem) )
                             {
                                 if( pPrev->mnEndPos == nAttrStart &&
                                     *pPrev->mpItem == *pItem )
@@ -2221,7 +2221,7 @@ bool SwTextNode::GetAttr( SfxItemSet& rSet, sal_Int32 nStt, sal_Int32 nEnd,
                                 else
                                 {
                                     rSet.InvalidateItem( nHintWhich );
-                                    pPrev->mpItem = reinterpret_cast<SfxPoolItem*>(-1);
+                                    pPrev->mpItem = INVALID_POOL_ITEM;
                                 }
                             }
                         }
@@ -2237,7 +2237,7 @@ bool SwTextNode::GetAttr( SfxItemSet& rSet, sal_Int32 nStt, sal_Int32 nEnd,
                 for (size_t n = 0; n < coArrSz; ++n)
                 {
                     const SwPoolItemEndPair& rItemPair = (*pAttrArr)[ n ];
-                    if( (nullptr != rItemPair.mpItem) && (reinterpret_cast<SfxPoolItem*>(-1) != rItemPair.mpItem) )
+                    if( rItemPair.mpItem && !IsInvalidItem(rItemPair.mpItem) )
                     {
                         const sal_uInt16 nWh =
                             static_cast<sal_uInt16>(n + RES_CHRATR_BEGIN);


More information about the Libreoffice-commits mailing list