public Dictionary <String, String> GetSetRefStateAttrsDictRecursive(CDClassPool ExecutionSpace, String VarName) { Dictionary <String, String> Result = new Dictionary <String, String>(); EXEReferencingSetVariable SetVar = this.FindSetReferencingVariableByName(VarName); if (SetVar == null) { return(Result); } int i = 0; Console.WriteLine(VarName + " has cardinality " + SetVar.GetReferencingVariables().Count()); foreach (EXEReferencingVariable Var in SetVar.GetReferencingVariables()) { CDClassInstance Inst = Var.RetrieveReferencedClassInstance(ExecutionSpace); if (Inst == null) { i++; continue; } foreach (var Attribute in Inst.GetStateWithoutID()) { Result[VarName + "[" + i + "]." + Attribute.Key] = Attribute.Value; } i++; } return(Result); }
public Dictionary <String, String> GetRefStateAttrsDictRecursive(CDClassPool ExecutionSpace) { Dictionary <String, String> Result = new Dictionary <String, String>(); EXEScope CurrentScope = this; while (CurrentScope != null) { foreach (EXEReferencingVariable Var in CurrentScope.ReferencingVariables) { CDClassInstance Inst = Var.RetrieveReferencedClassInstance(ExecutionSpace); if (Inst == null) { continue; } foreach (var Attribute in Inst.GetStateWithoutID()) { Result[Var.Name + "." + Attribute.Key] = Attribute.Value; } } CurrentScope = CurrentScope.SuperScope; } return(Result); }
public CDClassInstance CreateClassInstance() { long NewInstanceID = EXEInstanceIDSeed.GetInstance().GenerateID(); CDClassInstance Instance = new CDClassInstance(NewInstanceID, this.Attributes); this.Instances.Add(Instance); return(Instance); }
// SetUloh1 public CDClassInstance RetrieveReferencedClassInstance(CDClassPool ExecutionSpace) { CDClass Class = ExecutionSpace.getClassByName(this.ClassName); if (Class == null) { return(null); } CDClassInstance Instance = Class.GetInstanceByID(this.ReferencedInstanceId); return(Instance); }
public CDClassInstance GetInstanceByID(long id) { CDClassInstance Result = null; foreach (CDClassInstance ClassInstance in this.Instances) { if (ClassInstance.UniqueID == id) { Result = ClassInstance; } } return(Result); }
public CDClassInstance GetClassInstanceById(String ClassName, long Id) { CDClassInstance Result = null; foreach (CDClass Class in this.ClassPool) { if (String.Equals(Class.Name, ClassName)) { Result = Class.GetInstanceByID(Id); } } return(Result); }
//SetUloh1 // We have variable name, attribute name and scope, in which to look for variable // We need to get the value of given attribute of given variable // If this does not exist, return null // You will use EXEScope.FindReferencingVariableByName() method, but you need to implement it first // user.name public String EvaluateAttributeValue(String ReferencingVariableName, String AttributeName, EXEScope Scope, CDClassPool ExecutionSpace) { EXEReferencingVariable ReferencingVariable = Scope.FindReferencingVariableByName(ReferencingVariableName); if (ReferencingVariable == null) { return(null); } CDClassInstance ClassInstance = ExecutionSpace.GetClassInstanceById(ReferencingVariable.ClassName, ReferencingVariable.ReferencedInstanceId); if (ClassInstance == null) { return(null); } return(ClassInstance.GetAttributeValue(AttributeName)); }
// SetUloh2 public override bool Execute(OALProgram OALProgram, EXEScope Scope) { //Create an instance of given class -> will affect ExecutionSpace. //If ReferencingVariableName is provided (is not ""), create a referencing variable pointing to this instance -> will affect scope CDClass Class = OALProgram.ExecutionSpace.getClassByName(this.ClassName); if (Class == null) { return(false); } EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.ReferencingVariableName); if (Variable != null) { if (!String.Equals(this.ClassName, Variable.ClassName)) { return(false); } } CDClassInstance Instance = Class.CreateClassInstance(); if (Instance == null) { return(false); } if (!"".Equals(this.ReferencingVariableName)) { if (Variable != null) { Variable.ReferencedInstanceId = Instance.UniqueID; } else { Variable = new EXEReferencingVariable(this.ReferencingVariableName, Class.Name, Instance.UniqueID); return(Scope.AddVariable(Variable)); } } return(true); }
//SetUloh1 // Similar as task above, but this time we set the attribute value to "NewValue" parameter // But it's not that easy, you need to check if attribute type and NewValue type are the same (e.g. both are integer) // To do that, you need to find the referencing variable's class (via Scope) and then the attribute's type (vie ExecutionSpace) // When you know the type of attribute, use EXETypes.IsValidValue to see if you can or cannot assign that value to that attribute // You assign it in Scope // Return if you could assign it or not // EXETypes.determineVariableType() public Boolean SetAttributeValue(String ReferencingVariableName, String AttributeName, EXEScope Scope, CDClassPool ExecutionSpace, String NewValue) { EXEReferencingVariable ReferencingVariable = Scope.FindReferencingVariableByName(ReferencingVariableName); if (ReferencingVariable == null) { return(false); } CDClassInstance ClassInstance = ExecutionSpace.GetClassInstanceById(ReferencingVariable.ClassName, ReferencingVariable.ReferencedInstanceId); if (ClassInstance == null) { return(false); } CDClass Class = ExecutionSpace.getClassByName(ReferencingVariable.ClassName); if (Class == null) { return(false); } CDAttribute Attribute = Class.GetAttributeByName(AttributeName); if (Attribute == null) { return(false); } String NewValueType = EXETypes.DetermineVariableType(null, NewValue); if (!EXETypes.CanBeAssignedToAttribute(AttributeName, Attribute.Type, NewValueType)) { return(false); } ClassInstance.SetAttribute(AttributeName, EXETypes.AdjustAssignedValue(Attribute.Type, NewValue)); return(true); }
public Dictionary <String, String> GetRefStateAttrsDictRecursive(CDClassPool ExecutionSpace, String VarName) { Dictionary <String, String> Result = new Dictionary <String, String>(); EXEReferencingVariable Var = this.FindReferencingVariableByName(VarName); if (Var == null) { return(Result); } CDClassInstance Inst = Var.RetrieveReferencedClassInstance(ExecutionSpace); if (Inst == null) { return(Result); } foreach (var Attribute in Inst.GetStateWithoutID()) { Result[VarName + "." + Attribute.Key] = Attribute.Value; } return(Result); }
public bool VerifyReferences(EXEScope Scope, CDClassPool ExecutionSpace) { bool Result = false; EXEExpressionEvaluator Evaluator = new EXEExpressionEvaluator(); EXEEvaluatorHandleOperators HandleEvaluator = new EXEEvaluatorHandleOperators(); EXEReferenceEvaluator AccessEvaluator = new EXEReferenceEvaluator(); // If we just calculate with ints, reals, bools, strings if (Evaluator.IsSimpleOperator(this.Operation)) { foreach (EXEASTNode Operand in this.Operands) { if (!Operand.VerifyReferences(Scope, ExecutionSpace)) { return(false); } } Result = true; } // If we have handle operators else if (HandleEvaluator.IsHandleOperator(this.Operation)) { if (this.Operands.Count() == 1 && Scope.FindReferenceHandleByName(((EXEASTNodeLeaf)this.Operands[0]).GetNodeValue()) != null) { Result = true; } } // If we have access operator - we either access attribute or have decimal number. There are always 2 operands else if (".".Equals(this.Operation) && this.Operands.Count == 2) { if (EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) && EXETypes.IntegerTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue())) ) { Result = true; } else if (EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[0].GetNodeValue())) && EXETypes.ReferenceTypeName.Equals(EXETypes.DetermineVariableType("", this.Operands[1].GetNodeValue())) ) { EXEReferencingVariable Variable = Scope.FindReferencingVariableByName(this.Operands[0].GetNodeValue()); if (Variable == null) { return(false); } CDClass Class = ExecutionSpace.getClassByName(Variable.ClassName); if (Class == null) { return(false); } CDAttribute Attribute = Class.GetAttributeByName(this.Operands[1].GetNodeValue()); if (Attribute == null) { return(false); } CDClassInstance Instance = Variable.RetrieveReferencedClassInstance(ExecutionSpace); if (Instance == null) { return(false); } Result = true; } } return(Result); }