- Timestamp:
- 10/07/14 08:32:58 (10 years ago)
- Location:
- branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj
r11412 r11421 48 48 </ItemGroup> 49 49 <ItemGroup> 50 <Compile Include="IPort.cs" /> 50 51 <Compile Include="IVariablesNode.cs" /> 52 <Compile Include="Port.cs" /> 51 53 <Compile Include="VariablesNode.cs" /> 52 54 <Compile Include="EventArgs.cs" /> … … 61 63 <Compile Include="INetwork.cs" /> 62 64 <Compile Include="IInputPort.cs" /> 63 <Compile Include="I Port.cs" />65 <Compile Include="IValuePort.cs" /> 64 66 <Compile Include="INode.cs" /> 65 67 <Compile Include="Network.cs" /> … … 67 69 <Compile Include="NodeCollection.cs" /> 68 70 <Compile Include="PortCollection.cs" /> 69 <Compile Include=" Port.cs" />71 <Compile Include="ValuePort.cs" /> 70 72 <Compile Include="Plugin.cs" /> 71 73 <Compile Include="Properties\AssemblyInfo.cs" /> -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputOutputPort.cs
r11412 r11421 24 24 25 25 namespace HeuristicLab.Optimization.Networks { 26 public interface IInputOutputPort : I Port {26 public interface IInputOutputPort : IValuePort { 27 27 IOutputInputPort OutputInputPort { get; } 28 28 … … 30 30 } 31 31 32 public interface IInputOutputPort<TIn, TOut> : IInputOutputPort, I Port<TIn>32 public interface IInputOutputPort<TIn, TOut> : IInputOutputPort, IValuePort<TIn> 33 33 where TIn : class, IItem 34 34 where TOut : class, IItem { -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputPort.cs
r11412 r11421 24 24 25 25 namespace HeuristicLab.Optimization.Networks { 26 public interface IInputPort : I Port {26 public interface IInputPort : IValuePort { 27 27 IOutputPort OutputPort { get; set; } 28 28 … … 30 30 } 31 31 32 public interface IInputPort<T> : IInputPort, I Port<T> where T : class, IItem {32 public interface IInputPort<T> : IInputPort, IValuePort<T> where T : class, IItem { 33 33 new IOutputPort<T> OutputPort { get; set; } 34 34 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputInputPort.cs
r11406 r11421 24 24 25 25 namespace HeuristicLab.Optimization.Networks { 26 public interface IOutputInputPort : I Port {26 public interface IOutputInputPort : IValuePort { 27 27 object SendValue(object value); 28 28 } 29 29 30 public interface IOutputInputPort<TOut, TIn> : IOutputInputPort, I Port<TOut>30 public interface IOutputInputPort<TOut, TIn> : IOutputInputPort, IValuePort<TOut> 31 31 where TOut : class, IItem 32 32 where TIn : class, IItem { -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputPort.cs
r11401 r11421 23 23 24 24 namespace HeuristicLab.Optimization.Networks { 25 public interface IOutputPort : I Port {25 public interface IOutputPort : IValuePort { 26 26 new object Value { get; set; } 27 27 } 28 28 29 public interface IOutputPort<T> : IOutputPort, I Port<T> where T : class, IItem {29 public interface IOutputPort<T> : IOutputPort, IValuePort<T> where T : class, IItem { 30 30 new T Value { get; set; } 31 31 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IPort.cs
r11409 r11421 21 21 22 22 using HeuristicLab.Core; 23 using System;24 23 25 24 namespace HeuristicLab.Optimization.Networks { 26 25 public interface IPort : INamedItem { 27 //DISCUSS: Should there be a reference to the node of this port? 28 29 object Value { get; } 30 31 event EventHandler ValueChanged; 32 } 33 34 public interface IPort<T> : IPort where T : class, IItem { 35 new T Value { get; } 26 INode Node { get; set; } 36 27 } 37 28 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputOutputPort.cs
r11412 r11421 28 28 [Item("InputOutputPort", "A synchronous input/output port of an optimization network node.")] 29 29 [StorableClass] 30 public class InputOutputPort<TIn, TOut> : Port<TIn>, IInputOutputPort<TIn, TOut>30 public class InputOutputPort<TIn, TOut> : ValuePort<TIn>, IInputOutputPort<TIn, TOut> 31 31 where TIn : class, IItem 32 32 where TOut : class, IItem { -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs
r11412 r11421 29 29 [Item("InputPort", "An asynchronous input port of an optimization network node.")] 30 30 [StorableClass] 31 public class InputPort<T> : Port<T>, IInputPort<T> where T : class, IItem {31 public class InputPort<T> : ValuePort<T>, IInputPort<T> where T : class, IItem { 32 32 public static new Image StaticItemImage { 33 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.ArrowDown; } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Node.cs
r11401 r11421 56 56 public Node() 57 57 : base("Node") { 58 ports = new PortCollection( );58 ports = new PortCollection(this); 59 59 readOnlyPorts = null; 60 60 } 61 61 public Node(string name) 62 62 : base(name) { 63 ports = new PortCollection( );63 ports = new PortCollection(this); 64 64 readOnlyPorts = null; 65 65 } 66 66 public Node(string name, string description) 67 67 : base(name, description) { 68 ports = new PortCollection( );68 ports = new PortCollection(this); 69 69 readOnlyPorts = null; 70 70 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputInputPort.cs
r11406 r11421 28 28 [Item("OutputInputPort", "A synchronous output/input port of an optimization network node.")] 29 29 [StorableClass] 30 public class OutputInputPort<TOut, TIn> : Port<TOut>, IOutputInputPort<TOut, TIn>30 public class OutputInputPort<TOut, TIn> : ValuePort<TOut>, IOutputInputPort<TOut, TIn> 31 31 where TOut : class, IItem 32 32 where TIn : class, IItem { -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputPort.cs
r11409 r11421 29 29 [Item("OutputPort", "An asynchronous output port of an optimization network node.")] 30 30 [StorableClass] 31 public class OutputPort<T> : Port<T>, IOutputPort<T> where T : class, IItem {31 public class OutputPort<T> : ValuePort<T>, IOutputPort<T> where T : class, IItem { 32 32 public static new Image StaticItemImage { 33 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.ArrowUp; } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs
r11406 r11421 29 29 [Item("Port", "Abstract base class for ports of an optimization network node.")] 30 30 [StorableClass] 31 public abstract class Port <T> : NamedItem, IPort<T> where T : class, IItem{31 public abstract class Port : NamedItem, IPort { 32 32 public static new Image StaticItemImage { 33 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; } … … 35 35 36 36 [Storable] 37 protected T value; 38 public virtual T Value { 39 get { return value; } 40 protected set { 41 DeregisterValueEvents(); 42 this.value = value; 43 RegisterValueEvents(); 44 OnValueChanged(); 37 private INode node; 38 public INode Node { 39 get { return node; } 40 set { 41 if ((value != null) && !value.Ports.Contains(this)) 42 throw new InvalidOperationException("Port is not contained in port collection of node."); 43 if ((value == null) && node.Ports.Contains(this)) 44 throw new InvalidOperationException("Port is still contained in port collection of node."); 45 node = value; 45 46 } 46 }47 object IPort.Value {48 get { return Value; }49 47 } 50 48 51 49 [StorableConstructor] 52 50 protected Port(bool deserializing) : base(deserializing) { } 53 protected Port(Port <T>original, Cloner cloner)51 protected Port(Port original, Cloner cloner) 54 52 : base(original, cloner) { 55 value = cloner.Clone(original.value); 56 RegisterValueEvents(); 53 node = (INode)cloner.GetClone(original.node); // NOTE: original node is NOT automatically cloned 57 54 } 58 55 protected Port() : base("Port") { } 59 56 protected Port(string name) : base(name) { } 60 57 protected Port(string name, string description) : base(name, description) { } 61 62 [StorableHook(HookType.AfterDeserialization)]63 private void AfterDeserialization() {64 RegisterValueEvents();65 }66 67 public override string ToString() {68 return Name + ": " + (Value != null ? Value.ToString() : "null");69 }70 71 public event EventHandler ValueChanged;72 protected virtual void OnValueChanged() {73 var handler = ValueChanged;74 if (handler != null) handler(this, EventArgs.Empty);75 OnToStringChanged();76 }77 78 protected virtual void RegisterValueEvents() {79 if (value != null) {80 value.ToStringChanged += new EventHandler(Value_ToStringChanged);81 }82 }83 protected virtual void DeregisterValueEvents() {84 if (value != null) {85 value.ToStringChanged -= new EventHandler(Value_ToStringChanged);86 }87 }88 private void Value_ToStringChanged(object sender, EventArgs e) {89 OnToStringChanged();90 }91 58 } 92 59 } -
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/PortCollection.cs
r11401 r11421 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 using System; 26 using System.Collections.Generic; 26 27 27 28 namespace HeuristicLab.Optimization.Networks { 28 29 [StorableClass] 29 [Item("PortCollection", "Represents a collection of ports .")]30 [Item("PortCollection", "Represents a collection of ports in an optimization network node.")] 30 31 public class PortCollection : NamedItemCollection<IPort> { 32 [Storable] 33 private INode node; 34 public INode Node { 35 get { return node; } 36 } 37 31 38 [StorableConstructor] 32 39 protected PortCollection(bool deserializing) : base(deserializing) { } 33 protected PortCollection(PortCollection original, Cloner cloner) : base(original, cloner) { } 34 public PortCollection() : base() { } 35 public PortCollection(int capacity) : base(capacity) { } 36 public PortCollection(IEnumerable<IPort> collection) : base(collection) { } 40 protected PortCollection(PortCollection original, Cloner cloner) 41 : base(original, cloner) { 42 if (!cloner.ClonedObjectRegistered(original.node)) 43 // NOTE: cannot clone port collection alone if referenced node is not cloned 44 throw new InvalidOperationException("Node of port collection is not cloned."); 45 node = cloner.Clone(original.node); 46 } 47 public PortCollection(INode node) 48 : base() { 49 this.node = node; 50 } 51 public PortCollection(INode node, int capacity) 52 : base(capacity) { 53 this.node = node; 54 } 55 public PortCollection(INode node, IEnumerable<IPort> collection) 56 : base(collection) { 57 this.node = node; 58 } 37 59 38 60 public override IDeepCloneable Clone(Cloner cloner) { return new PortCollection(this, cloner); } 61 62 protected override void OnItemsAdded(IEnumerable<IPort> items) { 63 foreach (var p in items) 64 p.Node = node; 65 base.OnItemsAdded(items); 66 } 67 protected override void OnItemsRemoved(IEnumerable<IPort> items) { 68 foreach (var p in items) 69 p.Node = null; 70 base.OnItemsRemoved(items); 71 } 72 protected override void OnItemsReplaced(IEnumerable<IPort> items, IEnumerable<IPort> oldItems) { 73 foreach (var p in oldItems) 74 p.Node = null; 75 foreach (var p in items) 76 p.Node = node; 77 base.OnItemsReplaced(items, oldItems); 78 } 79 protected override void OnCollectionReset(IEnumerable<IPort> items, IEnumerable<IPort> oldItems) { 80 foreach (var p in oldItems) 81 p.Node = null; 82 foreach (var p in items) 83 p.Node = node; 84 base.OnCollectionReset(items, oldItems); 85 } 39 86 } 40 87 }
Note: See TracChangeset
for help on using the changeset viewer.