Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/ExecutionContextCollection.cs @ 2770

Last change on this file since 2770 was 2757, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

  • worked on parameters and operators
File size: 3.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.Linq;
25using System.Text;
26using System.Xml;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Core {
30  public class ExecutionContextCollection : DeepCloneable, IList<IExecutionContext>, IExecutionContext {
31    [Storable]
32    private IList<IExecutionContext> contexts;
33
34    [Storable]
35    private bool parallel;
36    public bool Parallel {
37      get { return parallel; }
38      set { parallel = value; }
39    }
40
41    public ExecutionContextCollection() {
42      contexts = new List<IExecutionContext>();
43      parallel = false;
44    }
45    public ExecutionContextCollection(IEnumerable<IExecutionContext> collection) {
46      contexts = new List<IExecutionContext>(collection.Where(e => e != null));
47      parallel = false;
48    }
49    public ExecutionContextCollection(params IExecutionContext[] list) {
50      contexts = new List<IExecutionContext>(list.Where(e => e != null));
51      parallel = false;
52    }
53
54    public override IDeepCloneable Clone(Cloner cloner) {
55      ExecutionContextCollection clone = new ExecutionContextCollection();
56      cloner.RegisterClonedObject(this, clone);
57      clone.parallel = parallel;
58      for (int i = 0; i < contexts.Count; i++)
59        clone.contexts.Add((IExecutionContext)cloner.Clone(contexts[i]));
60      return clone;
61    }
62
63    #region IList<IExecutionContext> Members
64    public int IndexOf(IExecutionContext item) {
65      return contexts.IndexOf(item);
66    }
67    public void Insert(int index, IExecutionContext item) {
68      if (item != null) contexts.Insert(index, item);
69    }
70    public void RemoveAt(int index) {
71      contexts.RemoveAt(index);
72    }
73    public IExecutionContext this[int index] {
74      get { return contexts[index]; }
75      set { if (value != null) contexts[index] = value; }
76    }
77    #endregion
78
79    #region ICollection<IExecutionContext> Members
80    public void Add(IExecutionContext item) {
81      if (item != null) contexts.Add(item);
82    }
83    public void Clear() {
84      contexts.Clear();
85    }
86    public bool Contains(IExecutionContext item) {
87      return contexts.Contains(item);
88    }
89    public void CopyTo(IExecutionContext[] array, int arrayIndex) {
90      contexts.CopyTo(array, arrayIndex);
91    }
92    public int Count {
93      get { return contexts.Count; }
94    }
95    public bool IsReadOnly {
96      get { return contexts.IsReadOnly; }
97    }
98    public bool Remove(IExecutionContext item) {
99      return contexts.Remove(item);
100    }
101    #endregion
102
103    #region IEnumerable<IExecutionContext> Members
104    public IEnumerator<IExecutionContext> GetEnumerator() {
105      return contexts.GetEnumerator();
106    }
107    #endregion
108
109    #region IEnumerable Members
110    System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
111      return contexts.GetEnumerator();
112    }
113    #endregion
114  }
115}
Note: See TracBrowser for help on using the repository browser.