Make GetItemSurrogatesForItem return a value, instead of using an out argument

Change-Id: I9f54cf6a016d3f01ae37de5c6429cb0c585b9a04
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185732
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
This commit is contained in:
Mike Kaganski
2025-05-24 12:50:26 +05:00
parent 8dd04408a9
commit 451776bc90
6 changed files with 61 additions and 68 deletions

View File

@ -324,8 +324,8 @@ public:
ItemSurrogates GetItemSurrogates(sal_uInt16 nWhich) const;
// special version for read-only itemSurrogates for NameOrIndex Items
void GetItemSurrogatesForItem(ItemSurrogates& rTarget, const SfxPoolItem& rItem) const;
void GetItemSurrogatesForItem(ItemSurrogates& rTarget, SfxItemType eItemType) const;
ItemSurrogates GetItemSurrogatesForItem(const SfxPoolItem& rItem) const;
ItemSurrogates GetItemSurrogatesForItem(SfxItemType eItemType) const;
sal_uInt16 GetFirstWhich() const { return mnStart; }
sal_uInt16 GetLastWhich() const { return mnEnd; }

View File

@ -882,23 +882,24 @@ void SfxItemPool::iterateItemSurrogates(
}
}
void SfxItemPool::GetItemSurrogatesForItem(ItemSurrogates& rTarget, SfxItemType eItemType) const
ItemSurrogates SfxItemPool::GetItemSurrogatesForItem(SfxItemType eItemType) const
{
rTarget.clear();
ItemSurrogates aTarget;
const registeredNameOrIndex& rRegistered(GetMasterPool()->maRegisteredNameOrIndex);
registeredNameOrIndex::const_iterator aHit(rRegistered.find(eItemType));
if (aHit != rRegistered.end())
{
rTarget.reserve(aHit->second.size());
aTarget.reserve(aHit->second.size());
for (const auto& entry : aHit->second)
rTarget.push_back(entry.first);
aTarget.push_back(entry.first);
}
return aTarget;
}
void SfxItemPool::GetItemSurrogatesForItem(ItemSurrogates& rTarget, const SfxPoolItem& rItem) const
ItemSurrogates SfxItemPool::GetItemSurrogatesForItem(const SfxPoolItem& rItem) const
{
assert(rItem.isNameOrIndex() && "ITEM: only Items derived from NameOrIndex supported for this mechanism (!)");
GetItemSurrogatesForItem(rTarget, rItem.ItemType());
return GetItemSurrogatesForItem(rItem.ItemType());
}
ItemSurrogates SfxItemPool::GetItemSurrogates(sal_uInt16 nWhich) const

View File

@ -289,9 +289,7 @@ static bool getByNameFromPool( std::u16string_view rSearchName, SfxItemPool cons
{
if (pPool)
{
ItemSurrogates aSurrogates;
pPool->GetItemSurrogatesForItem(aSurrogates, eItemType);
for (const SfxPoolItem* p : aSurrogates)
for (const SfxPoolItem* p : pPool->GetItemSurrogatesForItem(eItemType))
{
const NameOrIndex *pItem = static_cast<const NameOrIndex*>(p);
@ -335,9 +333,7 @@ uno::Any SAL_CALL SvxUnoMarkerTable::getByName( const OUString& aApiName )
static void createNamesForPool( SfxItemPool const * pPool, SfxItemType eItemType, std::set< OUString >& rNameSet )
{
ItemSurrogates aSurrogates;
pPool->GetItemSurrogatesForItem(aSurrogates, eItemType);
for (const SfxPoolItem* p : aSurrogates)
for (const SfxPoolItem* p : pPool->GetItemSurrogatesForItem(eItemType))
{
const NameOrIndex* pItem = static_cast<const NameOrIndex*>(p);
@ -378,9 +374,9 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasByName( const OUString& aName )
aSearchName = SvxUnogetInternalNameForItem(XATTR_LINESTART, aName);
if (mpModelPool)
{
ItemSurrogates aSurrogates;
mpModelPool->GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineStartItemType); // XATTR_LINESTART
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINESTART
for (const SfxPoolItem* p :
mpModelPool->GetItemSurrogatesForItem(SfxItemType::XLineStartItemType))
{
pItem = static_cast<const NameOrIndex*>(p);
if( pItem && pItem->GetName() == aSearchName )
@ -391,9 +387,9 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasByName( const OUString& aName )
aSearchName = SvxUnogetInternalNameForItem(XATTR_LINEEND, aName);
if (mpModelPool)
{
ItemSurrogates aSurrogates;
mpModelPool->GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineEndItemType); // XATTR_LINEEND
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINEEND
for (const SfxPoolItem* p :
mpModelPool->GetItemSurrogatesForItem(SfxItemType::XLineEndItemType))
{
pItem = static_cast<const NameOrIndex*>(p);
if( pItem && pItem->GetName() == aSearchName )
@ -418,9 +414,9 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasElements( )
if (mpModelPool)
{
ItemSurrogates aSurrogates;
mpModelPool->GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineStartItemType); // XATTR_LINESTART
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINESTART
for (const SfxPoolItem* p :
mpModelPool->GetItemSurrogatesForItem(SfxItemType::XLineStartItemType))
{
pItem = static_cast<const NameOrIndex*>(p);
if( pItem && !pItem->GetName().isEmpty() )
@ -430,9 +426,9 @@ sal_Bool SAL_CALL SvxUnoMarkerTable::hasElements( )
if (mpModelPool)
{
ItemSurrogates aSurrogates;
mpModelPool->GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineEndItemType); // XATTR_LINEEND
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINEEND
for (const SfxPoolItem* p :
mpModelPool->GetItemSurrogatesForItem(SfxItemType::XLineEndItemType))
{
pItem = static_cast<const NameOrIndex*>(p);
if( pItem && !pItem->GetName().isEmpty() )

View File

@ -1435,9 +1435,7 @@ bool SvxShape::SetFillAttribute( sal_uInt16 nWID, const OUString& rName, SfxItem
case XATTR_LINEDASH: eItemType = SfxItemType::XLineDashItemType; break;
default: assert(false); abort();
}
ItemSurrogates aSurrogates;
rSet.GetPool()->GetItemSurrogatesForItem(aSurrogates, eItemType);
for (const SfxPoolItem* p : aSurrogates)
for (const SfxPoolItem* p : rSet.GetPool()->GetItemSurrogatesForItem(eItemType))
{
const NameOrIndex* pItem = static_cast<const NameOrIndex*>(p);
if( pItem->GetName() == aName )

View File

@ -145,10 +145,8 @@ OUString NameOrIndex::CheckNamedItem(const sal_uInt16 nWhich, const SfxItemPool*
if (!aUniqueName.isEmpty() && pPool1)
{
ItemSurrogates aSurrogates;
// use special version to get buffered NameOrIndex Items
pPool1->GetItemSurrogatesForItem(aSurrogates, *this);
for (const SfxPoolItem* pItem : aSurrogates)
for (const SfxPoolItem* pItem : pPool1->GetItemSurrogatesForItem(*this))
{
const NameOrIndex *pNameOrIndex = static_cast<const NameOrIndex*>(pItem);
@ -234,10 +232,8 @@ OUString NameOrIndex::CheckNamedItem(const sal_uInt16 nWhich, const SfxItemPool*
if (aUniqueName.isEmpty() && pPool1)
{
ItemSurrogates aSurrogates;
// use special version to get buffered NameOrIndex Items
pPool1->GetItemSurrogatesForItem(aSurrogates, *this);
for (const SfxPoolItem* pItem : aSurrogates)
for (const SfxPoolItem* pItem : pPool1->GetItemSurrogatesForItem(*this))
{
const NameOrIndex *pNameOrIndex = static_cast<const NameOrIndex*>(pItem);
@ -1254,9 +1250,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel& rM
const SfxItemPool& rPool1 = rModel.GetItemPool();
if (!aUniqueName.isEmpty())
{
ItemSurrogates aSurrogates;
rPool1.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineStartItemType); // XATTR_LINESTART
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINESTART
for (const SfxPoolItem* p :
rPool1.GetItemSurrogatesForItem(SfxItemType::XLineStartItemType))
{
auto pItem = static_cast<const XLineStartItem*>(p);
@ -1276,8 +1272,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel& rM
if( !bForceNew )
{
rPool1.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineEndItemType); // XATTR_LINEEND
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINEEND
for (const SfxPoolItem* p :
rPool1.GetItemSurrogatesForItem(SfxItemType::XLineEndItemType))
{
auto pItem = static_cast<const XLineEndItem*>(p);
@ -1300,9 +1297,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel& rM
const SfxItemPool* pPool2 = rModel.GetStyleSheetPool() ? &rModel.GetStyleSheetPool()->GetPool() : nullptr;
if( !aUniqueName.isEmpty() && pPool2)
{
ItemSurrogates aSurrogates;
pPool2->GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineStartItemType); // XATTR_LINESTART
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINESTART
for (const SfxPoolItem* p :
pPool2->GetItemSurrogatesForItem(SfxItemType::XLineStartItemType))
{
auto pItem = static_cast<const XLineStartItem*>(p);
@ -1322,8 +1319,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel& rM
if( !bForceNew )
{
pPool2->GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineEndItemType); // XATTR_LINEEND
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINEEND
for (const SfxPoolItem* p :
pPool2->GetItemSurrogatesForItem(SfxItemType::XLineEndItemType))
{
auto pItem = static_cast<const XLineEndItem*>(p);
@ -1352,9 +1350,9 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel& rM
sal_Int32 nUserIndex = 1;
const OUString aUser(SvxResId(RID_SVXSTR_LINEEND));
ItemSurrogates aSurrogates;
rPool1.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineStartItemType); // XATTR_LINESTART
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINESTART
for (const SfxPoolItem* p :
rPool1.GetItemSurrogatesForItem(SfxItemType::XLineStartItemType))
{
auto pItem = static_cast<const XLineStartItem*>(p);
@ -1376,8 +1374,8 @@ std::unique_ptr<XLineStartItem> XLineStartItem::checkForUniqueItem( SdrModel& rM
}
}
rPool1.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineEndItemType); // XATTR_LINEEND
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINEEND
for (const SfxPoolItem* p : rPool1.GetItemSurrogatesForItem(SfxItemType::XLineEndItemType))
{
auto pItem = static_cast<const XLineEndItem*>(p);
@ -1499,9 +1497,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel& rModel
const SfxItemPool& rPool1 = rModel.GetItemPool();
if (!aUniqueName.isEmpty())
{
ItemSurrogates aSurrogates;
rPool1.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineStartItemType); // XATTR_LINESTART
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINESTART
for (const SfxPoolItem* p :
rPool1.GetItemSurrogatesForItem(SfxItemType::XLineStartItemType))
{
auto pItem = static_cast<const XLineStartItem*>(p);
@ -1521,8 +1519,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel& rModel
if( !bForceNew )
{
rPool1.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineEndItemType); // XATTR_LINEEND
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINEEND
for (const SfxPoolItem* p :
rPool1.GetItemSurrogatesForItem(SfxItemType::XLineEndItemType))
{
auto pItem = static_cast<const XLineEndItem*>(p);
@ -1545,9 +1544,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel& rModel
const SfxItemPool* pPool2 = rModel.GetStyleSheetPool() ? &rModel.GetStyleSheetPool()->GetPool() : nullptr;
if( !aUniqueName.isEmpty() && pPool2)
{
ItemSurrogates aSurrogates;
pPool2->GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineStartItemType); // XATTR_LINESTART
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINESTART
for (const SfxPoolItem* p :
pPool2->GetItemSurrogatesForItem(SfxItemType::XLineStartItemType))
{
auto pItem = static_cast<const XLineStartItem*>(p);
@ -1567,8 +1566,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel& rModel
if( !bForceNew )
{
pPool2->GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineEndItemType); // XATTR_LINEEND
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINEEND
for (const SfxPoolItem* p :
pPool2->GetItemSurrogatesForItem(SfxItemType::XLineEndItemType))
{
auto pItem = static_cast<const XLineEndItem*>(p);
@ -1597,9 +1597,9 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel& rModel
sal_Int32 nUserIndex = 1;
const OUString aUser(SvxResId(RID_SVXSTR_LINEEND));
ItemSurrogates aSurrogates;
rPool1.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineStartItemType); // XATTR_LINESTART
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINESTART
for (const SfxPoolItem* p :
rPool1.GetItemSurrogatesForItem(SfxItemType::XLineStartItemType))
{
auto pItem = static_cast<const XLineStartItem*>(p);
@ -1621,8 +1621,8 @@ std::unique_ptr<XLineEndItem> XLineEndItem::checkForUniqueItem( SdrModel& rModel
}
}
rPool1.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XLineEndItemType); // XATTR_LINEEND
for (const SfxPoolItem* p : aSurrogates)
// XATTR_LINEEND
for (const SfxPoolItem* p : rPool1.GetItemSurrogatesForItem(SfxItemType::XLineEndItemType))
{
auto pItem = static_cast<const XLineEndItem*>(p);

View File

@ -1412,9 +1412,7 @@ void RtfExport::OutColorTable()
}
// TextFrame or paragraph background solid fill.
ItemSurrogates aSurrogates;
rPool.GetItemSurrogatesForItem(aSurrogates, SfxItemType::XFillColorItemType);
for (const SfxPoolItem* pItem : aSurrogates)
for (const SfxPoolItem* pItem : rPool.GetItemSurrogatesForItem(SfxItemType::XFillColorItemType))
{
const auto& rColorItem = static_cast<const XFillColorItem&>(*pItem);
InsColor(rColorItem.GetColorValue());