Kaydet (Commit) f6f32e8e authored tarafından Jan Holesovsky's avatar Jan Holesovsky

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
üst 6be5ed60
......@@ -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)
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment