Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.DataImporter/HeuristicLab.DataImporter.Data/Model/ProgrammableColumn.cs @ 16824

Last change on this file since 16824 was 16567, checked in by gkronber, 6 years ago

#2520: changed StorableConstructors and added StorableType attributes in HeuristicLab.DataImporter addon

File size: 4.3 KB
RevLine 
[6134]1#region License Information
2/* HeuristicLab
[9615]3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[6134]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 System;
[6133]23using System.Collections;
24using System.Linq;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[16566]26using HEAL.Attic;
[6133]27
28namespace HeuristicLab.DataImporter.Data.Model {
[16566]29  [StorableType("5FAE0F69-2400-4DB9-AA1B-C80298C77A77")]
[6133]30  public class ProgrammableColumn : ColumnBase {
31    private DynamicValueList dynamicValues;
32    [Storable]
33    private int myIndexInColumnGroup;
34
[9614]35    [StorableConstructor]
[16567]36    protected ProgrammableColumn(StorableConstructorFlag _) : base(_) { }
[6133]37
38    public ProgrammableColumn(string columnName, ColumnGroup columnGroup)
39      : base(columnName) {
40      this.ColumnGroup = columnGroup;
41      Expression = string.Empty;
42    }
43
[9614]44    public override Type DataType {
45      get { return typeof(double?); }
46    }
47
[6133]48    private string expression;
49    [Storable]
50    public string Expression {
51      get { return expression; }
52      set {
53        expression = value;
54        dynamicValues = new DynamicValueList(expression, columnGroup);
55        dynamicValues.RecursiveIndex = myIndexInColumnGroup;
56      }
57    }
58
59    private ColumnGroup columnGroup;
60    [Storable]
61    private ColumnGroup ColumnGroup {
62      get { return this.columnGroup; }
63      set {
64        if (this.columnGroup != null)
65          this.columnGroup.Changed -= new EventHandler(columnGroup_Changed);
66        this.columnGroup = value;
67        RefreshMyIndex();
68        if (this.columnGroup != null)
69          columnGroup.Changed += new EventHandler(columnGroup_Changed);
70      }
71    }
72
73    public void columnGroup_Changed(object sender, EventArgs e) {
74      RefreshMyIndex();
75      dynamicValues.RecursiveIndex = myIndexInColumnGroup;
76    }
77
78    private void RefreshMyIndex() {
79      // find the index of this column to prevent recursive expressions
80      for (int i = 0; i < columnGroup.Columns.Count(); i++) {
81        if (columnGroup.GetColumn(i) == this) {
82          myIndexInColumnGroup = i;
83          return;
84        }
85      }
86      myIndexInColumnGroup = columnGroup.Columns.Count();
87    }
88
89    public override string ToString() {
90      return base.ToString() + " <Programmable>\n" + expression;
91    }
92
93    protected override IList Values {
94      get { return (IList)dynamicValues; }
95    }
96
97    public override void AddValue(IComparable value) {
98      dynamicValues.IncreaseLength();
99    }
100
101    public override void AddValueOrNull(IComparable value) {
102      dynamicValues.IncreaseLength();
103    }
104
105    public override void InsertValue(int position, IComparable value) {
106      dynamicValues.IncreaseLength();
107    }
108
109    public override void ChangeValue(int position, IComparable value) {
110      throw new NotSupportedException("Can't change values of a programmable column");
111    }
112
113    public override void ChangeValueOrNull(int position, IComparable value) {
114      throw new NotSupportedException("Can't change values of a programmable column");
115    }
116
117    public override void ChangeValueOrLeaveOldValue(int position, IComparable value) {
118      throw new NotSupportedException("Can't change values of a programmable column");
119    }
120
121    public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) {
122      return CreateCopyOfColumnWithoutValues();
123    }
124
125    public override ColumnBase CreateCopyOfColumnWithoutValues() {
126      ProgrammableColumn clone = new ProgrammableColumn(this.Name, this.columnGroup);
127      clone.Expression = expression;
128      return clone;
129    }
130  }
131}
Note: See TracBrowser for help on using the repository browser.