[2653] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[2757] | 24 | using System.Linq;
|
---|
[2653] | 25 | using System.Text;
|
---|
| 26 | using System.Xml;
|
---|
| 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace HeuristicLab.Core {
|
---|
[2773] | 30 | public class ExecutionContextCollection : DeepCloneable, IList<IExecutionSequence>, IExecutionSequence {
|
---|
[2653] | 31 | [Storable]
|
---|
[2773] | 32 | private IList<IExecutionSequence> contexts;
|
---|
[2653] | 33 |
|
---|
| 34 | [Storable]
|
---|
| 35 | private bool parallel;
|
---|
| 36 | public bool Parallel {
|
---|
| 37 | get { return parallel; }
|
---|
| 38 | set { parallel = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public ExecutionContextCollection() {
|
---|
[2773] | 42 | contexts = new List<IExecutionSequence>();
|
---|
[2653] | 43 | parallel = false;
|
---|
| 44 | }
|
---|
[2773] | 45 | public ExecutionContextCollection(IEnumerable<IExecutionSequence> collection) {
|
---|
| 46 | contexts = new List<IExecutionSequence>(collection.Where(e => e != null));
|
---|
[2653] | 47 | parallel = false;
|
---|
| 48 | }
|
---|
[2773] | 49 | public ExecutionContextCollection(params IExecutionSequence[] list) {
|
---|
| 50 | contexts = new List<IExecutionSequence>(list.Where(e => e != null));
|
---|
[2653] | 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++)
|
---|
[2773] | 59 | clone.contexts.Add((IExecutionSequence)cloner.Clone(contexts[i]));
|
---|
[2653] | 60 | return clone;
|
---|
| 61 | }
|
---|
| 62 |
|
---|
[2757] | 63 | #region IList<IExecutionContext> Members
|
---|
[2773] | 64 | public int IndexOf(IExecutionSequence item) {
|
---|
[2653] | 65 | return contexts.IndexOf(item);
|
---|
| 66 | }
|
---|
[2773] | 67 | public void Insert(int index, IExecutionSequence item) {
|
---|
[2757] | 68 | if (item != null) contexts.Insert(index, item);
|
---|
[2653] | 69 | }
|
---|
| 70 | public void RemoveAt(int index) {
|
---|
| 71 | contexts.RemoveAt(index);
|
---|
| 72 | }
|
---|
[2773] | 73 | public IExecutionSequence this[int index] {
|
---|
[2653] | 74 | get { return contexts[index]; }
|
---|
[2757] | 75 | set { if (value != null) contexts[index] = value; }
|
---|
[2653] | 76 | }
|
---|
| 77 | #endregion
|
---|
| 78 |
|
---|
[2757] | 79 | #region ICollection<IExecutionContext> Members
|
---|
[2773] | 80 | public void Add(IExecutionSequence item) {
|
---|
[2757] | 81 | if (item != null) contexts.Add(item);
|
---|
[2653] | 82 | }
|
---|
| 83 | public void Clear() {
|
---|
| 84 | contexts.Clear();
|
---|
| 85 | }
|
---|
[2773] | 86 | public bool Contains(IExecutionSequence item) {
|
---|
[2653] | 87 | return contexts.Contains(item);
|
---|
| 88 | }
|
---|
[2773] | 89 | public void CopyTo(IExecutionSequence[] array, int arrayIndex) {
|
---|
[2653] | 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 | }
|
---|
[2773] | 98 | public bool Remove(IExecutionSequence item) {
|
---|
[2653] | 99 | return contexts.Remove(item);
|
---|
| 100 | }
|
---|
| 101 | #endregion
|
---|
| 102 |
|
---|
[2757] | 103 | #region IEnumerable<IExecutionContext> Members
|
---|
[2773] | 104 | public IEnumerator<IExecutionSequence> GetEnumerator() {
|
---|
[2653] | 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 | }
|
---|