Merging from trunk
[ardour.git] / libs / cassowary / cassowary / ClStrength.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 // ClStrength.h
11
12 #ifndef ClStrength_H
13 #define ClStrength_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 <string>
21
22 #include "Cassowary.h"
23 #include "ClSymbolicWeight.h"
24
25 using std::string;
26
27 class ClStrength;
28
29 const ClStrength &ClsRequired();
30 const ClStrength &ClsStrong();
31 const ClStrength &ClsMedium();
32 const ClStrength &ClsWeak();
33
34 class ClStrength {
35  public:
36
37   ClStrength(const string &Name, const ClSymbolicWeight &symbolicWeight) :
38     _name(Name), _symbolicWeight(symbolicWeight)
39     { }
40
41   // special case for when nLevels = 3, should assert nLevels() == 3
42   ClStrength(const string &Name, double w1, double w2, double w3);
43
44   virtual ~ClStrength()
45     { }
46
47   virtual bool IsRequired() const
48     { return (_symbolicWeight == ClsRequired()._symbolicWeight); }
49
50 #ifndef CL_NO_IO
51   virtual ostream &PrintOn(ostream &xo) const
52     { 
53     xo << Name(); 
54     if (!IsRequired())
55       xo << ":" << symbolicWeight(); 
56     return xo; 
57     }
58
59   friend ostream& operator<<(ostream &xos, const ClStrength &Cls)
60     { Cls.PrintOn(xos); return xos; }
61
62 #endif
63
64   virtual const ClSymbolicWeight &symbolicWeight() const
65     { return _symbolicWeight; }
66
67   void SetPv(void *pv)
68     { _pv = pv; }
69
70   void *Pv() const
71     { return _pv; }
72
73  private:
74   string Name() const
75     { return _name; }
76
77   void SetName(string Name)
78     { _name = Name; }
79
80   void SetSymbolicWeight(const ClSymbolicWeight &symbolicWeight)
81     { _symbolicWeight = symbolicWeight; }
82
83   // instance variables
84   string _name;
85   ClSymbolicWeight _symbolicWeight;
86
87   void *_pv;
88
89 };
90
91 #endif