Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3167 was 3017, checked in by epitzer, 14 years ago

Merge StorableClassType.Empty into StorableClassType.MarkedOnly and make it the default if not specified (#548)

File size: 3.1 KB
Line 
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
22using HeuristicLab.Collections;
23using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
24
25namespace HeuristicLab.Core {
26  /// <summary>
27  /// A base class for items which have a name and contain parameters.
28  /// </summary>
29  [Item("ParameterizedNamedItem", "A base class for items which have a name and contain parameters.")]
30  [StorableClass]
31  public abstract class ParameterizedNamedItem : NamedItem, IParameterizedNamedItem {
32    private ParameterCollection parameters;
33    [Storable]
34    protected ParameterCollection Parameters {
35      get { return parameters; }
36      private set {
37        parameters = value;
38        readOnlyParameters = null;
39      }
40    }
41    private ReadOnlyObservableKeyedCollection<string, IParameter> readOnlyParameters;
42    IObservableKeyedCollection<string, IParameter> IParameterizedItem.Parameters {
43      get {
44        if (readOnlyParameters == null) readOnlyParameters = parameters.AsReadOnly();
45        return readOnlyParameters;
46      }
47    }
48
49    protected ParameterizedNamedItem()
50      : base() {
51      name = ItemName;
52      description = ItemDescription;
53      Parameters = new ParameterCollection();
54      readOnlyParameters = null;
55    }
56    protected ParameterizedNamedItem(string name)
57      : base(name) {
58      description = ItemDescription;
59      Parameters = new ParameterCollection();
60      readOnlyParameters = null;
61    }
62    protected ParameterizedNamedItem(string name, ParameterCollection parameters)
63      : base(name) {
64      description = ItemDescription;
65      Parameters = parameters;
66      readOnlyParameters = null;
67    }
68    protected ParameterizedNamedItem(string name, string description)
69      : base(name, description) {
70      Parameters = new ParameterCollection();
71      readOnlyParameters = null;
72    }
73    protected ParameterizedNamedItem(string name, string description, ParameterCollection parameters)
74      : base(name, description) {
75      Parameters = parameters;
76      readOnlyParameters = null;
77    }
78
79    public override IDeepCloneable Clone(Cloner cloner) {
80      ParameterizedNamedItem clone = (ParameterizedNamedItem)base.Clone(cloner);
81      clone.Parameters = (ParameterCollection)cloner.Clone(parameters);
82      return clone;
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.