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/DoubleBoundedConstraint.cs

    r1529 r1672  
    2727using HeuristicLab.Data;
    2828using System.Globalization;
     29using HeuristicLab.Persistence.Default.Decomposers.Storable;
    2930
    3031namespace HeuristicLab.Constraints {
     
    3334  /// </summary>
    3435  public class DoubleBoundedConstraint : ConstraintBase {
     36
     37    [Storable]
    3538    private double lowerBound;
    3639    /// <summary>
     
    4649      }
    4750    }
     51
     52    [Storable]
    4853    private bool lowerBoundIncluded;
    4954    /// <summary>
     
    5964      }
    6065    }
     66
     67    [Storable]
    6168    private bool lowerBoundEnabled;
    6269    /// <summary>
     
    7279      }
    7380    }
     81
     82    [Storable]
    7483    private double upperBound;
    7584    /// <summary>
     
    8594      }
    8695    }
     96
     97    [Storable]
    8798    private bool upperBoundIncluded;
    8899    /// <summary>
     
    98109      }
    99110    }
     111
     112    [Storable]
    100113    private bool upperBoundEnabled;
    101114    /// <summary>
     
    191204      return clone;
    192205    }
    193 
    194     #region persistence
    195     /// <summary>
    196     /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
    197     /// </summary>
    198     /// <remarks>The properties of the current instance are saved as attributes with special tag names.</remarks>
    199     /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
    200     /// <param name="document">The <see cref="XmlDocument"/> where the data is saved.</param>
    201     /// <param name="persistedObjects">The dictionary of all already persisted objects.
    202     /// (Needed to avoid cycles.)</param>
    203     /// <returns>The saved <see cref="XmlNode"/>.</returns>
    204     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    205       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    206       XmlAttribute lb = document.CreateAttribute("LowerBound");
    207       lb.Value = LowerBound.ToString("r", CultureInfo.InvariantCulture);
    208       XmlAttribute lbi = document.CreateAttribute("LowerBoundIncluded");
    209       lbi.Value = lowerBoundIncluded.ToString();
    210       XmlAttribute lbe = document.CreateAttribute("LowerBoundEnabled");
    211       lbe.Value = lowerBoundEnabled.ToString();
    212       XmlAttribute ub = document.CreateAttribute("UpperBound");
    213       ub.Value = upperBound.ToString("r", CultureInfo.InvariantCulture);
    214       XmlAttribute ubi = document.CreateAttribute("UpperBoundIncluded");
    215       ubi.Value = upperBoundIncluded.ToString();
    216       XmlAttribute ube = document.CreateAttribute("UpperBoundEnabled");
    217       ube.Value = upperBoundEnabled.ToString();
    218       node.Attributes.Append(lb);
    219       if (!lowerBoundIncluded) node.Attributes.Append(lbi);
    220       if (!lowerBoundEnabled) node.Attributes.Append(lbe);
    221       node.Attributes.Append(ub);
    222       if (!upperBoundIncluded) node.Attributes.Append(ubi);
    223       if (!upperBoundEnabled) node.Attributes.Append(ube);
    224       return node;
    225     }
    226 
    227     /// <summary>
    228     /// Loads the persisted constraint from the specified <paramref name="node"/>.
    229     /// </summary>
    230     /// <remarks>The constraint must be saved in a specific way, see <see cref="GetXmlNode"/> for
    231     /// more information.</remarks>
    232     /// <param name="node">The <see cref="XmlNode"/> where the instance is saved.</param>
    233     /// <param name="restoredObjects">The dictionary of all already restored objects.
    234     /// (Needed to avoid cycles.)</param>
    235     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    236       base.Populate(node, restoredObjects);
    237       lowerBound = double.Parse(node.Attributes["LowerBound"].Value, CultureInfo.InvariantCulture);
    238       if (node.Attributes["LowerBoundIncluded"] != null) {
    239         lowerBoundIncluded = bool.Parse(node.Attributes["LowerBoundIncluded"].Value);
    240       } else {
    241         lowerBoundIncluded = true;
    242       }
    243       if (node.Attributes["LowerBoundEnabled"] != null) {
    244         lowerBoundEnabled = bool.Parse(node.Attributes["LowerBoundEnabled"].Value);
    245       } else {
    246         lowerBoundEnabled = true;
    247       }
    248 
    249       upperBound = double.Parse(node.Attributes["UpperBound"].Value, CultureInfo.InvariantCulture);
    250       if (node.Attributes["UpperBoundIncluded"] != null) {
    251         upperBoundIncluded = bool.Parse(node.Attributes["UpperBoundIncluded"].Value);
    252       } else {
    253         upperBoundIncluded = true;
    254       }
    255       if (node.Attributes["UpperBoundEnabled"] != null) {
    256         upperBoundEnabled = bool.Parse(node.Attributes["UpperBoundEnabled"].Value);
    257       } else {
    258         upperBoundEnabled = true;
    259       }
    260     }
    261     #endregion
    262206  }
    263207}
Note: See TracChangeset for help on using the changeset viewer.