Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/27/09 15:29:27 (15 years ago)
Author:
epitzer
Message:

Migrate HL.Constraints-3.3 to new persistence library. (#603)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Constraints/3.3/IntBoundedConstraint.cs

    r1529 r1672  
    2626using HeuristicLab.Core;
    2727using HeuristicLab.Data;
     28using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2829
    2930namespace HeuristicLab.Constraints {
     
    3233  /// </summary>
    3334  public class IntBoundedConstraint : ConstraintBase {
     35
     36    [Storable]
    3437    private int lowerBound;
    3538    /// <summary>
     
    4548      }
    4649    }
     50
     51    [Storable]
    4752    private bool lowerBoundIncluded;
    4853    /// <summary>
     
    5863      }
    5964    }
     65
     66    [Storable]
    6067    private bool lowerBoundEnabled;
    6168    /// <summary>
     
    7178      }
    7279    }
     80
     81    [Storable]
    7382    private int upperBound;
    7483    /// <summary>
     
    8493      }
    8594    }
     95
     96    [Storable]
    8697    private bool upperBoundIncluded;
    8798    /// <summary>
     
    97108      }
    98109    }
     110
     111    [Storable]
    99112    private bool upperBoundEnabled;
    100113    /// <summary>
     
    128141    /// <param name="low">The lower bound of the constraint.</param>
    129142    /// <param name="high">The upper bound of the constraint.</param>
    130     public IntBoundedConstraint(int low, int high) : base() {
     143    public IntBoundedConstraint(int low, int high)
     144      : base() {
    131145      lowerBound = low;
    132146      lowerBoundIncluded = false;
     
    177191      return clone;
    178192    }
    179 
    180     #region persistence
    181     /// <summary>
    182     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    183     /// </summary>
    184     /// <remarks>The properties of the current instance are saved as attributes with special tag names.</remarks>
    185     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    186     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    187     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    188     /// (Needed to avoid cycles.)</param>
    189     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    190     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    191       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    192       XmlAttribute lb = document.CreateAttribute("LowerBound");
    193       lb.Value = LowerBound + "";
    194       XmlAttribute lbi = document.CreateAttribute("LowerBoundIncluded");
    195       lbi.Value = lowerBoundIncluded + "";
    196       XmlAttribute lbe = document.CreateAttribute("LowerBoundEnabled");
    197       lbe.Value = lowerBoundEnabled + "";
    198       XmlAttribute ub = document.CreateAttribute("UpperBound");
    199       ub.Value = upperBound + "";
    200       XmlAttribute ubi = document.CreateAttribute("UpperBoundIncluded");
    201       ubi.Value = upperBoundIncluded + "";
    202       XmlAttribute ube = document.CreateAttribute("UpperBoundEnabled");
    203       ube.Value = upperBoundEnabled + "";
    204       node.Attributes.Append(lb);
    205       if (!lowerBoundIncluded) node.Attributes.Append(lbi);
    206       if (!lowerBoundEnabled) node.Attributes.Append(lbe);
    207       node.Attributes.Append(ub);
    208       if (!upperBoundIncluded) node.Attributes.Append(ubi);
    209       if (!upperBoundEnabled) node.Attributes.Append(ube);
    210       return node;
    211     }
    212 
    213     /// <summary>
    214     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    215     /// </summary>
    216     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    217     /// more information.</remarks>
    218     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    219     /// <param name="restoredObjects">The dictionary of all already restored objects.
    220     /// (Needed to avoid cycles.)</param>
    221     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    222       base.Populate(node, restoredObjects);
    223       lowerBound = int.Parse(node.Attributes["LowerBound"].Value);
    224       if (node.Attributes["LowerBoundIncluded"] != null) {
    225         lowerBoundIncluded = bool.Parse(node.Attributes["LowerBoundIncluded"].Value);
    226       } else {
    227         lowerBoundIncluded = true;
    228       }
    229       if (node.Attributes["LowerBoundEnabled"] != null) {
    230         lowerBoundEnabled = bool.Parse(node.Attributes["LowerBoundEnabled"].Value);
    231       } else {
    232         lowerBoundEnabled = true;
    233       }
    234 
    235       upperBound = int.Parse(node.Attributes["UpperBound"].Value);
    236       if (node.Attributes["UpperBoundIncluded"] != null) {
    237         upperBoundIncluded = bool.Parse(node.Attributes["UpperBoundIncluded"].Value);
    238       } else {
    239         upperBoundIncluded = true;
    240       }
    241       if (node.Attributes["UpperBoundEnabled"] != null) {
    242         upperBoundEnabled = bool.Parse(node.Attributes["UpperBoundEnabled"].Value);
    243       } else {
    244         upperBoundEnabled = true;
    245       }
    246     }
    247     #endregion
    248193  }
    249194}
Note: See TracChangeset for help on using the changeset viewer.