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 {
|
---|
28 | public class Environment : ItemBase, IEnvironment {
|
---|
29 | private Environment parent;
|
---|
30 |
|
---|
31 | /// <summary>
|
---|
32 | /// Initializes a new instance of <see cref="Environment"/>.
|
---|
33 | /// </summary>
|
---|
34 | public Environment() { }
|
---|
35 | /// <summary>
|
---|
36 | /// Initializes a new instance of <see cref="Environment"/> with the given <paramref name="parent"/>.
|
---|
37 | /// </summary>
|
---|
38 | /// <param name="parnet">The parent environment.</param>
|
---|
39 | public Environment(Environment parent) {
|
---|
40 | this.parent = parent;
|
---|
41 | }
|
---|
42 |
|
---|
43 | /// <summary>
|
---|
44 | /// Clones the current instance.
|
---|
45 | /// </summary>
|
---|
46 | /// <remarks>The parent environment is cloned with the
|
---|
47 | /// <see cref="HeuristicLab.Core.Auxiliary.Clone"/> method of the <see cref="Auxiliary"/> class.</remarks>
|
---|
48 | /// <param name="clonedObjects">All already cloned objects. (Needed to avoid cycles.)</param>
|
---|
49 | /// <returns>The cloned object as <see cref="AtomicOperation"/>.</returns>
|
---|
50 | public override object Clone(IDictionary<Guid, object> clonedObjects) {
|
---|
51 | Environment clone = new Environment();
|
---|
52 | clonedObjects.Add(Guid, clone);
|
---|
53 | clone.parent = (Environment)Auxiliary.Clone(parent, clonedObjects);
|
---|
54 | return clone;
|
---|
55 | }
|
---|
56 |
|
---|
57 | #region Persistence Methods
|
---|
58 |
|
---|
59 | /// <summary>
|
---|
60 | /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
|
---|
61 | /// </summary>
|
---|
62 | /// <remarks>Calls <see cref="HeuristicLab.Core.StorableBase.GetXmlNode"/> of base
|
---|
63 | /// class <see cref="ItemBase"/>. <br/>
|
---|
64 | /// The parent environment is saved as child node having the tag name <c>ParentEnvironment</c>.</remarks>
|
---|
65 | /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
|
---|
66 | /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
|
---|
67 | /// <param name="persistedObjects">The dictionary of all already persisted objects. (Needed to avoid cycles.)</param>
|
---|
68 | /// <returns>The saved <see cref="XmlNode"/>.</returns>
|
---|
69 | public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
|
---|
70 | XmlNode node = base.GetXmlNode(name, document, persistedObjects);
|
---|
71 | node.AppendChild(PersistenceManager.Persist("ParentEnvironment", parent, document, persistedObjects));
|
---|
72 | return node;
|
---|
73 | }
|
---|
74 | /// <summary>
|
---|
75 | /// Loads the persisted operation from the specified <paramref name="node"/>.
|
---|
76 | /// </summary>
|
---|
77 | /// <remarks>Calls <see cref="HeuristicLab.Core.StorableBase.Populate"/> of base class
|
---|
78 | /// <see cref="ItemBase"/>.<br/>
|
---|
79 | /// The parent environment must be saved as a child node with the tag name <c>ParentEnvironment</c>
|
---|
80 | /// (see <see cref="GetXmlNode"/>).</remarks>
|
---|
81 | /// <param name="node">The <see cref="XmlNode"/> where the operation is saved.</param>
|
---|
82 | /// <param name="restoredObjects">A dictionary of all already restored objects. (Needed to avoid cycles.)</param>
|
---|
83 | public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
|
---|
84 | base.Populate(node, restoredObjects);
|
---|
85 | parent = (Environment)PersistenceManager.Restore(node.SelectSingleNode("ParentEnvironment"), restoredObjects);
|
---|
86 | }
|
---|
87 | #endregion
|
---|
88 | }
|
---|
89 | }
|
---|