Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.2/AtomicOperation.cs @ 1835

Last change on this file since 1835 was 1529, checked in by gkronber, 16 years ago

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

File size: 5.1 KB
RevLine 
[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
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Xml;
26
27namespace HeuristicLab.Core {
[776]28  /// <summary>
29  /// Represents a single operation with one operator and one scope.
30  /// </summary>
[2]31  public class AtomicOperation : ItemBase, IOperation {
32    private IOperator myOperator;
[776]33    /// <summary>
34    /// Gets the current operator as <see cref="IOperator"/>.
35    /// </summary>
[2]36    public IOperator Operator {
37      get { return myOperator; }
38    }
[776]39    private IScope myScope; 
40    /// <summary>
41    /// Gets the current scope as <see cref="IScope"/>.
42    /// </summary>
[2]43    public IScope Scope {
44      get { return myScope; }
45    }
46
[776]47    /// <summary>
48    /// Initializes a new instance of <see cref="AtomicOperation"/>.
49    /// </summary>
[2]50    public AtomicOperation() { }
[776]51    /// <summary>
52    /// Initializes a new instance of <see cref="AtomicOperation"/> with the given <paramref name="op"/>
53    /// and the given <paramref name="scope"/>.
54    /// </summary>
55    /// <param name="op">The operator to assign.</param>
56    /// <param name="scope">The scope to assign.</param>
[2]57    public AtomicOperation(IOperator op, IScope scope) {
58      myOperator = op;
59      myScope = scope;
60    }
61
[776]62    /// <summary>
63    /// Clones the current instance.
64    /// </summary>
65    /// <remarks>The operator and the scope objects are cloned with the
66    /// <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of the <see cref="Auxiliary"/> class.</remarks>
67    /// <param name="clonedObjects">All already cloned objects. (Needed to avoid cycles.)</param>
68    /// <returns>The cloned object as <see cref="AtomicOperation"/>.</returns>
[2]69    public override object Clone(IDictionary<Guid, object> clonedObjects) {
70      AtomicOperation clone = new AtomicOperation();
71      clonedObjects.Add(Guid, clone);
72      clone.myOperator = (IOperator)Auxiliary.Clone(Operator, clonedObjects);
73      clone.myScope = (IScope)Auxiliary.Clone(Scope, clonedObjects);
74      return clone;
75    }
76
77    #region Persistence Methods
[776]78
79    /// <summary>
80    ///  Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
81    /// </summary>
82    /// <remarks>Calls <see cref="HeuristicLab.Core.StorableBase.GetXmlNode"/> of base
83    /// class <see cref="ItemBase"/>. <br/>
84    /// The operator is saved as child node having the tag name <c>Operator</c>.<br/>
85    /// The scope is also saved as a child node having the tag name <c>Scope</c>.</remarks>
86    /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
87    /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
88    /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
89    /// <returns>The saved <see cref="XmlNode"/>.</returns>
[2]90    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
91      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
92      node.AppendChild(PersistenceManager.Persist("Operator", Operator, document, persistedObjects));
93      node.AppendChild(PersistenceManager.Persist("Scope", Scope, document, persistedObjects));
94      return node;
95    }
[776]96    /// <summary>
97    /// Loads the persisted operation from the specified <paramref name="node"/>.
98    /// </summary>
99    /// <remarks>Calls <see cref="HeuristicLab.Core.StorableBase.Populate"/> of base class
100    /// <see cref="ItemBase"/>.<br/>
101    /// The operator must be saved as a child node with the tag name <c>Operator</c>, also the scope must
102    /// be saved as a child node having the tag name <c>Scope</c> (see <see cref="GetXmlNode"/>).</remarks>
103    /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param>
104    /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
[2]105    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
106      base.Populate(node, restoredObjects);
107      myOperator = (IOperator)PersistenceManager.Restore(node.SelectSingleNode("Operator"), restoredObjects);
108      myScope = (IScope)PersistenceManager.Restore(node.SelectSingleNode("Scope"), restoredObjects);
109    }
110    #endregion
111  }
112}
Note: See TracBrowser for help on using the repository browser.