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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/*
Cassowary.net: an incremental constraint solver for .NET
(http://lumumba.uhasselt.be/jo/projects/cassowary.net/)
Copyright (C) 2005 Jo Vermeulen (jo.vermeulen@uhasselt.be)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public License
as published by the Free Software Foundation; either version 2.1
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System.Collections;
namespace Cassowary
{
public class ClVariable : ClAbstractVariable
{
public ClVariable(string name, double value) : base(name)
{
_value = value;
if (_ourVarMap != null) {
_ourVarMap.Add(name, this);
}
}
public ClVariable(string name) : base(name)
{
_value = 0.0;
if (_ourVarMap != null)
{
_ourVarMap.Add(name, this);
}
}
public ClVariable(double value)
{
_value = value;
}
public ClVariable()
{
_value = 0.0;
}
public ClVariable(long number, string prefix, double value) : base(number, prefix)
{
_value = value;
}
public ClVariable(long number, string prefix) : base(number, prefix)
{
_value = 0.0;
}
public override bool IsDummy
{
get { return false; }
}
public override bool IsExternal
{
get { return true; }
}
public override bool IsPivotable
{
get { return false; }
}
public override bool IsRestricted
{
get { return false; }
}
public override string ToString()
{
return "[" + Name + ":" + _value + "]";
}
/// <remarks>
/// Change the value held -- should *not* use this if the variable is
/// in a solver -- instead use AddEditVar() and SuggestValue() interface
/// </remarks>
public /*sealed*/ double Value
{
get { return _value; }
set { _value = value; }
}
/// <remarks>
/// Permit overriding in subclasses in case something needs to be
/// done when the value is changed by the solver
/// may be called when the value hasn't actually changed -- just
/// means the solver is setting the external variable
/// </remarks>
public void ChangeValue(double value)
{
_value = value;
}
public object AttachedObject
{
get { return _attachedObject; }
set { _attachedObject = value; }
}
public static Hashtable VarMap
{
get { return _ourVarMap; }
set { _ourVarMap = value; }
}
private static Hashtable _ourVarMap;
private double _value;
private object _attachedObject;
}
}
|