Author: czeidler Date: 2010-09-20 06:34:38 +0200 (Mon, 20 Sep 2010) New Revision: 38737 Changeset: http://dev.haiku-os.org/changeset/38737 Modified: haiku/trunk/headers/libs/linprog/Constraint.h haiku/trunk/headers/libs/linprog/Variable.h haiku/trunk/src/libs/linprog/Constraint.cpp haiku/trunk/src/libs/linprog/Variable.cpp Log: Clean up. Modified: haiku/trunk/headers/libs/linprog/Constraint.h =================================================================== --- haiku/trunk/headers/libs/linprog/Constraint.h 2010-09-20 04:23:27 UTC (rev 38736) +++ haiku/trunk/headers/libs/linprog/Constraint.h 2010-09-20 04:34:38 UTC (rev 38737) @@ -3,21 +3,21 @@ * Copyright 2007-2008, James Kim, jkim202@xxxxxxxxxxxxxxxxx * Distributed under the terms of the MIT License. */ - #ifndef CONSTRAINT_H #define CONSTRAINT_H -#include "OperatorType.h" -#include "Variable.h" -#include "Summand.h" +#include <math.h> #include <File.h> #include <List.h> #include <String.h> #include <SupportDefs.h> -#include <math.h> +#include "OperatorType.h" +#include "Summand.h" +#include "Variable.h" + namespace LinearProgramming { class LinearSpec; @@ -29,66 +29,66 @@ class Constraint { public: - int32 Index() const; + int32 Index() const; - BList* LeftSide(); - void SetLeftSide(BList* summands); - void UpdateLeftSide(); - void SetLeftSide(double coeff1, Variable* var1); - void SetLeftSide(double coeff1, Variable* var1, - double coeff2, Variable* var2); - void SetLeftSide(double coeff1, Variable* var1, - double coeff2, Variable* var2, - double coeff3, Variable* var3); - void SetLeftSide(double coeff1, Variable* var1, - double coeff2, Variable* var2, - double coeff3, Variable* var3, - double coeff4, Variable* var4); + BList* LeftSide(); + void SetLeftSide(BList* summands); + void UpdateLeftSide(); + void SetLeftSide(double coeff1, Variable* var1); + void SetLeftSide(double coeff1, Variable* var1, + double coeff2, Variable* var2); + void SetLeftSide(double coeff1, Variable* var1, + double coeff2, Variable* var2, + double coeff3, Variable* var3); + void SetLeftSide(double coeff1, Variable* var1, + double coeff2, Variable* var2, + double coeff3, Variable* var3, + double coeff4, Variable* var4); - OperatorType Op(); - void SetOp(OperatorType value); - double RightSide() const; - void SetRightSide(double value); - double PenaltyNeg() const; - void SetPenaltyNeg(double value); - double PenaltyPos() const; - void SetPenaltyPos(double value); + OperatorType Op(); + void SetOp(OperatorType value); + double RightSide() const; + void SetRightSide(double value); + double PenaltyNeg() const; + void SetPenaltyNeg(double value); + double PenaltyPos() const; + void SetPenaltyPos(double value); - const char* Label(); - void SetLabel(const char* label); + const char* Label(); + void SetLabel(const char* label); - void WriteXML(BFile* file); + void WriteXML(BFile* file); - Variable* DNeg() const; - Variable* DPos() const; + Variable* DNeg() const; + Variable* DPos() const; - void SetOwner(void* owner); - void* Owner() const; + void SetOwner(void* owner); + void* Owner() const; - bool IsValid(); - void Invalidate(); + bool IsValid(); + void Invalidate(); - operator BString() const; - void GetString(BString& string) const; + operator BString() const; + void GetString(BString& string) const; - ~Constraint(); + ~Constraint(); protected: - Constraint(LinearSpec* ls, BList* summands, - OperatorType op, double rightSide, - double penaltyNeg, double penaltyPos); + Constraint(LinearSpec* ls, BList* summands, + OperatorType op, double rightSide, + double penaltyNeg, double penaltyPos); private: - LinearSpec* fLS; - BList* fLeftSide; - OperatorType fOp; - double fRightSide; - Summand* fDNegObjSummand; - Summand* fDPosObjSummand; - void* fOwner; - char* fLabel; + LinearSpec* fLS; + BList* fLeftSide; + OperatorType fOp; + double fRightSide; + Summand* fDNegObjSummand; + Summand* fDPosObjSummand; + void* fOwner; + BString fLabel; - bool fIsValid; + bool fIsValid; public: friend class LinearSpec; Modified: haiku/trunk/headers/libs/linprog/Variable.h =================================================================== --- haiku/trunk/headers/libs/linprog/Variable.h 2010-09-20 04:23:27 UTC (rev 38736) +++ haiku/trunk/headers/libs/linprog/Variable.h 2010-09-20 04:34:38 UTC (rev 38737) @@ -3,13 +3,13 @@ * Copyright 2007-2008, James Kim, jkim202@xxxxxxxxxxxxxxxxx * Distributed under the terms of the MIT License. */ - #ifndef VARIABLE_H #define VARIABLE_H #include <File.h> +#include <List.h> +#include <String.h> #include <SupportDefs.h> -#include <List.h> namespace LinearProgramming { @@ -22,52 +22,52 @@ * Contains minimum and maximum values. */ class Variable { - public: - int32 Index() const; - LinearSpec* LS() const; - double Value() const; - void SetValue(double value); - double Min() const; - void SetMin(double min); - double Max() const; - void SetMax(double max); - void SetRange(double min, double max); + int32 Index() const; + LinearSpec* LS() const; + double Value() const; + void SetValue(double value); + double Min() const; + void SetMin(double min); + double Max() const; + void SetMax(double max); + void SetRange(double min, double max); - const char* Label(); - void SetLabel(const char* label); + const char* Label(); + void SetLabel(const char* label); - operator BString() const; - void GetString(BString& string) const; + operator BString() const; + void GetString(BString& string) const; - Constraint* IsEqual(Variable* var); - Constraint* IsSmallerOrEqual(Variable* var); - Constraint* IsGreaterOrEqual(Variable* var); + Constraint* IsEqual(Variable* var); + Constraint* IsSmallerOrEqual(Variable* var); + Constraint* IsGreaterOrEqual(Variable* var); - Constraint* IsEqual(Variable* var, - double penaltyNeg, double penaltyPos); - Constraint* IsSmallerOrEqual(Variable* var, - double penaltyNeg, double penaltyPos); - Constraint* IsGreaterOrEqual(Variable* var, - double penaltyNeg, double penaltyPos); + Constraint* IsEqual(Variable* var, + double penaltyNeg, double penaltyPos); + Constraint* IsSmallerOrEqual(Variable* var, + double penaltyNeg, double penaltyPos); + Constraint* IsGreaterOrEqual(Variable* var, + double penaltyNeg, double penaltyPos); - bool IsValid(); - void Invalidate(); + bool IsValid(); + void Invalidate(); - virtual ~Variable(); + virtual ~Variable(); protected: - Variable(LinearSpec* ls); + Variable(LinearSpec* ls); private: - LinearSpec* fLS; - BList* fUsingSummands; // All Summands that link to this Variable - double fValue; - double fMin; - double fMax; - char* fLabel; + LinearSpec* fLS; + BList* fUsingSummands; + // All Summands that link to this Variable + double fValue; + double fMin; + double fMax; + BString fLabel; - bool fIsValid; + bool fIsValid; public: friend class LinearSpec; Modified: haiku/trunk/src/libs/linprog/Constraint.cpp =================================================================== --- haiku/trunk/src/libs/linprog/Constraint.cpp 2010-09-20 04:23:27 UTC (rev 38736) +++ haiku/trunk/src/libs/linprog/Constraint.cpp 2010-09-20 04:34:38 UTC (rev 38737) @@ -325,15 +325,14 @@ const char* Constraint::Label() { - return fLabel; + return fLabel.String(); } void Constraint::SetLabel(const char* label) { - fLabel = (char*) malloc(strlen(label) + 1); - strcpy(fLabel, label); + fLabel = label; } @@ -471,8 +470,7 @@ Constraint::GetString(BString& string) const { string << "Constraint "; - if (fLabel) - string << fLabel; + string << fLabel; string << "(" << (int32)this << "): "; if (fIsValid) { @@ -504,7 +502,6 @@ fOp(op), fRightSide(rightSide), fOwner(NULL), - fLabel(NULL), fIsValid(true) { double coeffs[summands->CountItems() + 2]; Modified: haiku/trunk/src/libs/linprog/Variable.cpp =================================================================== --- haiku/trunk/src/libs/linprog/Variable.cpp 2010-09-20 04:23:27 UTC (rev 38736) +++ haiku/trunk/src/libs/linprog/Variable.cpp 2010-09-20 04:34:38 UTC (rev 38737) @@ -154,15 +154,14 @@ const char* Variable::Label() { - return fLabel; + return fLabel.String(); } void Variable::SetLabel(const char* label) { - fLabel = (char*) malloc(strlen(label) + 1); - strcpy(fLabel, label); + fLabel = label; } @@ -298,7 +297,7 @@ fLS->Variables()->RemoveItem(this); // invalidate all constraints that use this variable - BList* markedForInvalidation = new BList(); + BList markedForInvalidation; BList* constraints = fLS->Constraints(); for (int i = 0; i < constraints->CountItems(); i++) { Constraint* constraint = static_cast<Constraint*>( @@ -311,15 +310,14 @@ for (int j = 0; j < summands->CountItems(); j++) { Summand* summand = static_cast<Summand*>(summands->ItemAt(j)); if (summand->Var() == this) { - markedForInvalidation->AddItem(constraint); + markedForInvalidation.AddItem(constraint); break; } } } - for (int i = 0; i < markedForInvalidation->CountItems(); i++) - static_cast<Constraint*>(markedForInvalidation->ItemAt(i)) + for (int i = 0; i < markedForInvalidation.CountItems(); i++) + static_cast<Constraint*>(markedForInvalidation.ItemAt(i)) ->Invalidate(); - delete markedForInvalidation; } @@ -355,7 +353,6 @@ Variable::~Variable() { Invalidate(); - free(fLabel); delete fUsingSummands; }