Merging from trunk
[ardour.git] / libs / cassowary / cassowary / ClLinearEquation.h
1 // $Id$
2 //
3 // Cassowary Incremental Constraint Solver
4 // Original Smalltalk Implementation by Alan Borning
5 // This C++ Implementation by Greg J. Badros, <gjb@cs.washington.edu>
6 // http://www.cs.washington.edu/homes/gjb
7 // (C) 1998, 1999 Greg J. Badros and Alan Borning
8 // See ../LICENSE for legal details regarding this software
9 //
10 // ClLinearEquation.h
11
12 #ifndef ClLinearEquation_H
13 #define ClLinearEquation_H
14
15 #if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED) && !defined(CONFIG_INLINE_H_INCLUDED)
16 #include <cassowary/config-inline.h>
17 #define CONFIG_INLINE_H_INCLUDED
18 #endif
19
20 #include "Cassowary.h"
21 #include "ClLinearConstraint.h"
22 #include "ClLinearExpression.h"
23
24 class ClStrength;
25 class ClVariable;
26
27 class ClLinearEquation : public ClLinearConstraint {
28  private: typedef ClLinearConstraint super;
29
30  public:
31  //// Constructors
32
33  // ClLinearEquation(expr,...)    is   expr == 0
34  ClLinearEquation(const ClLinearExpression &cle,
35                   const ClStrength &strength = ClsRequired(),
36                   double weight = 1.0) :
37    ClLinearConstraint(cle,strength, weight)
38    { }
39
40  // ClLinearEquation(var,expr,...)  is   var == expr
41  ClLinearEquation(ClVariable clv,
42                   const ClLinearExpression &cle,
43                   const ClStrength &strength = ClsRequired(),
44                   double weight = 1.0) :
45    ClLinearConstraint(cle,strength,weight)
46    { _expression.AddVariable(clv,-1.0); }
47
48  // ClLinearEquation(expr,var,...) is   var == expr
49  ClLinearEquation(const ClLinearExpression &cle,
50                   ClVariable clv,
51                   const ClStrength &strength = ClsRequired(),
52                   double weight = 1.0) :
53    ClLinearConstraint(cle,strength,weight)
54    { _expression.AddVariable(clv,-1.0); }
55
56  // ClLinearEquation(expr,expr,...) is   expr == expr
57  ClLinearEquation(const ClLinearExpression &cle1,
58                   const ClLinearExpression &cle2,
59                   const ClStrength &strength = ClsRequired(),
60                   double weight = 1.0) :
61    ClLinearConstraint(cle1,strength,weight)
62    { _expression.AddExpression(cle2,-1.0); }
63
64 #ifndef CL_NO_IO 
65  virtual ostream &PrintOn(ostream &xo) const
66    {  super::PrintOn(xo); xo << " = 0 )"; return xo; }
67 #endif
68
69   virtual bool FIsSatisfied() const
70     { return (_expression.Evaluate() == 0); }
71
72 };
73
74 #endif