include/svl/itemset.hxx |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

New commits:
commit 6849b3a1593f56790ad22a050d60ec15333ce9af
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Feb 28 09:20:04 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Feb 28 10:21:00 2022 +0100

    checked signedness of Sfx*IntItem types (part2)
    
    See comments here
    https://lists.freedesktop.org/archives/libreoffice/2022-January/088360.html
    
    Make SfxItemSet::GetItemState check the type of the ppItem pointer
    using TypedWhichId the same way we do for other calls.
    
    Take the opportunity to name the new method GetItemIfSet and change
    the signature to reduce the boilerplate at call sites..
    
    This is just the initial commit, the bulk of the patch (the actual usage)
    will be split into lots of smaller patches to aid bisecting for
    bugs.
    
    Change-Id: I6704059331787c8776f786af764b4ba3478a307b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128908
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 8d5b9c3bb601..7b535fb93d6f 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -147,7 +147,27 @@ public:
                                                 bool bSrchInParent = true,
                                                 const SfxPoolItem **ppItem = 
nullptr ) const;
 
+    template <class T>
+    SfxItemState                GetItemState(   TypedWhichId<T> nWhich,
+                                                bool bSrchInParent = true,
+                                                const T **ppItem = nullptr ) 
const
+    { return GetItemState(sal_uInt16(nWhich), bSrchInParent, 
reinterpret_cast<SfxPoolItem const**>(ppItem)); }
+
+    /// Templatized version of GetItemState() to directly return the correct 
type.
+    template<class T>
+    const T *                   GetItemIfSet(   TypedWhichId<T> nWhich,
+                                                bool bSrchInParent = true ) 
const
+    {
+        const SfxPoolItem * pItem = nullptr;
+        if( SfxItemState::SET == GetItemState(sal_uInt16(nWhich), 
bSrchInParent, &pItem) )
+            return static_cast<const T*>(pItem);
+        return nullptr;
+    }
+
     bool                        HasItem(sal_uInt16 nWhich, const SfxPoolItem** 
ppItem = nullptr) const;
+    template<class T>
+    bool                        HasItem(TypedWhichId<T> nWhich, const T** 
ppItem = nullptr) const
+    { return HasItem(sal_uInt16(nWhich), reinterpret_cast<const 
SfxPoolItem**>(ppItem)); }
 
     void                        DisableItem(sal_uInt16 nWhich);
     void                        InvalidateItem( sal_uInt16 nWhich );

Reply via email to