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 ) 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->GetType() == svByte && rCurr->GetOpCode() != ocPush
&& !rCurr->HasForceArray() ) && !rCurr->HasForceArray() )
rCurr->SetForceArray( true); rCurr->SetForceArray( true);

View File

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

View File

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