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