/// <summary>
 /// Hash the GElement whose output has been updated to find which input
 /// it is connected to, then return or set the value associated with it.
 /// </summary>
 /// <param name="g">The GElement whose output was updated</param>
 /// <exception cref="KeyNotFoundException">Thrown if input GElement can't be found</exception>
 public bool this[GElement g]
 {
     get
     {
         int i = 0;
         if (inputs.TryGetValue(g, out i))
         {
             return inputCache[i];
         }
         else
         {
             throw new KeyNotFoundException();
         }
     }
     set
     {
         int i = 0;
         if (inputs.TryGetValue(g, out i))
         {
             if (value != inputCache[i])
             {
                 inputCache[i] = value;
             }
         }
         else
         {
             throw new KeyNotFoundException();
         }
     }
 }
示例#2
0
 /// <summary>
 /// Change the input of this GPrimitive. May remove in favor of event handler
 /// Future note: Add "if" statement to prevent calling Propagate() unless
 /// the value set is different from the value that was already in place.
 /// </summary>
 /// <param name="inputElement">The element sending the updated output</param>
 /// <param name="value">The new value</param>
 public async void SetInput(GElement inputElement, bool value)
 {
     // Map the sending GElement to its input
     for (int i = 0; i < InputElements.Length; i++) // Todo: replace with input values container code
     {
         // Once found, set the value 
         if (InputElements[i] == inputElement)
         {
             bool succeeded;
             try
             {
                 InputCache[i] = value;
                 this.Propagate();
                 succeeded = true;
             }
             catch (IndexOutOfRangeException)
             {
                 succeeded = false;
                 // I really don't know what I can productively do here so I'm doing the msg thing below
             }
             if (!succeeded)
             {
                 Windows.UI.Popups.MessageDialog msg = new Windows.UI.Popups.MessageDialog("Tried to assign value to nonexistant input");
                 await msg.ShowAsync();
             }
         }
     }
 }
示例#3
0
 /// <summary>
 /// Change the input of the GElement that this GPrimitive outputs to.
 /// Future note: Add "if" statement to prevent calling Propagate() unless
 /// the value set is different from the value that was already in place.
 /// </summary>
 /// <param name="inputElement">The element sending the updated output</param>
 /// <param name="value">The new value</param>
 public override void SetInput(GElement inputElement, bool value)
 {
     inputs[inputElement] = value;
     // TODO: Have above return true/false based on whether anything was changed? Need to know when to Propagate()
 }
示例#4
0
 /// <summary>
 /// Set the value of a given input for this component.
 /// The input to be set is determined by comparing the sending GElement
 /// to the list of this GElement's inputs. 
 /// </summary>
 /// <param name="inputElement">The element sending the input</param>
 /// <param name="value">The value to be set</param>
 public abstract void SetInput(GElement inputElement, bool value);
 /// <summary>
 /// Add an input to the Dictionary.
 /// </summary>
 /// <param name="g">The GElement connected to the input</param>
 /// <param name="i">The number of the input</param>
 public void SetInput(GElement g, int i)
 {
     inputs.Add(g, i);
 }
        Dictionary<GElement, int> inputs = new Dictionary<GElement, int>(); // TODO: Choose a good default size for this

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Create a new InputValuesContainer which must have a parent GElement
        /// </summary>
        /// <param name="parent">The GElement containing this InputValuesContainer</param>
        public InputValuesContainer(GElement parent)
        {
            // Initialize inputCache and Dictionary
        }