Author: czeidler Date: 2010-11-29 21:46:40 +0100 (Mon, 29 Nov 2010) New Revision: 39678 Changeset: http://dev.haiku-os.org/changeset/39678 Modified: haiku/trunk/src/libs/alm/ALMLayout.cpp haiku/trunk/src/libs/linprog/Constraint.cpp haiku/trunk/src/libs/linprog/LinearSpec.cpp Log: Replace new by new(std::nothrow). Modified: haiku/trunk/src/libs/alm/ALMLayout.cpp =================================================================== --- haiku/trunk/src/libs/alm/ALMLayout.cpp 2010-11-29 20:29:37 UTC (rev 39677) +++ haiku/trunk/src/libs/alm/ALMLayout.cpp 2010-11-29 20:46:40 UTC (rev 39678) @@ -73,7 +73,7 @@ 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 @@ 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 @@ Row* BALMLayout::AddRow() { - return new Row(this); + return new(std::nothrow) Row(this); } @@ -127,7 +127,7 @@ 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 @@ Column* BALMLayout::AddColumn() { - return new Column(this); + return new(std::nothrow) Column(this); } @@ -158,7 +158,7 @@ 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 @@ // 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 @@ { _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 @@ { _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(); Modified: haiku/trunk/src/libs/linprog/Constraint.cpp =================================================================== --- haiku/trunk/src/libs/linprog/Constraint.cpp 2010-11-29 20:29:37 UTC (rev 39677) +++ haiku/trunk/src/libs/linprog/Constraint.cpp 2010-11-29 20:46:40 UTC (rev 39678) @@ -1,10 +1,15 @@ /* * Copyright 2007-2008, Christof Lutteroth, lutteroth@xxxxxxxxxxxxxxxxx * Copyright 2007-2008, James Kim, jkim202@xxxxxxxxxxxxxxxxx + * Copyright 2010, Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx> * Distributed under the terms of the MIT License. */ + #include "Constraint.h" + +#include <new> + #include "LinearSpec.h" #include "Variable.h" @@ -109,7 +114,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ } 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 @@ 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; Modified: haiku/trunk/src/libs/linprog/LinearSpec.cpp =================================================================== --- haiku/trunk/src/libs/linprog/LinearSpec.cpp 2010-11-29 20:29:37 UTC (rev 39677) +++ haiku/trunk/src/libs/linprog/LinearSpec.cpp 2010-11-29 20:46:40 UTC (rev 39678) @@ -8,7 +8,9 @@ #include "LinearSpec.h" +#include <new> + /** * Constructor. * Creates a new specification for a linear programming problem. @@ -17,7 +19,7 @@ : fLpPresolved(NULL), fOptimization(MINIMIZE), - fObjFunction(new SummandList()), + fObjFunction(new(std::nothrow) SummandList()), fResult(ERROR), fObjectiveValue(NAN), fSolvingTime(NAN) @@ -63,7 +65,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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); }