Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Logging/Log.cs @ 1332

Last change on this file since 1332 was 1167, checked in by vdorfer, 16 years ago

Created API documentation for HeuristicLab.Operators.Metaprogramming and HeuristicLab.Logging namespace and changed a comment in HeuristicLab.Core namespace(#331)

File size: 4.7 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;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28
29namespace HeuristicLab.Logging {
30  /// <summary>
31  /// Represents a log object where to store a specific value that should be logged.
32  /// </summary>
33  public class Log : ItemBase, IVisualizationItem {
34    private ItemList myItems;
35    /// <summary>
36    /// Gets or sets the items of the current instance.
37    /// </summary>
38    public ItemList Items {
39      get { return myItems; }
40      set { myItems = value; }
41    }
42
43
44    /// <summary>
45    /// Initializes a new instance of <see cref="Log"/>.
46    /// </summary>
47    public Log() { }
48    /// <summary>
49    /// Initializes a new instance of <see cref="Log"/> with the given items.
50    /// </summary>
51    /// <param name="items">The list of items with which to initialize the current instance.</param>
52    public Log(ItemList items) {
53      myItems = items;
54    }
55
56    /// <summary>
57    /// Clones the current instance (deep clone).
58    /// </summary>
59    /// <remarks>Deep clone through <see cref="Auxiliary.Clone"/> method of helper class
60    /// <see cref="Auxiliary"/>.</remarks>
61    /// <param name="clonedObjects">Dictionary of all already clone objects. (Needed to avoid cycles.)</param>
62    /// <returns>The cloned object as <see cref="Log"/>.</returns>
63    public override object Clone(IDictionary<Guid, object> clonedObjects) {
64      Log clone = (Log)base.Clone(clonedObjects);
65      clone.myItems = (ItemList)Auxiliary.Clone(Items, clonedObjects);
66      return clone;
67    }
68
69    /// <summary>
70    /// Creates an instance of <see cref="LogView"/> to represent the current instance visually.
71    /// </summary>
72    /// <returns>The created view as <see cref="LogView"/>.</returns>
73    public override IView CreateView() {
74      return new LogView(this);
75    }
76
77    /// <summary>
78    /// Occurs when the items have been changed.
79    /// </summary>
80    public event EventHandler ItemsChanged;
81    /// <summary>
82    /// Fires a new <c>ItemsChanged</c> event.
83    /// </summary>
84    protected virtual void OnItemsChanged() {
85      if (ItemsChanged != null)
86        ItemsChanged(this, new EventArgs());
87    }
88
89    #region Persistence Methods
90    /// <summary>
91    /// Saves the current instance as <see cref="XmlNode"/> in the specified <paramref name="document"/>.
92    /// </summary>
93    /// <remarks>The items of the current instance are saved as a child node with the tag name
94    /// <c>Items</c>.</remarks>
95    /// <param name="name">The (tag)name of the <see cref="XmlNode"/>.</param>
96    /// <param name="document">The <see cref="XmlDocument"/> where to save the data.</param>
97    /// <param name="persistedObjects">The dictionary of all already persisted objects.
98    /// (Needed to avoid cycles.)</param>
99    /// <returns>The saved <see cref="XmlNode"/>.</returns>
100    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
101      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
102      node.AppendChild(PersistenceManager.Persist("Items", Items, document, persistedObjects));
103      return node;
104    }
105    /// <summary>
106    /// Loads the persisted item from the specified <paramref name="node"/>.
107    /// </summary>
108    /// <remarks>Has to be saved in a special way, see <see cref="GetXmlNode"/> for further information.</remarks>
109    /// <param name="node">The <see cref="XmlNode"/> where the Log is saved.</param>
110    /// <param name="restoredObjects">The dictionary of all already restored objects.
111    /// (Needed to avoid cycles.)</param>
112    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
113      base.Populate(node, restoredObjects);
114      myItems = (ItemList)PersistenceManager.Restore(node.SelectSingleNode("Items"), restoredObjects);
115    }
116    #endregion
117  }
118}
Note: See TracBrowser for help on using the repository browser.