#region License Information /* HeuristicLab * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Collections; using System.Linq; using System.Text; using System.Xml; using System.Globalization; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.DataImporter.Data.Model { [StorableClass] public class ProgrammableColumn : ColumnBase { private DynamicValueList dynamicValues; [Storable] private int myIndexInColumnGroup; private ProgrammableColumn() : base(string.Empty) { this.DataType = typeof(double?); } public ProgrammableColumn(string columnName, ColumnGroup columnGroup) : base(columnName) { this.DataType = typeof(double?); this.ColumnGroup = columnGroup; Expression = string.Empty; } private string expression; [Storable] public string Expression { get { return expression; } set { expression = value; dynamicValues = new DynamicValueList(expression, columnGroup); dynamicValues.RecursiveIndex = myIndexInColumnGroup; } } private ColumnGroup columnGroup; [Storable] private ColumnGroup ColumnGroup { get { return this.columnGroup; } set { if (this.columnGroup != null) this.columnGroup.Changed -= new EventHandler(columnGroup_Changed); this.columnGroup = value; RefreshMyIndex(); if (this.columnGroup != null) columnGroup.Changed += new EventHandler(columnGroup_Changed); } } public void columnGroup_Changed(object sender, EventArgs e) { RefreshMyIndex(); dynamicValues.RecursiveIndex = myIndexInColumnGroup; } private void RefreshMyIndex() { // find the index of this column to prevent recursive expressions for (int i = 0; i < columnGroup.Columns.Count(); i++) { if (columnGroup.GetColumn(i) == this) { myIndexInColumnGroup = i; return; } } myIndexInColumnGroup = columnGroup.Columns.Count(); } public override string ToString() { return base.ToString() + " \n" + expression; } protected override IList Values { get { return (IList)dynamicValues; } } public override void AddValue(IComparable value) { dynamicValues.IncreaseLength(); } public override void AddValueOrNull(IComparable value) { dynamicValues.IncreaseLength(); } public override void InsertValue(int position, IComparable value) { dynamicValues.IncreaseLength(); } public override void ChangeValue(int position, IComparable value) { throw new NotSupportedException("Can't change values of a programmable column"); } public override void ChangeValueOrNull(int position, IComparable value) { throw new NotSupportedException("Can't change values of a programmable column"); } public override void ChangeValueOrLeaveOldValue(int position, IComparable value) { throw new NotSupportedException("Can't change values of a programmable column"); } public override ColumnBase CreateCopyOfColumnWithoutValues(int capacity) { return CreateCopyOfColumnWithoutValues(); } public override ColumnBase CreateCopyOfColumnWithoutValues() { ProgrammableColumn clone = new ProgrammableColumn(this.Name, this.columnGroup); clone.Expression = expression; return clone; } } }