1 module cassowary.Constraint;
2 
3 import std.conv;
4 import std.typecons;
5 
6 import cassowary.Strength;
7 import cassowary.LinearExpression;
8 
9 abstract class ClConstraint
10 {
11 	this(const ClStrength strength = ClStrength.required, double weight = 1)
12 	{
13 		_strength = strength;
14 		_weight = weight;
15 	}
16 
17 	abstract ClLinearExpression expression();
18 
19 	bool isEditConstraint() const
20 	{
21 		return false;
22 	}
23 
24 	bool isInequality() const
25 	{
26 		return false;
27 	}
28 
29 	bool isRequired() const
30 	{
31 		return _strength.isRequired();
32 	}
33 
34 	bool isStayConstraint() const
35 	{
36 		return false;
37 	}
38 
39 	const(ClStrength) strength()
40 	{
41 		return _strength;
42 	}
43 
44 	double weight() const
45 	{
46 		return _weight;
47 	}
48 
49 	override string toString() const
50 	{
51 		return _strength.toString() ~
52 			   " {" ~ weight().to!string() ~ "} (" ~ (cast(ClConstraint)this).expression().toString();
53 	}
54 
55 	private void setStrength(ClStrength strength)
56 	{
57 		_strength = strength;
58 	}
59 
60 	private void setWeight(double weight)
61 	{
62 		_weight = weight;
63 	}
64 
65 	Object attachedObject;
66 
67 	private Rebindable!(const ClStrength) _strength;
68 	private double _weight;
69 }