/// <summary> /// Creates a property reference. /// </summary> /// <param name="nHolder"> A holder of string representation of the name. </param> /// <param name="varIndex"> An index in a result during evaluation. </param> /// <param name="propID"> An ID of the accessed property. </param> public VariablePropertyReference(VariableReferenceNameHolder nHolder, int varIndex, int propID) : base(nHolder, varIndex) { if (propID < 0) { throw new ArgumentException($"{this.GetType()}, property ID must be >= 0, propID == {propID}."); } this.PropertyID = propID; }
/// <summary> /// Creates a variable reference. /// </summary> /// <param name="nHolder"> A holder of string representation of the name. </param> /// <param name="varIndex"> An index of an element in a result during evaluation.</param> protected VariableReference(VariableReferenceNameHolder nHolder, int varIndex) { if (nHolder == null) { throw new ArgumentNullException($"{this.GetType()}, trying to assign null to a construtor."); } else if (varIndex < 0) { throw new ArgumentException($"{this.GetType()}, variable index must be >= 0, index == {varIndex}."); } this.NameHolder = nHolder; this.VariableIndex = varIndex; }
/// <summary> /// If it consists only of a name, variable id reference is created. /// Otherwise property reference will be created. /// </summary> public void Visit(VariableNode node) { this.nameHolder = new VariableReferenceNameHolder(); if (node.name == null) { throw new ArgumentException($"{this.GetType()}, expected name of a variable."); } else { node.name.Accept(this); if (node.propName != null) { node.propName.Accept(this); } } // Get the position of the variable in the result. int varIndex = this.variableMap.GetVariablePosition(this.nameHolder.Name); if (this.nameHolder.PropName == null) { this.expr = new VariableIDReference(this.nameHolder, varIndex); } else { // Get type of accessed property. if (!this.labels.TryGetValue(this.nameHolder.PropName, out Tuple <int, Type> tuple)) { throw new ArgumentException($"{this.GetType()}, property {this.nameHolder.PropName} does not exists in the graph."); } else { this.expr = VariableReferencePropertyFactory.Create(this.nameHolder, varIndex, tuple.Item2, tuple.Item1); } } }
/// <summary> /// Constructs an id reference. /// </summary> /// <param name="nHolder"> A holder of string representation of the name.</param> /// <param name="varIndex"> An index in a result during evaluation.</param> public VariableIDReference(VariableReferenceNameHolder nHolder, int varIndex) : base(nHolder, varIndex) { }