Bug 210528: Modernize XPath-classes to use nsAutoPtr

r=Pike sr=jst
This commit is contained in:
sicking%bigfoot.com 2003-06-30 18:44:22 +00:00
Родитель ae5826b6f6
Коммит eb53572f85
17 изменённых файлов: 101 добавлений и 184 удалений

Просмотреть файл

@ -38,16 +38,13 @@
/**
* Creates a new AdditiveExpr using the given operator
**/
AdditiveExpr::AdditiveExpr(Expr* leftExpr, Expr* rightExpr, short op) {
this->op = op;
this->leftExpr = leftExpr;
this->rightExpr = rightExpr;
} //-- AdditiveExpr
AdditiveExpr::~AdditiveExpr() {
delete leftExpr;
delete rightExpr;
} //-- ~AdditiveExpr
AdditiveExpr::AdditiveExpr(nsAutoPtr<Expr> aLeftExpr,
nsAutoPtr<Expr> aRightExpr, short aOp)
: op(aOp),
leftExpr(aLeftExpr),
rightExpr(aRightExpr)
{
}
/**
* Evaluates this Expr based on the given context node and processor state

Просмотреть файл

@ -31,11 +31,6 @@
#include "ExprResult.h"
#include "txIXPathContext.h"
/**
* Create a new AttributeValueTemplate
**/
AttributeValueTemplate::AttributeValueTemplate() {};
/**
* Default destructor
**/
@ -49,8 +44,15 @@ AttributeValueTemplate::~AttributeValueTemplate() {
/**
* Adds the given Expr to this AttributeValueTemplate
**/
void AttributeValueTemplate::addExpr(Expr* expr) {
if (expr) expressions.add(expr);
nsresult
AttributeValueTemplate::addExpr(nsAutoPtr<Expr> aExpr)
{
nsresult rv = expressions.add(aExpr);
NS_ENSURE_SUCCESS(rv, rv);
aExpr.forget();
return NS_OK;
} //-- addExpr
/**

Просмотреть файл

@ -41,15 +41,12 @@
/**
* Creates a new BooleanExpr using the given operator
**/
BooleanExpr::BooleanExpr(Expr* leftExpr, Expr* rightExpr, short op) {
this->op = op;
this->leftExpr = leftExpr;
this->rightExpr = rightExpr;
} //-- BooleanExpr
BooleanExpr::~BooleanExpr() {
delete leftExpr;
delete rightExpr;
BooleanExpr::BooleanExpr(nsAutoPtr<Expr> aLeftExpr,
nsAutoPtr<Expr> aRightExpr, short aOp)
: op(aOp),
leftExpr(aLeftExpr),
rightExpr(aRightExpr)
{
} //-- ~BooleanExpr
/**

Просмотреть файл

@ -119,7 +119,7 @@ public:
* Adds the given parameter to this FunctionCall's parameter list
* @param expr the Expr to add to this FunctionCall's parameter list
**/
nsresult addParam(Expr* aExpr);
nsresult addParam(nsAutoPtr<Expr> aExpr);
/**
* Check if the number of parameters falls within a range.
@ -140,8 +140,6 @@ protected:
txList params;
FunctionCall();
/*
* Evaluates the given Expression and converts its result to a String.
* The value is appended to the given destination String
@ -179,15 +177,12 @@ protected:
class AttributeValueTemplate: public Expr {
public:
AttributeValueTemplate();
virtual ~AttributeValueTemplate();
/**
* Adds the given Expr to this AttributeValueTemplate
**/
void addExpr(Expr* expr);
nsresult addExpr(nsAutoPtr<Expr> expr);
TX_DECL_EXPR;
@ -232,11 +227,8 @@ public:
txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID,
Node::NodeType aNodeType);
~txNameTest();
TX_DECL_NODE_TEST;
private:
nsCOMPtr<nsIAtom> mPrefix;
nsCOMPtr<nsIAtom> mLocalName;
PRInt32 mNamespace;
@ -261,8 +253,6 @@ public:
*/
txNodeTypeTest(NodeType aNodeType);
~txNodeTypeTest();
/*
* Sets the name of the node to match. Only availible for pi nodes
*/
@ -282,11 +272,6 @@ private:
class PredicateList {
public:
/**
* Creates a new PredicateList
**/
PredicateList();
/**
* Destructor, will delete all Expressions in the list, so remove
* any you may need
@ -297,7 +282,7 @@ public:
* Adds the given Expr to the list
* @param expr the Expr to add to the list
**/
void add(Expr* expr);
nsresult add(nsAutoPtr<Expr> aExpr);
nsresult evaluatePredicates(NodeSet* aNodes, txIMatchContext* aContext);
@ -373,17 +358,12 @@ public:
* Creates a new FilterExpr using the given Expr
* @param expr the Expr to use for evaluation
**/
FilterExpr(Expr* aExpr);
/**
* Destructor, will delete all predicates and the given Expr
**/
virtual ~FilterExpr();
FilterExpr(nsAutoPtr<Expr> aExpr);
TX_DECL_EXPR;
private:
Expr* expr;
nsAutoPtr<Expr> expr;
}; //-- FilterExpr
@ -413,15 +393,15 @@ public:
//-- LF, changed from static const short to enum
enum _AdditiveExprType { ADDITION = 1, SUBTRACTION };
AdditiveExpr(Expr* leftExpr, Expr* rightExpr, short op);
~AdditiveExpr();
AdditiveExpr(nsAutoPtr<Expr> aLeftExpr, nsAutoPtr<Expr> aRightExpr,
short aOp);
TX_DECL_EXPR;
private:
short op;
Expr* leftExpr;
Expr* rightExpr;
nsAutoPtr<Expr> leftExpr;
nsAutoPtr<Expr> rightExpr;
}; //-- AdditiveExpr
/**
@ -431,13 +411,12 @@ class UnaryExpr : public Expr {
public:
UnaryExpr(Expr* expr);
~UnaryExpr();
UnaryExpr(nsAutoPtr<Expr> aExpr);
TX_DECL_EXPR;
private:
Expr* expr;
nsAutoPtr<Expr> expr;
}; //-- UnaryExpr
/**
@ -451,15 +430,15 @@ public:
//-- BooleanExpr Types
enum _BooleanExprType { AND = 1, OR };
BooleanExpr(Expr* leftExpr, Expr* rightExpr, short op);
~BooleanExpr();
BooleanExpr(nsAutoPtr<Expr> aLeftExpr, nsAutoPtr<Expr> aRightExpr,
short aOp);
TX_DECL_EXPR;
private:
short op;
Expr* leftExpr;
Expr* rightExpr;
nsAutoPtr<Expr> leftExpr;
nsAutoPtr<Expr> rightExpr;
}; //-- BooleanExpr
/**
@ -478,15 +457,15 @@ public:
//-- LF, changed from static const short to enum
enum _MultiplicativeExprType { DIVIDE = 1, MULTIPLY, MODULUS };
MultiplicativeExpr(Expr* leftExpr, Expr* rightExpr, short op);
~MultiplicativeExpr();
MultiplicativeExpr(nsAutoPtr<Expr> aLeftExpr, nsAutoPtr<Expr> aRightExpr,
short aOp);
TX_DECL_EXPR;
private:
short op;
Expr* leftExpr;
Expr* rightExpr;
nsAutoPtr<Expr> leftExpr;
nsAutoPtr<Expr> rightExpr;
}; //-- MultiplicativeExpr
/**
@ -511,7 +490,8 @@ public:
GREATER_OR_EQUAL
};
RelationalExpr(Expr* aLeftExpr, Expr* aRightExpr, RelationalExprType aOp);
RelationalExpr(nsAutoPtr<Expr> aLeftExpr, nsAutoPtr<Expr> aRightExpr,
RelationalExprType aOp);
TX_DECL_EXPR;
@ -533,7 +513,6 @@ class VariableRefExpr : public Expr {
public:
VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID);
~VariableRefExpr();
TX_DECL_EXPR;
@ -555,11 +534,6 @@ public:
//-- LF, changed from static const short to enum
enum PathOperator { RELATIVE_OP, DESCENDANT_OP };
/**
* Creates a new PathExpr
**/
PathExpr();
/**
* Destructor, will delete all Expressions
**/
@ -569,13 +543,13 @@ public:
* Adds the Expr to this PathExpr
* @param expr the Expr to add to this PathExpr
**/
void addExpr(Expr* expr, PathOperator pathOp);
nsresult addExpr(nsAutoPtr<Expr> aExpr, PathOperator aPathOp);
TX_DECL_EXPR;
private:
struct PathExprItem {
Expr* expr;
nsAutoPtr<Expr> expr;
PathOperator pathOp;
};
@ -619,11 +593,6 @@ class UnionExpr : public Expr {
public:
/**
* Creates a new UnionExpr
**/
UnionExpr();
/**
* Destructor, will delete all Path Expressions
**/
@ -633,7 +602,7 @@ public:
* Adds the PathExpr to this UnionExpr
* @param expr the Expr to add to this UnionExpr
**/
void addExpr(Expr* expr);
nsresult addExpr(nsAutoPtr<Expr> aExpr);
TX_DECL_EXPR;

Просмотреть файл

@ -35,17 +35,11 @@
* Creates a new FilterExpr using the given Expr
* @param expr the Expr to use for evaluation
**/
FilterExpr::FilterExpr(Expr* expr) : PredicateList() {
this->expr = expr;
FilterExpr::FilterExpr(nsAutoPtr<Expr> aExpr)
: expr(aExpr)
{
} //-- FilterExpr
/**
* Destroys this FilterExpr, all predicates and the expr will be deleted
**/
FilterExpr::~FilterExpr() {
delete expr;
} //-- ~FilterExpr
//-----------------------------/
//- Virtual methods from Expr -/
//-----------------------------/

Просмотреть файл

@ -33,10 +33,6 @@
* This class represents a FunctionCall as defined by the XSL Working Draft
**/
FunctionCall::FunctionCall()
{
}
/**
* Destructor
**/
@ -56,10 +52,14 @@ FunctionCall::~FunctionCall()
* Adds the given parameter to this FunctionCall's parameter list
* @param expr the Expr to add to this FunctionCall's parameter list
**/
nsresult FunctionCall::addParam(Expr* aExpr)
nsresult
FunctionCall::addParam(nsAutoPtr<Expr> aExpr)
{
if (aExpr)
params.add(aExpr);
nsresult rv = params.add(aExpr);
NS_ENSURE_SUCCESS(rv, rv);
aExpr.forget();
return NS_OK;
} //-- addParam

Просмотреть файл

@ -44,16 +44,13 @@
/**
* Creates a new MultiplicativeExpr using the given operator
**/
MultiplicativeExpr::MultiplicativeExpr(Expr* leftExpr, Expr* rightExpr, short op) {
this->op = op;
this->leftExpr = leftExpr;
this->rightExpr = rightExpr;
} //-- MultiplicativeExpr
MultiplicativeExpr::~MultiplicativeExpr() {
delete leftExpr;
delete rightExpr;
} //-- ~MultiplicativeExpr
MultiplicativeExpr::MultiplicativeExpr(nsAutoPtr<Expr> aLeftExpr,
nsAutoPtr<Expr> aRightExpr, short aOp)
: op(aOp),
leftExpr(aLeftExpr),
rightExpr(aRightExpr)
{
}
/**
* Evaluates this Expr based on the given context node and processor state

Просмотреть файл

@ -41,14 +41,6 @@
//- PathExpr -/
//------------/
/**
* Creates a new PathExpr
**/
PathExpr::PathExpr()
{
//-- do nothing
}
/**
* Destructor, will delete all Expressions
**/
@ -57,7 +49,6 @@ PathExpr::~PathExpr()
txListIterator iter(&expressions);
while (iter.hasNext()) {
PathExprItem* pxi = (PathExprItem*)iter.next();
delete pxi->expr;
delete pxi;
}
} //-- ~PathExpr
@ -66,21 +57,20 @@ PathExpr::~PathExpr()
* Adds the Expr to this PathExpr
* @param expr the Expr to add to this PathExpr
**/
void PathExpr::addExpr(Expr* expr, PathOperator pathOp)
nsresult
PathExpr::addExpr(nsAutoPtr<Expr> aExpr, PathOperator aPathOp)
{
NS_ASSERTION(expressions.getLength() > 0 || pathOp == RELATIVE_OP,
NS_ASSERTION(expressions.getLength() > 0 || aPathOp == RELATIVE_OP,
"First step has to be relative in PathExpr");
if (expr) {
PathExprItem* pxi = new PathExprItem;
if (!pxi) {
// XXX ErrorReport: out of memory
NS_ASSERTION(0, "out of memory");
return;
}
pxi->expr = expr;
pxi->pathOp = pathOp;
expressions.add(pxi);
}
nsAutoPtr<PathExprItem> pxi(new PathExprItem);
NS_ENSURE_TRUE(pxi, NS_ERROR_OUT_OF_MEMORY);
pxi->expr = aExpr;
pxi->pathOp = aPathOp;
nsresult rv = expressions.add(pxi);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
} //-- addPattenExpr
//-----------------------------/

Просмотреть файл

@ -32,10 +32,6 @@
* for use with Step and Filter Expressions
*/
PredicateList::PredicateList()
{
} // PredicateList
/*
* Destructor, will delete all Expressions in the list
*/
@ -51,9 +47,15 @@ PredicateList::~PredicateList()
* Adds the given Expr to the list
* @param expr the Expr to add to the list
*/
void PredicateList::add(Expr* expr)
nsresult
PredicateList::add(nsAutoPtr<Expr> aExpr)
{
predicates.add(expr);
nsresult rv = predicates.add(aExpr);
NS_ENSURE_SUCCESS(rv, rv);
aExpr.forget();
return NS_OK;
} // add
nsresult

Просмотреть файл

@ -32,9 +32,12 @@
#include "XMLDOMUtils.h"
#include "txIXPathContext.h"
RelationalExpr::RelationalExpr(Expr* aLeftExpr, Expr* aRightExpr,
RelationalExpr::RelationalExpr(nsAutoPtr<Expr> aLeftExpr,
nsAutoPtr<Expr> aRightExpr,
RelationalExprType aOp)
: mLeftExpr(aLeftExpr), mRightExpr(aRightExpr), mOp(aOp)
: mLeftExpr(aLeftExpr),
mRightExpr(aRightExpr),
mOp(aOp)
{
}

Просмотреть файл

@ -27,14 +27,9 @@
#include "ExprResult.h"
#include "txIXPathContext.h"
UnaryExpr::UnaryExpr(Expr* expr)
UnaryExpr::UnaryExpr(nsAutoPtr<Expr> aExpr)
: expr(aExpr)
{
this->expr = expr;
}
UnaryExpr::~UnaryExpr()
{
delete expr;
}
/*

Просмотреть файл

@ -32,13 +32,6 @@
//-------------/
/**
* Creates a new UnionExpr
**/
UnionExpr::UnionExpr() {
//-- do nothing
}
/**
* Destructor, will delete all Path Expressions
**/
@ -53,9 +46,15 @@ UnionExpr::~UnionExpr() {
* Adds the Expr to this UnionExpr
* @param expr the Expr to add to this UnionExpr
**/
void UnionExpr::addExpr(Expr* expr) {
if (expr)
expressions.add(expr);
nsresult
UnionExpr::addExpr(nsAutoPtr<Expr> aExpr)
{
nsresult rv = expressions.add(aExpr);
NS_ENSURE_SUCCESS(rv, rv);
aExpr.forget();
return NS_OK;
} //-- addExpr
//-----------------------------/

Просмотреть файл

@ -44,13 +44,6 @@ VariableRefExpr::VariableRefExpr(nsIAtom* aPrefix, nsIAtom* aLocalName,
mPrefix = 0;
}
/*
* Release the local name atom
*/
VariableRefExpr::~VariableRefExpr()
{
}
/**
* Evaluates this Expr based on the given context node and processor state
* @param context the context node for evaluation of this Expr

Просмотреть файл

@ -37,10 +37,6 @@ txNameTest::txNameTest(nsIAtom* aPrefix, nsIAtom* aLocalName, PRInt32 aNSID,
NS_ASSERTION(aLocalName, "txNameTest without a local name?");
}
txNameTest::~txNameTest()
{
}
/*
* Determines whether this txNodeTest matches the given node
*/

Просмотреть файл

@ -35,10 +35,6 @@ txNodeTypeTest::txNodeTypeTest(NodeType aNodeType)
{
}
txNodeTypeTest::~txNodeTypeTest()
{
}
void txNodeTypeTest::setNodeName(const nsAString& aName)
{
mNodeName = do_GetAtom(aName);

Просмотреть файл

@ -459,11 +459,6 @@ void txKeyPattern::toString(nsAString& aDest)
* a txPattern to hold the NodeTest and the Predicates of a StepPattern
*/
txStepPattern::~txStepPattern()
{
delete mNodeTest;
}
MBool txStepPattern::matches(Node* aNode, txIMatchContext* aContext)
{
NS_ASSERTION(mNodeTest && aNode, "Internal error");

Просмотреть файл

@ -131,12 +131,7 @@ private:
{
}
~Step()
{
delete pattern;
}
txPattern* pattern;
nsAutoPtr<txPattern> pattern;
MBool isChild;
};
@ -198,12 +193,9 @@ public:
{
}
~txStepPattern();
TX_DECL_PATTERN;
private:
txNodeTest* mNodeTest;
nsAutoPtr<txNodeTest> mNodeTest;
MBool mIsAttr;
};