summaryrefslogtreecommitdiff
path: root/libs/cassowary/cassowary/ClFDBinaryOneWayConstraint.h
blob: a779ec1f91d5cad5ee48b788f230cfa3617a9cb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// $Id$
//
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This C++ Implementation by Greg J. Badros, <gjb@cs.washington.edu>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// ClFDBinaryOneWayConstraint.h

#ifndef ClFDBinaryOneWayConstraint_H
#define ClFDBinaryOneWayConstraint_H

#if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED) && !defined(CONFIG_INLINE_H_INCLUDED)
#include <cassowary/config-inline.h>
#define CONFIG_INLINE_H_INCLUDED
#endif

#include "Cassowary.h"
#include "ClFDConstraint.h"

class ClLinearConstraint;

// Just a node in the class hierarchy for now
class ClFDBinaryOneWayConstraint : public ClFDConstraint {
 private: typedef ClFDConstraint super;

 public:

  ClFDBinaryOneWayConstraint(ClVariable vRW, enum ClCnRelation rel, ClVariable vRO, 
                             double coefficient = 1.0, double constant = 0.0,
                             const ClStrength &strength = ClsRequired(),
                             double weight = 1.0)
      : ClFDConstraint(strength,weight), _vRW(vRW), _rel(rel), _vRO(vRO),
        _coefficient(coefficient), _constant(constant)
    { }
  
  ClFDBinaryOneWayConstraint(ClVariable vRW, enum ClCnRelation rel, double constant,
                             const ClStrength &strength = ClsRequired(),
                              double weight = 1.0)
      : ClFDConstraint(strength,weight), _vRW(vRW), _rel(rel), _vRO(clvNil),
        _coefficient(0), _constant(constant)
    { }
  
  ClFDBinaryOneWayConstraint(const ClConstraint &cn);

  static void EnsurePreconditionsForCn(const ClConstraint &cn);

  static bool FCanConvertCn(const ClConstraint &cn);

#ifndef CL_NO_IO
  virtual ostream &PrintOn(ostream &xo) const
    { 
      xo << "FDCn: " << _vRW << " " << StrCnRelation(_rel) << " ";
      if (_coefficient != 0) {
        if (_coefficient != 1) xo << _coefficient << "*";
        if (_vRO != clvNil) xo << _vRO;
      }
      if (_constant != 0) xo << " + " << _constant;
      return xo;
    }

  friend ostream& operator<<(ostream &xos, const ClFDBinaryOneWayConstraint &constraint)
    { return constraint.PrintOn(xos); }

#endif

  ClVariable ClvRW() const
    { return _vRW; }
  ClVariable ClvRO() const 
    { return _vRO; }
  enum ClCnRelation Relation() const 
    { return _rel; }
  double Coefficient() const 
    { return _coefficient; }
  double Constant() const 
    { return _constant; }

  bool IsInequality() const
    { return (_rel != cnEQ && _rel != cnNEQ); }

  bool IsStrictInequality() const
    { return (_rel == cnGT || _rel == cnLT); }

 protected:
  ClVariable _vRW;
  enum ClCnRelation _rel;
  ClVariable _vRO;
  double _coefficient;
  double _constant;
};

#endif