Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/CompositeOperation.cs @ 2636

Last change on this file since 2636 was 2526, checked in by swagner, 15 years ago

Refactored cloning (#806)

File size: 3.6 KB
RevLine 
[2]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;
[1823]26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[2]27
28namespace HeuristicLab.Core {
[776]29  /// <summary>
30  /// Represents a class for operations consisting themselves of several operations.
31  /// Can also be executed in parallel.
32  /// </summary>
[2]33  public class CompositeOperation : ItemBase, IOperation {
[1667]34
35    [Storable]
[2]36    private bool myExecuteInParallel;
[776]37    /// <summary>
38    /// Gets or sets the bool value, whether the operation should be executed in parallel or not. 
39    /// </summary>
[2]40    public bool ExecuteInParallel {
41      get { return myExecuteInParallel; }
42      set { myExecuteInParallel = value; }
43    }
[1667]44
45    [Storable]
[2]46    private List<IOperation> myOperations;
[776]47    /// <summary>
48    /// Gets all current operations.
49    /// <note type="caution"> Operations are read-only!</note>
50    /// </summary>
[2]51    public IList<IOperation> Operations {
52      get { return myOperations.AsReadOnly(); }
53    }
54
[776]55    /// <summary>
56    /// Initializes a new instance of <see cref="CompositeOperation"/>, the <see cref="ExecuteInParallel"/>
57    /// property set to <c>false</c>.
58    /// </summary>
[2]59    public CompositeOperation() {
60      myOperations = new List<IOperation>();
61      myExecuteInParallel = false;
62    }
63
[776]64    /// <summary>
65    /// Adds an operation to the current list of operations.
66    /// </summary>
67    /// <param name="operation">The operation to add.</param>
[2]68    public void AddOperation(IOperation operation) {
69      myOperations.Add(operation);
70    }
[776]71    /// <summary>
72    /// Removes an operation from the current list.
73    /// </summary>
74    /// <param name="operation">The operation to remove.</param>
[2]75    public void RemoveOperation(IOperation operation) {
76      myOperations.Remove(operation);
77    }
78
[776]79    /// <summary>
80    /// Clones the current instance of <see cref="CompositeOperation"/> (deep clone).
81    /// </summary>
82    /// <remarks>All operations of the current instance are cloned, too (deep clone), with the
[2526]83    /// <see cref="HeuristicLab.Core.cloner.Clone"/> method of the class <see cref="Auxiliary"/>.</remarks>
[776]84    /// <param name="clonedObjects">A dictionary of all already cloned objects. (Needed to avoid cycles.)</param>
85    /// <returns>The cloned operation as <see cref="CompositeOperation"/>.</returns>
[2526]86    public override IItem Clone(ICloner cloner) {
[2]87      CompositeOperation clone = new CompositeOperation();
[2526]88      cloner.RegisterClonedObject(this, clone);
[2]89      clone.myExecuteInParallel = ExecuteInParallel;
90      for (int i = 0; i < Operations.Count; i++)
[2526]91        clone.AddOperation((IOperation)cloner.Clone(Operations[i]));
[2]92      return clone;
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.