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