Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Operator Architecture Refactoring/HeuristicLab.Core/3.2/AtomicOperation.cs @ 2045

Last change on this file since 2045 was 1994, checked in by swagner, 15 years ago

Refactoring of the operator architecture (#95)

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