Skip to content

Commit

Permalink
Merge pull request #119 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
Merge in master
  • Loading branch information
lilyclements authored Jan 31, 2017
2 parents e462bd9 + e2cbda2 commit fecdd52
Show file tree
Hide file tree
Showing 26 changed files with 1,925 additions and 973 deletions.
58 changes: 58 additions & 0 deletions instat/clsCondition.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Public Class Condition
Private bIsParameterValues As Boolean = False
Private bIsParameterPresenet As Boolean = False
Private bIsFunctionNames As Boolean = False
Private strParameterName As String = ""
Private lstValues As List(Of String) = New List(Of String)

Public Sub SetParameterPresentName(strParamName As String)
strParameterName = strParamName
bIsParameterPresenet = True
bIsParameterValues = False
bIsFunctionNames = False
End Sub

Public Sub SetParameterValues(strParamName As String, lstParamValues As List(Of String))
strParameterName = strParamName
lstValues = lstParamValues
bIsParameterValues = True
bIsParameterPresenet = False
bIsFunctionNames = False
End Sub

Public Sub SetParameterValues(strParamName As String, strParamValues As String)
SetParameterValues(strParameterName, New List(Of String)({strParamValues}))
End Sub

Public Sub SetFunctionName(strFuncName As String)
SetFunctionNamesMultiple(New List(Of String)({strFuncName}))
End Sub

Public Sub SetFunctionNamesMultiple(lstFuncNames As List(Of String))
lstValues = lstFuncNames
bIsFunctionNames = True
bIsParameterValues = False
bIsParameterPresenet = False
End Sub

Public Function IsSatisfied(clsRCode As RCodeStructure) As Boolean
Dim clsTempParam As RParameter
Dim clsTempFunc As RFunction

If bIsParameterValues Then
clsTempParam = clsRCode.GetParameter(strParameterName)
Return (clsTempParam IsNot Nothing AndAlso clsTempParam.bIsString AndAlso clsTempParam.strArgumentValue IsNot Nothing AndAlso lstValues.Contains(clsRCode.GetParameter(strParameterName).strArgumentValue))
ElseIf bIsParameterPresenet Then
Return (clsRCode.ContainsParameter(strParameterName))
ElseIf bIsFunctionNames Then
If TypeOf clsRCode Is RFunction Then
clsTempFunc = CType(clsRCode, RFunction)
Return lstValues.Contains(clsTempFunc.strRCommand)
Else
Return False
End If
Else
Return True
End If
End Function
End Class
17 changes: 7 additions & 10 deletions instat/clsRCodeStructure.vb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ Public Class RCodeStructure
clsParam.SetArgument(clsROperatorParameter)
End If
clsParam.bIncludeArgumentName = bIncludeArgumentName
AddParameter(clsParam, iPosition)
clsParam.Position = iPosition
AddParameter(clsParam)
End Sub

'TODO This should be call AddParameter but need to make it unambiguous with above
Expand All @@ -213,20 +214,16 @@ Public Class RCodeStructure
End If
End Sub

Public Overridable Sub AddParameter(clsNewParam As RParameter, Optional iPosition As Integer = -1)
Public Overridable Sub AddParameter(clsNewParam As RParameter)
Dim i As Integer = -1
Dim strTempArgumentName As String = clsNewParam.strArgumentName
clsNewParam.Position = iPosition
If clsNewParam.strArgumentName Is Nothing Then
Dim x = 1
End If
If clsParameters IsNot Nothing Then
If clsNewParam.strArgumentName IsNot Nothing Then
'Dim match As Predicate(Of RParameter) = Function(x) x.strArgumentName.Equals(clsParam.strArgumentName)
i = clsParameters.FindIndex(Function(x) x.strArgumentName.Equals(strTempArgumentName))
End If
If i = -1 Then
ShiftParametersPositions(iPosition) 'Checking if there is room in the parameter's positions to add a parameter with position = iPosition
ShiftParametersPositions(clsNewParam.Position) 'Checking if there is room in the parameter's positions to add a parameter with position = iPosition
clsParameters.Add(clsNewParam)
Else
If clsNewParam.bIsString AndAlso clsNewParam.strArgumentValue IsNot Nothing Then
Expand All @@ -236,12 +233,12 @@ Public Class RCodeStructure
Else
'message
End If
If clsParameters(i).Position <> iPosition Then
If clsParameters(i).Position <> clsNewParam.Position Then
'In case the position needs to be changed, there might exist another parameter with the new position in the list
'The parameter i is then temporarily set to unordered until the Shift in positions has been operated within the clsParameters (if necessary).
clsParameters(i).Position = -1
If iPosition <> -1 Then
ShiftParametersPositions(iPosition)
If clsNewParam.Position <> -1 Then
ShiftParametersPositions(clsNewParam.Position)
clsParameters(i).Position = clsNewParam.Position
End If
End If
Expand Down
5 changes: 3 additions & 2 deletions instat/clsRFunction.vb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ Public Class RFunction
Public Overrides Sub AddParameter(Optional strParameterName As String = "", Optional strParameterValue As String = "", Optional clsRFunctionParameter As RFunction = Nothing, Optional clsROperatorParameter As ROperator = Nothing, Optional bIncludeArgumentName As Boolean = True, Optional iPosition As Integer = -1)
MyBase.AddParameter(strParameterName, strParameterValue, clsRFunctionParameter, clsROperatorParameter, bIncludeArgumentName, iPosition)
End Sub
Public Overrides Sub AddParameter(clsParam As RParameter, Optional iPosition As Integer = -1)
MyBase.AddParameter(clsParam, iPosition)

Public Overrides Sub AddParameter(clsParam As RParameter)
MyBase.AddParameter(clsParam)
End Sub

Public Overrides Function GetParameter(strName As String) As RParameter
Expand Down
4 changes: 2 additions & 2 deletions instat/clsROperator.vb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Public Class ROperator
End Function


Public Overrides Sub AddParameter(clsParam As RParameter, Optional iPosition As Integer = -1)
Public Overrides Sub AddParameter(clsParam As RParameter)
clsParam.bIncludeArgumentName = False 'We don't want to allow names in operator parameters...
MyBase.AddParameter(clsParam, iPosition)
MyBase.AddParameter(clsParam)
End Sub

Public Overrides Function GetParameter(strName As String) As RParameter
Expand Down
5 changes: 3 additions & 2 deletions instat/clsRParameter.vb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ Public Class RParameter
Public bIsString As Boolean = False
'iPosition determines the position this parameter should take among other parameters of an Operator or Function. If iPosition is 0, then it is part of the unordered parameters that are added after the ordered ones.
'Note, it is allowed to have gaps in the positions: parameters with positions a 0, b 2, c 5, d 3, e 0 will be sorted as b d c (a e). See CompareParametersPosition in clsRCodeStructure.
Private iPosition As Integer = 0
Private iPosition As Integer = -1
'See strArgumentName
Public bIncludeArgumentName As Boolean = True

Public Sub New()
End Sub

Public Sub New(strParameterName As String)
Public Sub New(strParameterName As String, Optional iNewPosition As Integer = -1)
SetArgumentName(strParameterName)
Position = iNewPosition
End Sub

''Public Event PositionChanged()
Expand Down
93 changes: 40 additions & 53 deletions instat/dlgAppend.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fecdd52

Please sign in to comment.