Skip to content

Commit 0d1da7d

Browse files
committedSep 13, 2018
Add unique_ptr in nodeBinaryOperatorFromOgcFilter
1 parent 23d2df2 commit 0d1da7d

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed
 

‎src/core/qgsogcutils.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3171,7 +3171,9 @@ QgsExpressionNodeBinaryOperator *QgsOgcUtilsExpressionFromFilter::nodeBinaryOper
31713171
}
31723172

31733173
QDomElement operandElem = element.firstChildElement();
3174-
QgsExpressionNode *expr = nodeFromOgcFilter( operandElem ), *leftOp = expr;
3174+
std::unique_ptr<QgsExpressionNode> expr( nodeFromOgcFilter( operandElem ) );
3175+
std::unique_ptr<QgsExpressionNode> leftOp( expr->clone() );
3176+
31753177
if ( !expr )
31763178
{
31773179
mErrorMessage = QObject::tr( "invalid left operand for '%1' binary operator" ).arg( element.tagName() );
@@ -3180,11 +3182,10 @@ QgsExpressionNodeBinaryOperator *QgsOgcUtilsExpressionFromFilter::nodeBinaryOper
31803182

31813183
for ( operandElem = operandElem.nextSiblingElement(); !operandElem.isNull(); operandElem = operandElem.nextSiblingElement() )
31823184
{
3183-
QgsExpressionNode *opRight = nodeFromOgcFilter( operandElem );
3185+
std::unique_ptr<QgsExpressionNode> opRight( nodeFromOgcFilter( operandElem ) );
31843186
if ( !opRight )
31853187
{
31863188
mErrorMessage = QObject::tr( "invalid right operand for '%1' binary operator" ).arg( element.tagName() );
3187-
delete expr;
31883189
return nullptr;
31893190
}
31903191

@@ -3206,7 +3207,7 @@ QgsExpressionNodeBinaryOperator *QgsOgcUtilsExpressionFromFilter::nodeBinaryOper
32063207
escape = element.attribute( QStringLiteral( "escape" ) );
32073208
}
32083209
// replace
3209-
QString oprValue = static_cast<const QgsExpressionNodeLiteral *>( opRight )->value().toString();
3210+
QString oprValue = static_cast<const QgsExpressionNodeLiteral *>( opRight.get() )->value().toString();
32103211
if ( !wildCard.isEmpty() && wildCard != QLatin1String( "%" ) )
32113212
{
32123213
oprValue.replace( '%', QLatin1String( "\\%" ) );
@@ -3243,24 +3244,19 @@ QgsExpressionNodeBinaryOperator *QgsOgcUtilsExpressionFromFilter::nodeBinaryOper
32433244
{
32443245
oprValue.replace( escape + escape, escape );
32453246
}
3246-
opRight = new QgsExpressionNodeLiteral( oprValue );
3247+
opRight.reset( new QgsExpressionNodeLiteral( oprValue ) );
32473248
}
32483249

3249-
expr = new QgsExpressionNodeBinaryOperator( static_cast< QgsExpressionNodeBinaryOperator::BinaryOperator >( op ), expr, opRight );
3250+
expr.reset( new QgsExpressionNodeBinaryOperator( static_cast< QgsExpressionNodeBinaryOperator::BinaryOperator >( op ), expr.release(), opRight.release() ) );
32503251
}
32513252

32523253
if ( expr == leftOp )
32533254
{
32543255
mErrorMessage = QObject::tr( "only one operand for '%1' binary operator" ).arg( element.tagName() );
3255-
delete expr;
32563256
return nullptr;
32573257
}
32583258

3259-
QgsExpressionNodeBinaryOperator *ret = dynamic_cast< QgsExpressionNodeBinaryOperator * >( expr );
3260-
if ( !ret )
3261-
delete expr;
3262-
3263-
return ret;
3259+
return dynamic_cast< QgsExpressionNodeBinaryOperator * >( expr.release() );
32643260
}
32653261

32663262

0 commit comments

Comments
 (0)
Please sign in to comment.