#region License Information
/* HeuristicLab
* Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
*
* This file is part of HeuristicLab.
*
* HeuristicLab is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HeuristicLab is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with HeuristicLab. If not, see .
*/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
namespace HeuristicLab.Core {
///
/// Representation of a group of operators (can also include subgroups).
///
public class OperatorGroup : StorableBase, IOperatorGroup {
[Storable]
private string myName;
///
/// Gets or sets the name of the current operator group.
///
/// Calls in the setter.
public string Name {
get { return myName; }
set {
if (myName != value) {
myName = value;
OnNameChanged();
}
}
}
[Storable]
private List mySubGroups;
///
/// Gets all subgroups of the current instance.
/// The subgroups are returned read-only.
///
public ICollection SubGroups {
get { return mySubGroups.AsReadOnly(); }
}
[Storable]
private List myOperators;
///
/// Gets all operators of the current instance.
/// The operators are returned read-only.
///
public ICollection Operators {
get { return myOperators.AsReadOnly(); }
}
///
/// Initializes a new instance of having "Anonymous" as name.
///
public OperatorGroup() {
myName = "Anonymous";
mySubGroups = new List();
myOperators = new List();
}
///
/// Clones the current instance (deep clone).
///
/// Deep clone with method of helper class
/// .
/// Dictionary of all already cloned objects. (Needed to avoid cycles.)
/// The cloned object as .
public override object Clone(IDictionary clonedObjects) {
OperatorGroup clone = (OperatorGroup)base.Clone(clonedObjects);
clone.myName = Name;
foreach (IOperatorGroup group in SubGroups)
clone.AddSubGroup((IOperatorGroup)Auxiliary.Clone(group, clonedObjects));
foreach (IOperator op in Operators)
clone.AddOperator((IOperator)Auxiliary.Clone(op, clonedObjects));
return clone;
}
///
/// Adds the given subgroup () to the current instance.
///
/// The subgroup to add.
public virtual void AddSubGroup(IOperatorGroup group) {
mySubGroups.Add(group);
}
///
/// Removes the given subgroup () from the current instance.
///
/// The subgroup to remove.
public virtual void RemoveSubGroup(IOperatorGroup group) {
mySubGroups.Remove(group);
}
///
/// Ads the given operator to the current instance.
///
/// The operator to add.
public virtual void AddOperator(IOperator op) {
myOperators.Add(op);
}
///
/// Removes the given operator from the current instance.
///
/// The operator to remove.
public virtual void RemoveOperator(IOperator op) {
myOperators.Remove(op);
}
///
/// Occurs when the name of the operator was changed.
///
public event EventHandler NameChanged;
///
/// Fires a new NameChanged event.
///
protected virtual void OnNameChanged() {
if (NameChanged != null) {
NameChanged(this, new EventArgs());
}
}
}
}