Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

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