vfs: check userland buffers before reading them.
[haiku.git] / headers / libs / linprog / Variable.h
blob32c4b58798dd1d2aa50f429b90b08a269bf69274
1 /*
2 * Copyright 2007-2008, Christof Lutteroth, lutteroth@cs.auckland.ac.nz
3 * Copyright 2007-2008, James Kim, jkim202@ec.auckland.ac.nz
4 * Distributed under the terms of the MIT License.
5 */
6 #ifndef VARIABLE_H
7 #define VARIABLE_H
10 #include <ObjectList.h>
11 #include <String.h>
13 namespace LinearProgramming {
15 class Constraint;
16 class LinearSpec;
17 class Summand;
19 /**
20 * Contains minimum and maximum values.
22 class Variable {
23 public:
24 int32 Index() const;
25 int32 GlobalIndex() const;
26 LinearSpec* LS() const;
27 double Value() const;
28 void SetValue(double value);
29 double Min() const;
30 void SetMin(double min);
31 double Max() const;
32 void SetMax(double max);
33 void SetRange(double min, double max);
35 const char* Label();
36 void SetLabel(const char* label);
38 BString ToString() const;
40 Constraint* IsEqual(Variable* var);
41 Constraint* IsSmallerOrEqual(Variable* var);
42 Constraint* IsGreaterOrEqual(Variable* var);
44 Constraint* IsEqual(Variable* var,
45 double penaltyNeg, double penaltyPos);
46 Constraint* IsSmallerOrEqual(Variable* var,
47 double penaltyNeg, double penaltyPos);
48 Constraint* IsGreaterOrEqual(Variable* var,
49 double penaltyNeg, double penaltyPos);
51 bool IsValid();
52 //! Dangerous the variable don't belong to the LinearSpec anymore,
53 //! delete it yourself!
54 void Invalidate();
56 virtual ~Variable();
58 protected:
59 Variable(LinearSpec* ls);
61 //! returns the ref count
62 int32 AddReference();
63 int32 RemoveReference();
64 private:
65 LinearSpec* fLS;
67 double fValue;
68 double fMin;
69 double fMax;
70 BString fLabel;
72 bool fIsValid;
74 int32 fReferenceCount;
75 public:
76 friend class LinearSpec;
80 typedef BObjectList<Variable> VariableList;
83 } // namespace LinearProgramming
85 using LinearProgramming::Variable;
86 using LinearProgramming::VariableList;
88 #endif // VARIABLE_H