~jozilla/uiml.net/uiml.net-tp

« back to all changes in this revision

Viewing changes to Cassowary/ClVariable.cs

  • Committer: Jo Vermeulen
  • Date: 2007-09-05 14:26:30 UTC
  • mfrom: (249.1.16 Uiml.net)
  • Revision ID: jo.vermeulen@uhasselt.be-20070905142630-w5eafpsfntbgz0ko
Merged with Jo's main branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
  Cassowary.net: an incremental constraint solver for .NET
3
 
  (http://lumumba.uhasselt.be/jo/projects/cassowary.net/)
4
 
  
5
 
  Copyright (C) 2005  Jo Vermeulen (jo.vermeulen@uhasselt.be)
6
 
  
7
 
  This program is free software; you can redistribute it and/or
8
 
  modify it under the terms of the GNU Lesser General Public License
9
 
  as published by the Free Software Foundation; either version 2.1
10
 
  of  the License, or (at your option) any later version.
11
 
 
12
 
  This program is distributed in the hope that it will be useful,
13
 
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
  GNU Lesser General Public License for more details.
16
 
 
17
 
  You should have received a copy of the GNU Lesser General Public License
18
 
  along with this program; if not, write to the Free Software
19
 
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
 
*/
21
 
 
22
 
using System.Collections;
23
 
 
24
 
namespace Cassowary
25
 
{
26
 
  public class ClVariable : ClAbstractVariable
27
 
  {
28
 
    public ClVariable(string name, double value) : base(name)
29
 
    {
30
 
      _value = value;
31
 
      if (_ourVarMap != null) {
32
 
        _ourVarMap.Add(name, this);
33
 
      }
34
 
    }
35
 
 
36
 
    public ClVariable(string name) : base(name)
37
 
    {
38
 
      _value = 0.0;
39
 
      if (_ourVarMap != null)
40
 
      {
41
 
        _ourVarMap.Add(name, this);
42
 
      }
43
 
    }
44
 
  
45
 
    public ClVariable(double value)
46
 
    {
47
 
      _value = value;
48
 
    }
49
 
  
50
 
    public ClVariable()
51
 
    {
52
 
      _value = 0.0;
53
 
    }
54
 
 
55
 
    public ClVariable(long number, string prefix, double value) : base(number, prefix)
56
 
    {
57
 
      _value = value;
58
 
    }
59
 
  
60
 
    public ClVariable(long number, string prefix) : base(number, prefix)
61
 
    {
62
 
      _value = 0.0;
63
 
    }
64
 
  
65
 
    public override bool IsDummy
66
 
    {
67
 
      get { return false; }
68
 
    }
69
 
 
70
 
    public override bool IsExternal
71
 
    {
72
 
      get { return true; }
73
 
    }
74
 
  
75
 
    public override bool IsPivotable
76
 
    {
77
 
      get { return false; }
78
 
    }
79
 
 
80
 
    public override bool IsRestricted
81
 
    {
82
 
      get { return false; }
83
 
    }
84
 
 
85
 
    public override string ToString()
86
 
    {
87
 
      return "[" + Name + ":" + _value + "]";
88
 
    }
89
 
 
90
 
    /// <remarks>
91
 
    /// Change the value held -- should *not* use this if the variable is 
92
 
    /// in a solver -- instead use AddEditVar() and SuggestValue() interface
93
 
    /// </remarks>
94
 
    public /*sealed*/ double Value
95
 
    {
96
 
      get { return _value; }
97
 
      set { _value = value; }
98
 
    }
99
 
 
100
 
    /// <remarks>
101
 
    /// Permit overriding in subclasses in case something needs to be
102
 
    /// done when the value is changed by the solver
103
 
    /// may be called when the value hasn't actually changed -- just
104
 
    /// means the solver is setting the external variable
105
 
    /// </remarks>
106
 
    public void ChangeValue(double value)
107
 
    {
108
 
      _value = value;
109
 
    }
110
 
 
111
 
    public object AttachedObject
112
 
    {
113
 
      get { return _attachedObject; }
114
 
      set { _attachedObject = value; }
115
 
    }
116
 
  
117
 
    public static Hashtable VarMap
118
 
    {
119
 
      get { return _ourVarMap; }
120
 
      set { _ourVarMap = value; }
121
 
    }
122
 
  
123
 
    private static Hashtable _ourVarMap;
124
 
    private double _value;
125
 
    private object _attachedObject;
126
 
  }
127
 
}