Imports Basics
Imports System.ComponentModel
'almacena operaciones con el proposto de devolver bajo demanda un resultado
<TypeConverter(GetType(PropertyParseItem))> _
Public Class EcuationItem
Inherits EcuationItemBase
Protected intOperation As TypeOperation 'indica el tipo de operacion o funcion matematica
Protected ArrayItems As BVArrayList 'array que contiene los items derivados
'los tipos de punteros o resultados que puede tener un Item son:
' intResult As ComplexUndefinied
Protected funcDelegateU() As OperDelegateU
'Protected funcInvDelegateU As OperDelegateU
Protected funcDelegateUU() As OperDelegateUU
#Region "Constructor"
Public Sub New()
MyBase.New(TypeOfVar.pVariableRe, New ComplexUndefinied, "x")
intOperation = TypeOperation.OpPlus
Initialize()
End Sub
Public Sub New(ByVal TypeOfVariable As TypeOfVar, ByVal Expresion As String) 'ByVal Manager As ParseManager)
MyBase.New(TypeOfVariable, Expresion)
intOperation = Operation
Initialize()
End Sub
Public Sub New(ByVal TypeOfVariable As TypeOfVar, ByVal Operation As TypeOperation, ByVal Expresion As String) 'ByVal Manager As ParseManager)
MyBase.New(TypeOfVariable, New ComplexUndefinied, Expresion)
intOperation = Operation
Initialize()
End Sub
Protected Overrides Sub Initialize()
ArrayItems = New BVArrayList
MyBase.Initialize()
End Sub
#End Region
Public Overrides Property Value() As ComplexUndefinied 'resultado
Get
If ArrayItems.Count > 0 Then
'si hay sub elementos dependientes de �ste => resuelvo
If Not funcDelegateU Is Nothing Then
'operador binario
Dim i As Integer
Dim CU As ComplexUndefinied
Dim C2 As ComplexUndefinied
If Me.intOperation = TypeOperation.OpPlus Then
'tomo el primero, lo niego o lo tomo como esta egun corresponda
If CType(ArrayItems(0), EcuationItem).FunctionIndex = 0 Then
CU = CType(ArrayItems(0), EcuationItem).Value
Else
CU = intMath.ComplexNot(CType(ArrayItems(0), EcuationItem).Value)
End If
For i = 1 To Me.ArrayItems.Count - 1
If CType(ArrayItems(i), EcuationItem).FunctionIndex = 0 Then
CU = funcDelegateU(0)(CType(ArrayItems(i), EcuationItem).Value, CU)
Else
CU = funcDelegateU(0)(intMath.ComplexNot(CType(ArrayItems(i), EcuationItem).Value), CU)
End If
Next
ElseIf Me.intOperation = TypeOperation.OpMult Then
CU = CType(ArrayItems(0), EcuationItem).Value
For i = 1 To Me.ArrayItems.Count - 1
CU = funcDelegateU(CType(ArrayItems(i), EcuationItem).FunctionIndex)(CU, CType(ArrayItems(i), EcuationItem).Value)
Next
Else
'guarda el ultimo
CU = CType(ArrayItems(ArrayItems.Count - 1), EcuationItem).Value
For i = Me.ArrayItems.Count - 2 To 0 Step -1
'CU = funcDelegateU(CType(ArrayItems(i), EcuationItem).FunctionIndex)(CType(ArrayItems(i), EcuationItem).Value, CU)
CU = funcDelegateU(CType(ArrayItems(i + 1), EcuationItem).FunctionIndex)(CType(ArrayItems(i), EcuationItem).Value, CU)
Next
End If
intResult = CU
ElseIf Not funcDelegateUU Is Nothing Then
'cuando utilizo el operador unario el array de Items solo contendr� un
'unico Item, un ComplexUndefinied o una referencia a variable
If TypeOf ArrayItems(0) Is EcuationItem Then
intResult = funcDelegateUU(CType(ArrayItems(0), EcuationItem).FunctionIndex)(CType(ArrayItems(0), EcuationItem).Value)
ElseIf TypeOf ArrayItems(0) Is ComplexUndefinied Then
intResult = funcDelegateUU(CType(ArrayItems(0), EcuationItem).FunctionIndex)(ArrayItems(0))
Else
Stop
End If
Else
Stop
End If
End If
'If intMinus Then
' Return Me.intMath.ComplexNot(intResult)
'Else
' Return intResult
'End If
Return intResult
End Get
Set(ByVal Value As ComplexUndefinied)
intResult = Value
End Set
End Property
'cuenta de los items dependientes
Public ReadOnly Property Count()
Get
Return Me.ArrayItems.Count
End Get
End Property
'permite asignar al primer array de funciones el delegado correspondiente
<Browsable(False)> _
Public Property funcDelegate() As [Delegate]
Get
If Not funcDelegateU Is Nothing Then
Return Me.funcDelegateU(0)
ElseIf Not funcDelegateUU Is Nothing Then
Return Me.funcDelegateUU(0)
Else
'Stop
Return Nothing
End If
End Get
Set(ByVal Value As [Delegate])
If TypeOf Value Is OperDelegateU Then
ResizeArrayU()
funcDelegateU(0) = Value
ElseIf TypeOf Value Is OperDelegateUU Then
ResizeArrayUU()
funcDelegateUU(0) = Value
Else
Throw New Exception("An functionDelegate must by passed")
Stop
End If
End Set
End Property
'permite asignar al elemento Index del array de funciones el delegado correspondiente
<Browsable(False)> _
Public ReadOnly Property funcDelegate(ByVal index As Integer) As [Delegate]
Get
If Not funcDelegateU Is Nothing Then
Return Me.funcDelegateU(index)
ElseIf Not funcDelegateUU Is Nothing Then
Return Me.funcDelegateUU(index)
Else
Stop
End If
End Get
End Property
'<Browsable(False)> _
Public ReadOnly Property functionDelegateCount() As Integer
Get
If Not funcDelegateU Is Nothing Then
Return Me.funcDelegateU.GetUpperBound(0) + 1
ElseIf Not funcDelegateUU Is Nothing Then
Return Me.funcDelegateUU.GetUpperBound(0) + 1
Else
Return 0
End If
End Get
End Property
Public Property Operation() As TypeOperation
Get
Return intOperation
End Get
Set(ByVal Value As TypeOperation)
intOperation = Value
End Set
End Property
#Region "Funciones"
Public Function GetItem(ByVal Index As Integer) As EcuationItem
If ArrayItems.Count > Index Then
Return ArrayItems(Index)
Else
Stop
End If
End Function
Public Sub AddfuncDelegate(ByVal Value As [Delegate])
If TypeOf Value Is OperDelegateU Then
ResizeArrayU()
funcDelegateU(funcDelegateU.GetUpperBound(0)) = Value
ElseIf TypeOf Value Is OperDelegateUU Then
ResizeArrayUU()
funcDelegateUU(funcDelegateUU.GetUpperBound(0)) = Value
Else
Throw New Exception("An functionDelegate must by passed")
Stop
End If
End Sub
Public Sub Add(ByVal EcItm As EcuationItemBase)
ArrayItems.Add(EcItm)
End Sub
'almacena una constante del tipo ComplexUndefinied
'en ese caso no p�ede contener otros items
Public Sub SetToConstant(ByVal c As ComplexUndefinied)
ArrayItems.Clear()
ArrayItems.Add(c)
End Sub
Public Sub Reset()
ArrayItems.Clear()
End Sub
Protected Sub ResizeArrayU()
If funcDelegateU Is Nothing Then
ReDim Preserve funcDelegateU(0)
Else
ReDim Preserve funcDelegateU(funcDelegateU.GetUpperBound(0) + 1)
End If
End Sub
Protected Sub ResizeArrayUU()
If funcDelegateUU Is Nothing Then
ReDim Preserve funcDelegateUU(0)
Else
ReDim Preserve funcDelegateUU(funcDelegateUU.GetUpperBound(0) + 1)
End If
End Sub
#End Region
End Class