Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.Core/3.3/OperatorGroup.cs @ 4412

Last change on this file since 4412 was 1823, checked in by epitzer, 16 years ago

Namespace refactoring: rename formatters & decomposers -> primitive and composite serializers. (#603)

File size: 4.8 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.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Core {
29  /// <summary>
30  /// Representation of a group of operators (can also include subgroups).
31  /// </summary>
32  public class OperatorGroup : StorableBase, IOperatorGroup {
33
34    [Storable]
35    private string myName;
36    /// <summary>
37    /// Gets or sets the name of the current operator group.
38    /// </summary>
39    /// <remarks>Calls <see cref="OnNameChanged"/> in the setter.</remarks>
40    public string Name {
41      get { return myName; }
42      set {
43        if (myName != value) {
44          myName = value;
45          OnNameChanged();
46        }
47      }
48    }
49
50    [Storable]
51    private List<IOperatorGroup> mySubGroups;
52    /// <summary>
53    /// Gets all subgroups of the current instance.
54    /// <note type="caution"> The subgroups are returned read-only.</note>
55    /// </summary>
56    public ICollection<IOperatorGroup> SubGroups {
57      get { return mySubGroups.AsReadOnly(); }
58    }
59
60    [Storable]
61    private List<IOperator> myOperators;
62    /// <summary>
63    /// Gets all operators of the current instance.
64    /// <note type="caution"> The operators are returned read-only.</note>
65    /// </summary>
66    public ICollection<IOperator> Operators {
67      get { return myOperators.AsReadOnly(); }
68    }
69
70    /// <summary>
71    /// Initializes a new instance of <see cref="OperatorGroup"/> having "Anonymous" as name.
72    /// </summary>
73    public OperatorGroup() {
74      myName = "Anonymous";
75      mySubGroups = new List<IOperatorGroup>();
76      myOperators = new List<IOperator>();
77    }
78
79    /// <summary>
80    /// Clones the current instance (deep clone).
81    /// </summary>
82    /// <remarks>Deep clone with <see cref="Auxiliary.Clone"/> method of helper class
83    /// <see cref="Auxiliary"/>.</remarks>
84    /// <param name="clonedObjects">Dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
85    /// <returns>The cloned object as <see cref="OperatorGroup"/>.</returns>
86    public override object Clone(IDictionary<Guid, object> clonedObjects) {
87      OperatorGroup clone = (OperatorGroup)base.Clone(clonedObjects);
88      clone.myName = Name;
89      foreach (IOperatorGroup group in SubGroups)
90        clone.AddSubGroup((IOperatorGroup)Auxiliary.Clone(group, clonedObjects));
91      foreach (IOperator op in Operators)
92        clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
93      return clone;
94    }
95
96    /// <summary>
97    /// Adds the given subgroup (<paramref name="group"/>) to the current instance.
98    /// </summary>
99    /// <param name="group">The subgroup to add.</param>
100    public virtual void AddSubGroup(IOperatorGroup group) {
101      mySubGroups.Add(group);
102    }
103    /// <summary>
104    /// Removes the given subgroup (<paramref name="group"/>) from the current instance.
105    /// </summary>
106    /// <param name="group">The subgroup to remove.</param>
107    public virtual void RemoveSubGroup(IOperatorGroup group) {
108      mySubGroups.Remove(group);
109    }
110    /// <summary>
111    /// Ads the given operator <paramref name="op"/> to the current instance.
112    /// </summary>
113    /// <param name="op">The operator to add.</param>
114    public virtual void AddOperator(IOperator op) {
115      myOperators.Add(op);
116    }
117    /// <summary>
118    /// Removes the given operator <paramref name="op"/> from the current instance.
119    /// </summary>
120    /// <param name="op">The operator to remove.</param>
121    public virtual void RemoveOperator(IOperator op) {
122      myOperators.Remove(op);
123    }
124
125    /// <summary>
126    /// Occurs when the name of the operator was changed.
127    /// </summary>
128    public event EventHandler NameChanged;
129    /// <summary>
130    /// Fires a new <c>NameChanged</c> event.
131    /// </summary>
132    protected virtual void OnNameChanged() {
133      if (NameChanged != null) {
134        NameChanged(this, new EventArgs());
135      }
136    }
137  }
138}
Note: See TracBrowser for help on using the repository browser.