Debian Codegraph @

lib/vpsc/constraint.cpp

raw
1 /**
2 * \brief A constraint determines a minimum or exact spacing required between
3 * two variables.
4 *
5 * Authors:
6 * Tim Dwyer <[email protected]>
7 *
8 * Copyright (C) 2005 Authors
9 *
10 * This version is released under the CPL (Common Public License) with
11 * the Graphviz distribution.
12 * A version is also available under the LGPL as part of the Adaptagrams
13 * project: https://github.com/mjwybrow/adaptagrams.
14 * If you make improvements or bug fixes to this code it would be much
15 * appreciated if you could also contribute those changes back to the
16 * Adaptagrams repository.
17 */
18
19 #include "config.h"
20
21 #include <vpsc/constraint.h>
22 #include <cassert>
23 Constraint::Constraint(Variable *left_, Variable *right_, double gap_)
24 : left(left_), right(right_), gap(gap_), timeStamp(0), active(false),
25 visited(false) {
26 left->out.push_back(this);
27 right->in.push_back(this);
28 }
29 Constraint::~Constraint() {
30 Constraints::iterator i;
31 for(i=left->out.begin(); i!=left->out.end(); i++) {
32 if(*i==this) break;
33 }
34 left->out.erase(i);
35 for(i=right->in.begin(); i!=right->in.end(); i++) {
36 if(*i==this) break;
37 }
38 right->in.erase(i);
39 }
40 std::ostream& operator <<(std::ostream &os, const Constraint &c)
41 {
42 os<<*c.left<<"+"<<c.gap<<"<="<<*c.right<<"("<<c.slack()<<")"<<(c.active?"-active":"");
43 return os;
44 }