[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab 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 General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Text;
|
---|
| 25 | using System.Xml;
|
---|
| 26 |
|
---|
| 27 | namespace HeuristicLab.Core {
|
---|
[776] | 28 | /// <summary>
|
---|
| 29 | /// Represents a library of operators consisting of one <see cref="IOperatorGroup"/>.
|
---|
| 30 | /// </summary>
|
---|
[2] | 31 | public class OperatorLibrary : ItemBase, IOperatorLibrary, IEditable {
|
---|
| 32 | private IOperatorGroup myGroup;
|
---|
[776] | 33 | /// <summary>
|
---|
| 34 | /// Gets the operator group of the current instance.
|
---|
| 35 | /// </summary>
|
---|
[2] | 36 | public IOperatorGroup Group {
|
---|
| 37 | get { return myGroup; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
[776] | 40 | /// <summary>
|
---|
| 41 | /// Initializes a new instance of <see cref="OperatorLibrary"/>.
|
---|
| 42 | /// </summary>
|
---|
[2] | 43 | public OperatorLibrary() {
|
---|
| 44 | myGroup = new OperatorGroup();
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[776] | 47 | /// <summary>
|
---|
| 48 | /// Creates a new instance of <see cref="OperatorLibraryEditor"/> to display the current instance.
|
---|
| 49 | /// </summary>
|
---|
| 50 | /// <returns>The created view as <see cref="OperatorLibraryEditor"/>.</returns>
|
---|
[2] | 51 | public override IView CreateView() {
|
---|
| 52 | return new OperatorLibraryEditor(this);
|
---|
| 53 | }
|
---|
[776] | 54 | /// <summary>
|
---|
| 55 | /// Creates a new instance of <see cref="OperatorLibraryEditor"/> to display the current instance.
|
---|
| 56 | /// </summary>
|
---|
| 57 | /// <returns>The created editor as <see cref="OperatorLibraryEditor"/>.</returns>
|
---|
[2] | 58 | public virtual IEditor CreateEditor() {
|
---|
| 59 | return new OperatorLibraryEditor(this);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[776] | 62 | /// <summary>
|
---|
| 63 | /// Clones the current instance (deep clone).
|
---|
| 64 | /// </summary>
|
---|
| 65 | /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
|
---|
| 66 | /// <see cref="Auxiliary"/>.</remarks>
|
---|
| 67 | /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
|
---|
| 68 | /// <returns>The cloned object as <see cref="OperatorLibrary"/>.</returns>
|
---|
[2] | 69 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
| 70 | OperatorLibrary clone = new OperatorLibrary();
|
---|
| 71 | clonedObjects.Add(Guid, clone);
|
---|
| 72 | clone.myGroup = (IOperatorGroup)Auxiliary.Clone(Group, clonedObjects);
|
---|
| 73 | return clone;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | #region Persistence Methods
|
---|
[776] | 77 | /// <summary>
|
---|
| 78 | /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
|
---|
| 79 | /// </summary>
|
---|
| 80 | /// <remarks>Calls <see cref="StorableBase.GetXmlNode"/> of base class <see cref="ItemBase"/>.<br/>
|
---|
| 81 | /// The operator group is saved as a child node with the tag name <c>OperatorGroup</c>.</remarks>
|
---|
| 82 | /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
|
---|
| 83 | /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
|
---|
| 84 | /// <param name="persistedObjects">The dictionary of all already persisted objects.
|
---|
| 85 | /// (Needed to avoid cycles.)</param>
|
---|
| 86 | /// <returns>The saved <see cref="XmlNode"/>.</returns>
|
---|
[2] | 87 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid,IStorable> persistedObjects) {
|
---|
| 88 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
| 89 | node.AppendChild(PersistenceManager.Persist("OperatorGroup", Group, document, persistedObjects));
|
---|
| 90 | return node;
|
---|
| 91 | }
|
---|
[776] | 92 | /// <summary>
|
---|
| 93 | /// Loads the persisted operator library from the specified <paramref name="node"/>.
|
---|
| 94 | /// </summary>
|
---|
| 95 | /// <remarks>Calls <see cref="StorableBase.Populate"/> of base class <see cref="ItemBase"/>.<br/>
|
---|
| 96 | /// See <see cref="GetXmlNode"/> for further information on how the data must be saved.</remarks>
|
---|
| 97 | /// <param name="node">The <see cref="XmlNode"/> where the operator library is saved.</param>
|
---|
| 98 | /// <param name="restoredObjects">The dictionary of all already restored objects.
|
---|
| 99 | /// (Needed to avoid cycles.)</param>
|
---|
[2] | 100 | public override void Populate(XmlNode node, IDictionary<Guid,IStorable> restoredObjects) {
|
---|
| 101 | base.Populate(node, restoredObjects);
|
---|
| 102 | myGroup = (IOperatorGroup)PersistenceManager.Restore(node.SelectSingleNode("OperatorGroup"), restoredObjects);
|
---|
| 103 | }
|
---|
| 104 | #endregion
|
---|
| 105 | }
|
---|
| 106 | }
|
---|