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 |
|
---|
22 | using HeuristicLab.Collections;
|
---|
23 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
24 |
|
---|
25 | namespace 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 | public abstract class ParameterizedNamedItem : NamedItem, IParameterizedNamedItem {
|
---|
31 | private ParameterCollection parameters;
|
---|
32 | [Storable]
|
---|
33 | protected ParameterCollection Parameters {
|
---|
34 | get { return parameters; }
|
---|
35 | private set {
|
---|
36 | if (parameters != null) parameters.Changed -= new ChangedEventHandler(Parameters_Changed);
|
---|
37 | parameters = value;
|
---|
38 | readOnlyParameters = null;
|
---|
39 | if (parameters != null) parameters.Changed += new ChangedEventHandler(Parameters_Changed);
|
---|
40 | }
|
---|
41 | }
|
---|
42 | private ReadOnlyObservableKeyedCollection<string, IParameter> readOnlyParameters;
|
---|
43 | IObservableKeyedCollection<string, IParameter> IParameterizedItem.Parameters {
|
---|
44 | get {
|
---|
45 | if (readOnlyParameters == null) readOnlyParameters = parameters.AsReadOnly();
|
---|
46 | return readOnlyParameters;
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | protected ParameterizedNamedItem()
|
---|
51 | : base() {
|
---|
52 | name = ItemName;
|
---|
53 | description = ItemDescription;
|
---|
54 | Parameters = new ParameterCollection();
|
---|
55 | readOnlyParameters = null;
|
---|
56 | }
|
---|
57 | protected ParameterizedNamedItem(string name)
|
---|
58 | : base(name) {
|
---|
59 | description = ItemDescription;
|
---|
60 | Parameters = new ParameterCollection();
|
---|
61 | readOnlyParameters = null;
|
---|
62 | }
|
---|
63 | protected ParameterizedNamedItem(string name, ParameterCollection parameters)
|
---|
64 | : base(name) {
|
---|
65 | description = ItemDescription;
|
---|
66 | Parameters = parameters;
|
---|
67 | readOnlyParameters = null;
|
---|
68 | }
|
---|
69 | protected ParameterizedNamedItem(string name, string description)
|
---|
70 | : base(name, description) {
|
---|
71 | Parameters = new ParameterCollection();
|
---|
72 | readOnlyParameters = null;
|
---|
73 | }
|
---|
74 | protected ParameterizedNamedItem(string name, string description, ParameterCollection parameters)
|
---|
75 | : base(name, description) {
|
---|
76 | Parameters = parameters;
|
---|
77 | readOnlyParameters = null;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
81 | ParameterizedNamedItem clone = (ParameterizedNamedItem)base.Clone(cloner);
|
---|
82 | clone.Parameters = (ParameterCollection)cloner.Clone(parameters);
|
---|
83 | return clone;
|
---|
84 | }
|
---|
85 |
|
---|
86 | private void Parameters_Changed(object sender, ChangedEventArgs e) {
|
---|
87 | OnChanged(e);
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|