Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/ParameterizedNamedItem.cs @ 6409

Last change on this file since 6409 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

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