Implemented FormulaTokneRef using boost::intrusive_ptr.

This commit is contained in:
Kohei Yoshida
2010-12-21 17:41:33 -05:00
parent c631cf94e4
commit c4b7910c12
4 changed files with 21 additions and 11 deletions

View File

@@ -331,7 +331,7 @@ private:
static inline void ForceArrayOperator( FormulaTokenRef& rCurr, const FormulaTokenRef& rPrev )
{
if ( rPrev.Is() && rPrev->HasForceArray() &&
if ( rPrev && rPrev->HasForceArray() &&
rCurr->GetType() == svByte && rCurr->GetOpCode() != ocPush
&& !rCurr->HasForceArray() )
rCurr->SetForceArray( true);

View File

@@ -33,11 +33,12 @@
#include <string.h>
#include <vector>
#include "formula/opcode.hxx"
#include "formula/intruref.hxx"
#include <tools/mempool.hxx>
#include "formula/IFunctionDescription.hxx"
#include "formula/formuladllapi.h"
#include <boost/intrusive_ptr.hpp>
namespace formula
{
@@ -85,9 +86,8 @@ typedef StackVarEnum StackVar;
class FormulaToken;
typedef SimpleIntrusiveReference< class FormulaToken > FormulaTokenRef;
typedef SimpleIntrusiveReference< const class FormulaToken > FormulaConstTokenRef;
typedef ::boost::intrusive_ptr<FormulaToken> FormulaTokenRef;
typedef ::boost::intrusive_ptr<const FormulaToken> FormulaConstTokenRef;
class FORMULA_DLLPUBLIC FormulaToken : public IFormulaToken
{
@@ -179,6 +179,16 @@ public:
{ return GetStrLenBytes( rStr.Len() ); }
};
inline void intrusive_ptr_add_ref(const FormulaToken* p)
{
p->IncRef();
}
inline void intrusive_ptr_release(const FormulaToken* p)
{
p->DecRef();
}
class FORMULA_DLLPUBLIC FormulaByteToken : public FormulaToken
{
private:

View File

@@ -859,11 +859,11 @@ BOOL FormulaCompiler::GetToken()
if ( nWasColRowName )
nWasColRowName++;
if ( bAutoCorrect && !pStack )
CreateStringFromToken( aCorrectedFormula, pToken, FALSE );
CreateStringFromToken( aCorrectedFormula, pToken.get(), FALSE );
pToken = pArr->Next();
}
if ( bAutoCorrect && !pStack && pToken )
CreateStringFromToken( aCorrectedSymbol, pToken, FALSE );
CreateStringFromToken( aCorrectedSymbol, pToken.get(), FALSE );
if( !pToken )
{
if( pStack )
@@ -1401,7 +1401,7 @@ bool FormulaCompiler::MergeRangeReference(FormulaToken * * const pCode1, Formula
p->IncRef();
p1->DecRef();
p2->DecRef();
*pCode1 = p;
*pCode1 = p.get();
--pCode, --pc;
pArr->nRefs--;
@@ -1840,7 +1840,7 @@ void FormulaCompiler::PutCode( FormulaTokenRef& p )
{
p = new FormulaByteToken( ocStop );
p->IncRef();
*pCode++ = p;
*pCode++ = p.get();
++pc;
}
SetError(errCodeOverflow);
@@ -1850,7 +1850,7 @@ void FormulaCompiler::PutCode( FormulaTokenRef& p )
return;
ForceArrayOperator( p, pCurrentFactorToken);
p->IncRef();
*pCode++ = p;
*pCode++ = p.get();
pc++;
}

View File

@@ -263,7 +263,7 @@ BOOL FormulaByteToken::operator==( const FormulaToken& r ) const
}
FormulaToken* FormulaFAPToken::GetFAPOrigToken() const { return pOrigToken; }
FormulaToken* FormulaFAPToken::GetFAPOrigToken() const { return pOrigToken.get(); }
BOOL FormulaFAPToken::operator==( const FormulaToken& r ) const
{
return FormulaByteToken::operator==( r ) && pOrigToken == r.GetFAPOrigToken();