summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2015-10-19 08:43:28 +0200
committerJan Holesovsky <kendy@collabora.com>2015-10-19 10:14:03 +0200
commitf6f32e8eabb2e09fbe2b70dfb540bb1ea1ee75a9 (patch)
treec209bbe8553133fc32bb986473795f2441517f48
parent6be5ed60e1823d909511c6af48e6bdc2817cce7c (diff)
sfx items: Get rid of the TypeId check, nobody uses that any more.
And introduce the appropriate assert() in the templatized version instead. Change-Id: I3e5b01e5e5ee49049fa6f35e3d05ef65a1890dc1
-rw-r--r--include/svl/itemset.hxx20
-rw-r--r--svl/source/items/itemset.cxx35
2 files changed, 19 insertions, 36 deletions
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 7520d0de5fb6..a070eab2dfc1 100644
--- a/include/svl/itemset.hxx
+++ b/include/svl/itemset.hxx
@@ -80,16 +80,26 @@ public:
sal_uInt16 TotalCount() const;
const SfxPoolItem& Get( sal_uInt16 nWhich, bool bSrchInParent = true ) const;
- const SfxPoolItem* GetItem( sal_uInt16 nWhich, bool bSearchInParent = true,
- TypeId aItemType = 0 ) const;
- /// Templatized version to directly return the correct type.
+ /** This method eases accessing single Items in the SfxItemSet.
+
+ @param nId SlotId or the Item's WhichId
+ @param bSearchInParent also search in parent ItemSets
+ @returns 0 if the ItemSet does not contain an Item with the Id 'nWhich'
+ */
+ const SfxPoolItem* GetItem(sal_uInt16 nWhich, bool bSearchInParent = true) const;
+
+ /// Templatized version of GetItem() to directly return the correct type.
template<class T> const T* GetItem(sal_uInt16 nWhich, bool bSearchInParent = true) const
{
- return dynamic_cast<const T*>(GetItem(nWhich, bSearchInParent));
+ const SfxPoolItem* pItem = GetItem(nWhich, bSearchInParent);
+ const T* pCastedItem = dynamic_cast<const T*>(pItem);
+
+ assert(!pItem || pCastedItem); // if it exists, must have the correct type
+ return pCastedItem;
}
- /// Templatized static version to directly return the correct type if the SfxItemSet is available.
+ /// Templatized static version of GetItem() to directly return the correct type if the SfxItemSet is available.
template<class T> static const T* GetItem(const SfxItemSet* pItemSet, sal_uInt16 nWhich, bool bSearchInParent = true)
{
if (pItemSet)
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index d9363c14b725..1e72cf67e21e 100644
--- a/svl/source/items/itemset.cxx
+++ b/svl/source/items/itemset.cxx
@@ -812,47 +812,20 @@ bool SfxItemSet::Set
return bRet;
}
-/**
- * This method eases accessing single Items in the SfxItemSet.
- * Type checking is done via assertion, which makes client code
- * much more readable.
- *
- * The PRODUCT version returns 0, if the Item found is not of the
- * specified class.
- *
- * @returns 0 if the ItemSet does not contain an Item with the Id 'nWhich'
- */
-const SfxPoolItem* SfxItemSet::GetItem
-(
- sal_uInt16 nId, // SlotId or the Item's WhichId
- bool bSrchInParent, // sal_True: also search in Parent ItemSets
- TypeId aItemType // != 0 => RTTI check using assertion
-) const
+const SfxPoolItem* SfxItemSet::GetItem(sal_uInt16 nId, bool bSearchInParent) const
{
// Convert to WhichId
sal_uInt16 nWhich = GetPool()->GetWhich(nId);
// Is the Item set or 'bDeep == true' available?
const SfxPoolItem *pItem = 0;
- SfxItemState eState = GetItemState( nWhich, bSrchInParent, &pItem );
- if ( bSrchInParent && SfxItemState::DEFAULT == eState &&
- nWhich <= SFX_WHICH_MAX )
+ SfxItemState eState = GetItemState(nWhich, bSearchInParent, &pItem);
+ if (bSearchInParent && SfxItemState::DEFAULT == eState && nWhich <= SFX_WHICH_MAX)
{
pItem = &m_pPool->GetDefaultItem(nWhich);
}
- if ( pItem )
- {
- // Does the type match?
- if ( !aItemType || pItem->IsA(aItemType) )
- return pItem;
-
- // Else report error
- assert(!"invalid argument type");
- }
-
- // No Item of wrong type found
- return 0;
+ return pItem;
}
const SfxPoolItem& SfxItemSet::Get( sal_uInt16 nWhich, bool bSrchInParent) const