Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/27/09 15:29:27 (16 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/NumberOfSubOperatorsConstraint.cs

    r1529 r1672  
    2727using HeuristicLab.Data;
    2828using System.Xml;
     29using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2930
    3031namespace HeuristicLab.Constraints {
     
    3334  /// </summary>
    3435  public class NumberOfSubOperatorsConstraint : ConstraintBase {
     36
     37    [Storable]
    3538    private IntData minOperators;
     39
     40    [Storable]
    3641    private IntData maxOperators;
    3742
     
    5964    /// </summary>
    6065    public NumberOfSubOperatorsConstraint()
    61       : this(0,0) {
     66      : this(0, 0) {
    6267    }
    6368
     
    6873    /// <param name="min">The minimum number of sub-operators.</param>
    6974    /// <param name="max">The maximum number of sub-operators.</param>
    70     public NumberOfSubOperatorsConstraint(int min, int max) : base() {
     75    public NumberOfSubOperatorsConstraint(int min, int max)
     76      : base() {
    7177      minOperators = new IntData(min);
    7278      maxOperators = new IntData(max);
     
    106112      return new NumberOfSubOperatorsConstraintView(this);
    107113    }
    108 
    109     #region persistence
    110     /// <summary>
    111     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    112     /// </summary>
    113     /// <remarks>The minimum and the maximum number of sub-operators are saved as child nodes with tag
    114     /// names <c>min</c> and <c>max</c>.</remarks>
    115     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    116     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    117     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    118     /// (Needed to avoid cycles.)</param>
    119     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    120     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
    121       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    122       XmlNode minNode = PersistenceManager.Persist("min", minOperators, document, persistedObjects);
    123       XmlNode maxNode = PersistenceManager.Persist("max", maxOperators, document, persistedObjects);
    124       node.AppendChild(minNode);
    125       node.AppendChild(maxNode);
    126       return node;
    127     }
    128 
    129     /// <summary>
    130     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    131     /// </summary>
    132     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    133     /// more information.</remarks>
    134     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    135     /// <param name="restoredObjects">The dictionary of all already restored objects.
    136     /// (Needed to avoid cycles.)</param>
    137     public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
    138       base.Populate(node, restoredObjects);
    139       minOperators = (IntData)PersistenceManager.Restore(node.SelectSingleNode("min"), restoredObjects);
    140       maxOperators = (IntData)PersistenceManager.Restore(node.SelectSingleNode("max"), restoredObjects);
    141     }
    142     #endregion persistence
    143 
    144114  }
    145115}
Note: See TracChangeset for help on using the changeset viewer.