Replace new by new(std::nothrow).

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39678 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Clemens Zeidler
2010-11-29 20:46:40 +00:00
parent e6cec9839d
commit 59c3263165
3 changed files with 77 additions and 68 deletions
+13 -13
View File
@@ -73,7 +73,7 @@ BALMLayout::~BALMLayout()
XTab*
BALMLayout::AddXTab()
{
XTab* tab = new XTab(fSolver);
XTab* tab = new(std::nothrow) XTab(fSolver);
if (!tab)
return NULL;
if (!fSolver->AddVariable(tab)) {
@@ -93,7 +93,7 @@ BALMLayout::AddXTab()
YTab*
BALMLayout::AddYTab()
{
YTab* tab = new YTab(fSolver);
YTab* tab = new(std::nothrow) YTab(fSolver);
if (!tab)
return NULL;
if (!fSolver->AddVariable(tab)) {
@@ -113,7 +113,7 @@ BALMLayout::AddYTab()
Row*
BALMLayout::AddRow()
{
return new Row(this);
return new(std::nothrow) Row(this);
}
@@ -127,7 +127,7 @@ BALMLayout::AddRow()
Row*
BALMLayout::AddRow(YTab* top, YTab* bottom)
{
Row* row = new Row(this);
Row* row = new(std::nothrow) Row(this);
if (top != NULL)
row->Constraints()->AddItem(row->Top()->IsEqual(top));
if (bottom != NULL)
@@ -144,7 +144,7 @@ BALMLayout::AddRow(YTab* top, YTab* bottom)
Column*
BALMLayout::AddColumn()
{
return new Column(this);
return new(std::nothrow) Column(this);
}
@@ -158,7 +158,7 @@ BALMLayout::AddColumn()
Column*
BALMLayout::AddColumn(XTab* left, XTab* right)
{
Column* column = new Column(this);
Column* column = new(std::nothrow) Column(this);
if (left != NULL)
column->Constraints()->AddItem(column->Left()->IsEqual(left));
if (right != NULL)
@@ -794,7 +794,7 @@ BALMLayout::_SolveLayout()
// them.
BFile* file = NULL;
if (fPerformancePath != NULL) {
file = new BFile(fPerformancePath,
file = new(std::nothrow) BFile(fPerformancePath,
B_READ_WRITE | B_CREATE_FILE | B_OPEN_AT_END);
}
@@ -823,9 +823,9 @@ BALMLayout::_CalculateMinSize()
{
_UpdateAreaConstraints();
SummandList* newObjFunction = new SummandList(2);
newObjFunction->AddItem(new Summand(1.0, fRight));
newObjFunction->AddItem(new Summand(1.0, fBottom));
SummandList* newObjFunction = new(std::nothrow) SummandList(2);
newObjFunction->AddItem(new(std::nothrow) Summand(1.0, fRight));
newObjFunction->AddItem(new(std::nothrow) Summand(1.0, fBottom));
SummandList* oldObjFunction = fSolver->SwapObjectiveFunction(
newObjFunction);
_SolveLayout();
@@ -852,9 +852,9 @@ BALMLayout::_CalculateMaxSize()
{
_UpdateAreaConstraints();
SummandList* newObjFunction = new SummandList(2);
newObjFunction->AddItem(new Summand(-1.0, fRight));
newObjFunction->AddItem(new Summand(-1.0, fBottom));
SummandList* newObjFunction = new(std::nothrow) SummandList(2);
newObjFunction->AddItem(new(std::nothrow) Summand(-1.0, fRight));
newObjFunction->AddItem(new(std::nothrow) Summand(-1.0, fBottom));
SummandList* oldObjFunction = fSolver->SwapObjectiveFunction(
newObjFunction);
_SolveLayout();
+21 -14
View File
@@ -1,10 +1,15 @@
/*
* Copyright 2007-2008, Christof Lutteroth, [email protected]
* Copyright 2007-2008, James Kim, [email protected]
* Copyright 2010, Clemens Zeidler <[email protected]>
* Distributed under the terms of the MIT License.
*/
#include "Constraint.h"
#include <new>
#include "LinearSpec.h"
#include "Variable.h"
@@ -109,7 +114,7 @@ Constraint::SetLeftSide(double coeff1, Variable* var1)
for (int i=0; i<fLeftSide->CountItems(); i++)
delete fLeftSide->ItemAt(i);
fLeftSide->MakeEmpty();
fLeftSide->AddItem(new Summand(coeff1, var1));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff1, var1));
UpdateLeftSide();
}
@@ -124,8 +129,8 @@ Constraint::SetLeftSide(double coeff1, Variable* var1,
for (int i=0; i<fLeftSide->CountItems(); i++)
delete fLeftSide->ItemAt(i);
fLeftSide->MakeEmpty();
fLeftSide->AddItem(new Summand(coeff1, var1));
fLeftSide->AddItem(new Summand(coeff2, var2));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff1, var1));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff2, var2));
UpdateLeftSide();
}
@@ -141,9 +146,9 @@ Constraint::SetLeftSide(double coeff1, Variable* var1,
for (int i=0; i<fLeftSide->CountItems(); i++)
delete fLeftSide->ItemAt(i);
fLeftSide->MakeEmpty();
fLeftSide->AddItem(new Summand(coeff1, var1));
fLeftSide->AddItem(new Summand(coeff2, var2));
fLeftSide->AddItem(new Summand(coeff3, var3));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff1, var1));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff2, var2));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff3, var3));
UpdateLeftSide();
}
@@ -160,10 +165,10 @@ Constraint::SetLeftSide(double coeff1, Variable* var1,
for (int i=0; i<fLeftSide->CountItems(); i++)
delete fLeftSide->ItemAt(i);
fLeftSide->MakeEmpty();
fLeftSide->AddItem(new Summand(coeff1, var1));
fLeftSide->AddItem(new Summand(coeff2, var2));
fLeftSide->AddItem(new Summand(coeff3, var3));
fLeftSide->AddItem(new Summand(coeff4, var4));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff1, var1));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff2, var2));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff3, var3));
fLeftSide->AddItem(new(std::nothrow) Summand(coeff4, var4));
UpdateLeftSide();
}
@@ -263,7 +268,7 @@ Constraint::SetPenaltyNeg(double value)
return;
if (fDNegObjSummand == NULL) {
fDNegObjSummand = new Summand(value, fLS->AddVariable());
fDNegObjSummand = new(std::nothrow) Summand(value, fLS->AddVariable());
fLS->ObjectiveFunction()->AddItem(fDNegObjSummand);
UpdateLeftSide();
fLS->UpdateObjectiveFunction();
@@ -305,7 +310,7 @@ Constraint::SetPenaltyPos(double value)
return;
if (fDPosObjSummand == NULL) {
fDPosObjSummand = new Summand(value, fLS->AddVariable());
fDPosObjSummand = new(std::nothrow) Summand(value, fLS->AddVariable());
fLS->ObjectiveFunction()->AddItem(fDPosObjSummand);
UpdateLeftSide();
fLS->UpdateObjectiveFunction();
@@ -499,7 +504,8 @@ Constraint::Constraint(LinearSpec* ls, SummandList* summands, OperatorType op,
}
if (penaltyNeg != INFINITY && penaltyNeg != 0. && fOp != OperatorType(LE)) {
fDNegObjSummand = new Summand(penaltyNeg, ls->AddVariable());
fDNegObjSummand = new(std::nothrow) Summand(penaltyNeg,
ls->AddVariable());
fLS->fObjFunction->AddItem(fDNegObjSummand);
varIndexes[nCoefficient] = fDNegObjSummand->Var()->Index();
coeffs[nCoefficient] = 1.0;
@@ -509,7 +515,8 @@ Constraint::Constraint(LinearSpec* ls, SummandList* summands, OperatorType op,
fDNegObjSummand = NULL;
if (penaltyPos != INFINITY && penaltyPos != 0. && fOp != OperatorType(GE)) {
fDPosObjSummand = new Summand(penaltyPos, ls->AddVariable());
fDPosObjSummand = new(std::nothrow) Summand(penaltyPos,
ls->AddVariable());
fLS->fObjFunction->AddItem(fDPosObjSummand);
varIndexes[nCoefficient] = fDPosObjSummand->Var()->Index();
coeffs[nCoefficient] = -1.0;
+43 -41
View File
@@ -8,6 +8,8 @@
#include "LinearSpec.h"
#include <new>
/**
* Constructor.
@@ -17,7 +19,7 @@ LinearSpec::LinearSpec()
:
fLpPresolved(NULL),
fOptimization(MINIMIZE),
fObjFunction(new SummandList()),
fObjFunction(new(std::nothrow) SummandList()),
fResult(ERROR),
fObjectiveValue(NAN),
fSolvingTime(NAN)
@@ -63,7 +65,7 @@ LinearSpec::~LinearSpec()
Variable*
LinearSpec::AddVariable()
{
Variable* variable = new Variable(this);
Variable* variable = new(std::nothrow) Variable(this);
if (!variable)
return NULL;
if (!AddVariable(variable)) {
@@ -148,7 +150,7 @@ Constraint*
LinearSpec::AddConstraint(SummandList* summands, OperatorType op,
double rightSide)
{
Constraint* c = new Constraint(this, summands, op, rightSide,
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
INFINITY, INFINITY);
RemovePresolved();
return c;
@@ -168,9 +170,9 @@ Constraint*
LinearSpec::AddConstraint(double coeff1, Variable* var1,
OperatorType op, double rightSide)
{
SummandList* summands = new SummandList(1);
summands->AddItem(new Summand(coeff1, var1));
Constraint* c = new Constraint(this, summands, op, rightSide,
SummandList* summands = new(std::nothrow) SummandList(1);
summands->AddItem(new(std::nothrow) Summand(coeff1, var1));
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
INFINITY, INFINITY);
RemovePresolved();
return c;
@@ -192,10 +194,10 @@ Constraint*
LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, OperatorType op, double rightSide)
{
SummandList* summands = new SummandList(2);
summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2));
Constraint* c = new Constraint(this, summands, op, rightSide,
SummandList* summands = new(std::nothrow) SummandList(2);
summands->AddItem(new(std::nothrow) Summand(coeff1, var1));
summands->AddItem(new(std::nothrow) Summand(coeff2, var2));
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
INFINITY, INFINITY);
RemovePresolved();
return c;
@@ -220,11 +222,11 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, double coeff3, Variable* var3,
OperatorType op, double rightSide)
{
SummandList* summands = new SummandList(3);
summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2));
summands->AddItem(new Summand(coeff3, var3));
Constraint* c = new Constraint(this, summands, op, rightSide,
SummandList* summands = new(std::nothrow) SummandList(3);
summands->AddItem(new(std::nothrow) Summand(coeff1, var1));
summands->AddItem(new(std::nothrow) Summand(coeff2, var2));
summands->AddItem(new(std::nothrow) Summand(coeff3, var3));
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
INFINITY, INFINITY);
RemovePresolved();
return c;
@@ -251,12 +253,12 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, double coeff3, Variable* var3,
double coeff4, Variable* var4, OperatorType op, double rightSide)
{
SummandList* summands = new SummandList(3);
summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2));
summands->AddItem(new Summand(coeff3, var3));
summands->AddItem(new Summand(coeff4, var4));
Constraint* c = new Constraint(this, summands, op, rightSide,
SummandList* summands = new(std::nothrow) SummandList(3);
summands->AddItem(new(std::nothrow) Summand(coeff1, var1));
summands->AddItem(new(std::nothrow) Summand(coeff2, var2));
summands->AddItem(new(std::nothrow) Summand(coeff3, var3));
summands->AddItem(new(std::nothrow) Summand(coeff4, var4));
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
INFINITY, INFINITY);
RemovePresolved();
return c;
@@ -278,7 +280,7 @@ Constraint*
LinearSpec::AddConstraint(SummandList* summands, OperatorType op,
double rightSide, double penaltyNeg, double penaltyPos)
{
Constraint* c = new Constraint(this, summands, op, rightSide,
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
penaltyNeg, penaltyPos);
RemovePresolved();
return c;
@@ -299,9 +301,9 @@ Constraint*
LinearSpec::AddConstraint(double coeff1, Variable* var1,
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
{
SummandList* summands = new SummandList(1);
summands->AddItem(new Summand(coeff1, var1));
Constraint* c = new Constraint(this, summands, op, rightSide,
SummandList* summands = new(std::nothrow) SummandList(1);
summands->AddItem(new(std::nothrow) Summand(coeff1, var1));
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
penaltyNeg, penaltyPos);
RemovePresolved();
return c;
@@ -325,10 +327,10 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, OperatorType op, double rightSide,
double penaltyNeg, double penaltyPos)
{
SummandList* summands = new SummandList(2);
summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2));
Constraint* c = new Constraint(this, summands, op, rightSide,
SummandList* summands = new(std::nothrow) SummandList(2);
summands->AddItem(new(std::nothrow) Summand(coeff1, var1));
summands->AddItem(new(std::nothrow) Summand(coeff2, var2));
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
penaltyNeg, penaltyPos);
RemovePresolved();
return c;
@@ -354,11 +356,11 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff2, Variable* var2, double coeff3, Variable* var3,
OperatorType op, double rightSide, double penaltyNeg, double penaltyPos)
{
SummandList* summands = new SummandList(2);
summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2));
summands->AddItem(new Summand(coeff3, var3));
Constraint* c = new Constraint(this, summands, op, rightSide,
SummandList* summands = new(std::nothrow) SummandList(2);
summands->AddItem(new(std::nothrow) Summand(coeff1, var1));
summands->AddItem(new(std::nothrow) Summand(coeff2, var2));
summands->AddItem(new(std::nothrow) Summand(coeff3, var3));
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
penaltyNeg, penaltyPos);
RemovePresolved();
return c;
@@ -387,12 +389,12 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
double coeff4, Variable* var4, OperatorType op, double rightSide,
double penaltyNeg, double penaltyPos)
{
SummandList* summands = new SummandList(2);
summands->AddItem(new Summand(coeff1, var1));
summands->AddItem(new Summand(coeff2, var2));
summands->AddItem(new Summand(coeff3, var3));
summands->AddItem(new Summand(coeff4, var4));
Constraint* c = new Constraint(this, summands, op, rightSide,
SummandList* summands = new(std::nothrow) SummandList(2);
summands->AddItem(new(std::nothrow) Summand(coeff1, var1));
summands->AddItem(new(std::nothrow) Summand(coeff2, var2));
summands->AddItem(new(std::nothrow) Summand(coeff3, var3));
summands->AddItem(new(std::nothrow) Summand(coeff4, var4));
Constraint* c = new(std::nothrow) Constraint(this, summands, op, rightSide,
penaltyNeg, penaltyPos);
RemovePresolved();
return c;
@@ -410,7 +412,7 @@ LinearSpec::AddConstraint(double coeff1, Variable* var1,
PenaltyFunction*
LinearSpec::AddPenaltyFunction(Variable* var, BList* xs, BList* gs)
{
return new PenaltyFunction(this, var, xs, gs);
return new(std::nothrow) PenaltyFunction(this, var, xs, gs);
}