[2845] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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 |
|
---|
[3260] | 22 | using System.Collections.Generic;
|
---|
| 23 | using System.Linq;
|
---|
[2845] | 24 | using HeuristicLab.Collections;
|
---|
[3376] | 25 | using HeuristicLab.Common;
|
---|
[2845] | 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Core {
|
---|
| 29 | /// <summary>
|
---|
| 30 | /// A base class for items which have a name and contain parameters.
|
---|
| 31 | /// </summary>
|
---|
| 32 | [Item("ParameterizedNamedItem", "A base class for items which have a name and contain parameters.")]
|
---|
[3017] | 33 | [StorableClass]
|
---|
[2845] | 34 | public abstract class ParameterizedNamedItem : NamedItem, IParameterizedNamedItem {
|
---|
[3280] | 35 | [Storable]
|
---|
[2845] | 36 | private ParameterCollection parameters;
|
---|
| 37 | protected ParameterCollection Parameters {
|
---|
| 38 | get { return parameters; }
|
---|
| 39 | }
|
---|
[3393] | 40 | private ReadOnlyKeyedItemCollection<string, IParameter> readOnlyParameters;
|
---|
| 41 | IKeyedItemCollection<string, IParameter> IParameterizedItem.Parameters {
|
---|
[2845] | 42 | get {
|
---|
| 43 | if (readOnlyParameters == null) readOnlyParameters = parameters.AsReadOnly();
|
---|
| 44 | return readOnlyParameters;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[2851] | 48 | protected ParameterizedNamedItem()
|
---|
| 49 | : base() {
|
---|
| 50 | name = ItemName;
|
---|
| 51 | description = ItemDescription;
|
---|
[3280] | 52 | parameters = new ParameterCollection();
|
---|
[2845] | 53 | readOnlyParameters = null;
|
---|
| 54 | }
|
---|
| 55 | protected ParameterizedNamedItem(string name)
|
---|
| 56 | : base(name) {
|
---|
[2851] | 57 | description = ItemDescription;
|
---|
[3280] | 58 | parameters = new ParameterCollection();
|
---|
[2845] | 59 | readOnlyParameters = null;
|
---|
| 60 | }
|
---|
| 61 | protected ParameterizedNamedItem(string name, ParameterCollection parameters)
|
---|
| 62 | : base(name) {
|
---|
[2851] | 63 | description = ItemDescription;
|
---|
[3280] | 64 | this.parameters = parameters;
|
---|
[2845] | 65 | readOnlyParameters = null;
|
---|
| 66 | }
|
---|
| 67 | protected ParameterizedNamedItem(string name, string description)
|
---|
| 68 | : base(name, description) {
|
---|
[3280] | 69 | parameters = new ParameterCollection();
|
---|
[2845] | 70 | readOnlyParameters = null;
|
---|
| 71 | }
|
---|
| 72 | protected ParameterizedNamedItem(string name, string description, ParameterCollection parameters)
|
---|
| 73 | : base(name, description) {
|
---|
[3280] | 74 | this.parameters = parameters;
|
---|
[2845] | 75 | readOnlyParameters = null;
|
---|
| 76 | }
|
---|
[3280] | 77 | [StorableConstructor]
|
---|
| 78 | protected ParameterizedNamedItem(bool deserializing) : base(deserializing) { }
|
---|
[2845] | 79 |
|
---|
| 80 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 81 | ParameterizedNamedItem clone = (ParameterizedNamedItem)base.Clone(cloner);
|
---|
[3280] | 82 | clone.parameters = (ParameterCollection)cloner.Clone(parameters);
|
---|
| 83 | clone.readOnlyParameters = null;
|
---|
[2845] | 84 | return clone;
|
---|
| 85 | }
|
---|
[3260] | 86 |
|
---|
| 87 | public virtual void CollectParameterValues(IDictionary<string, IItem> values) {
|
---|
| 88 | foreach (IValueParameter param in parameters.OfType<IValueParameter>()) {
|
---|
[3280] | 89 | values.Add(param.Name, param.Value);
|
---|
[3260] | 90 | if (param.Value is IParameterizedItem) {
|
---|
| 91 | Dictionary<string, IItem> children = new Dictionary<string, IItem>();
|
---|
| 92 | ((IParameterizedItem)param.Value).CollectParameterValues(children);
|
---|
| 93 | foreach (string key in children.Keys)
|
---|
| 94 | values.Add(param.Name + "." + key, children[key]);
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
[2845] | 98 | }
|
---|
| 99 | }
|
---|