Kohei,
Help!
From calc/sc/inc/rangelst.hxx:
typedef ScRange* ScRangePtr;
typedef ::std::vector< ScRangePtr > ScRangeListBase;
class SC_DLLPUBLIC ScRangeList : public ScRangeListBase, public SvRefBase { ... }
I'm changing the definition of ScRangeListBase from a DECLARE_LIST() to a ::std:vector<>. For the
most part the change is going well; however, we have a method in the class named "Join" that looks
like it's trying to merge two lists together.
My issues are related to nOldPos:
1) I might need to write code to do the GetPos(); this just returns the Index to the address given.
This is easy and not a big concern.
2) The Remove( nOldPos ) can be replaced with an erase( begin() + nOldPos ); however, at this point
I believe that it's removing the object because it's in both lists (they have the same address).
I'm thinking that destroying one instance will destroy the 2nd which would make this code
incorrect. (I know, it's been working for years; I just don't see how).
3) Why is this recursive? This my have something to do with ScRange acting like a ScRangeList;
which is my next task to find out why.
4) All the comments being in German isn't helping...
5) I'm thinking the Seek() is related to updating the position for the List iterator. vector<> uses
a different iterator process so this can be removed; however, do I need to do something to update
the vector<>'s iterator?
The code in question is calc/sc/core/tool/rangelst.cxx:
void ScRangeList::Join( const ScRange& r, bool bIsInList )
{
if ( empty() )
{
Append( r );
return ;
}
SCCOL nCol1 = r.aStart.Col();
SCROW nRow1 = r.aStart.Row();
SCTAB nTab1 = r.aStart.Tab();
SCCOL nCol2 = r.aEnd.Col();
SCROW nRow2 = r.aEnd.Row();
SCTAB nTab2 = r.aEnd.Tab();
ScRangePtr pOver = (ScRangePtr) &r; // fies aber wahr wenn bInList
size_t nOldPos = 0;
if ( bIsInList )
{ // merken um ggbf. zu loeschen bzw. wiederherzustellen
nOldPos = GetPos( pOver );
}
bool bJoinedInput = false;
size_t nRanges = size();
for ( size_t i = 0; i < nRanges; ++i )
{
ScRangePtr p = at( i );
if ( p == pOver )
continue; // derselbe, weiter mit dem naechsten
bool bJoined = false;
if ( p->In( r ) )
{ // Range r in Range p enthalten oder identisch
if ( bIsInList )
bJoined = true; // weg mit Range r
else
{ // das war's dann
bJoinedInput = true; // nicht anhaengen
break; // for
}
}
else if ( r.In( *p ) )
{ // Range p in Range r enthalten, r zum neuen Range machen
*p = r;
bJoined = true;
}
if ( !bJoined && p->aStart.Tab() == nTab1 && p->aEnd.Tab() == nTab2 )
{ // 2D
if ( p->aStart.Col() == nCol1 && p->aEnd.Col() == nCol2 )
{
if ( p->aStart.Row() == nRow2+1 )
{ // oben
p->aStart.SetRow( nRow1 );
bJoined = true;
}
else if ( p->aEnd.Row() == nRow1-1 )
{ // unten
p->aEnd.SetRow( nRow2 );
bJoined = true;
}
}
else if ( p->aStart.Row() == nRow1 && p->aEnd.Row() == nRow2 )
{
if ( p->aStart.Col() == nCol2+1 )
{ // links
p->aStart.SetCol( nCol1 );
bJoined = true;
}
else if ( p->aEnd.Col() == nCol1-1 )
{ // rechts
p->aEnd.SetCol( nCol2 );
bJoined = true;
}
}
}
if ( bJoined )
{
if ( bIsInList )
{ // innerhalb der Liste Range loeschen
Remove( nOldPos );
delete pOver;
pOver = NULL;
if ( nOldPos )
nOldPos--; // Seek richtig aufsetzen
}
bJoinedInput = true;
Join( *p, true ); // rekursiv!
}
}
if ( bIsInList )
Seek( nOldPos );
else if ( !bJoinedInput )
Append( r );
}
Joe P
PS: We have a 2nd Join for the PairLIst that looks the same.
Context
- [Libreoffice] Help on removing a DECLARE_LIST() · Joseph Powers
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.