Beispiel #1
0
        /**
         * Adds a integer Profile to the state with the given key. If no Profile exists, a new Profile is created
         * with the corresponding key. If a Profile exists with that key, the Profile is appended onto the end of the Profile.
         * @param key The key corresponding to the state variable.
         * @param profIn The Profile to be added to the integer Profile.
         */
        public void addValue(StateVarKey <int> key, HSFProfile <int> profIn)
        {
            HSFProfile <int> valueOut;

            if (!Idata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one.
            {
                Idata.Add(key, profIn);
            }
            else         // Otherwise, add this data point to the existing Profile.
            {
                valueOut.Add(profIn);
            }
        }
Beispiel #2
0
        /**
         * Returns the integer Profile matching the key given. If no Profile is found, it goes back one Event
         * and checks again until it gets to the initial state.
         * @param key The integer state variable key that is being looked up.
         * @return The Profile saved in the state.
         */
        public HSFProfile <int> getProfile(StateVarKey <int> key)
        {
            HSFProfile <int> valueOut;

            if (Idata.Count != 0)                         // Are there any Profiles in there?
            {
                if (Idata.TryGetValue(key, out valueOut)) //see if our key is in there
                {
                    return(valueOut);
                }
            }
            return(Previous.getProfile(key));        // This isn't the right profile, go back one and try it out!
        }
Beispiel #3
0
        /**
         * Gets the integer value of the state at a certain time. If the exact time is not found, the data is
         * assumed to be on a zero-order hold, and the last value set is found.
         * @param key The integer state variable key that is being looked up.
         * @param time The time the value is looked up at.
         * @return A pair containing the last time the variable was set, and the integer value.
         */
        public KeyValuePair <double, int> getValueAtTime(StateVarKey <int> key, double time)
        {
            HSFProfile <int> valueOut;

            if (Idata.Count != 0)                         // Are there any Profiles in there?
            {
                if (Idata.TryGetValue(key, out valueOut)) //see if our key is in there
                {
                    return(valueOut.DataAtTime(time));
                }
            }
            return(Previous.getValueAtTime(key, time));         //either no profiles or none that match our keys, try finding it in the previous one
        }
Beispiel #4
0
        //took out setters and getters becuase they're public fields

        /** TODO: figure out if this can all be done with dictionary stuff
         * Gets the last int value set for the given state variable key in the state. If no value is found
         * it checks the previous state, continuing all the way to the initial state.
         * @param key The integer state variable key that is being looked up.
         * @return A pair containing the last time the variable was set, and the integer value.
         */
        public KeyValuePair <double, int> getLastValue(StateVarKey <int> key)
        {
            HSFProfile <int> valueOut;

            if (Idata.Count != 0)                         // Are there any Profiles in there?
            {
                if (Idata.TryGetValue(key, out valueOut)) //see if our key is in there
                {
                    return(valueOut.Last());              //found it, return it TODO: return last value or pair?
                }
            }
            return(Previous.getLastValue(key)); //either no profiles or none that match our keys, try finding it in the previous one
        }
Beispiel #5
0
        /**
         * Adds a integer Profile value pair to the state with the given key. If no Profile exists, a new Profile is created
         * with the corresponding key. If a Profile exists with that key, the pair is appended onto the end of the Profile.
         * Ensure that the Profile is still time ordered if this is the case.
         * @param key The key corresponding to the state variable.
         * @param pairIn The pair to be added to the integer Profile.
         */
        void addValue(StateVarKey <int> key, KeyValuePair <double, int> pairIn)
        {
            HSFProfile <int> valueIn = new HSFProfile <int>(pairIn);
            HSFProfile <int> valueOut;

            if (!Idata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one.
            {
                Idata.Add(key, valueIn);
            }
            else                      // Otherwise, add this data point to the existing Profile.
            {
                valueOut.Add(pairIn); //TODO: make sure this is ok. was formally iterator.second.data
            }
        }
Beispiel #6
0
        /**
         * Sets the integer Profile in the state with its matching key. If a Profile is found already under
         * that key, this will overwrite the old Profile.
         * @param key The integer state variable key that is being set.\
         * @param profIn The integer Profile being saved.
         */
        public void setProfile(StateVarKey <int> key, HSFProfile <int> profIn)
        {
            HSFProfile <int> valueOut;

            if (!Idata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one.
            {
                Idata.Add(key, profIn);
            }
            else           // Otherwise, erase whatever is there, and insert a new one.
            {
                Idata.Remove(key);
                Idata.Add(key, profIn);
            }
        }
Beispiel #7
0
        /** TODO: make sure valueOut is a good replacement for iterator.second
         * Returns the integer Profile for this state and all previous states merged into one Profile
         * @param key The integer state variable key that is being looked up.
         * @return The full Profile
         */
        public HSFProfile <int> getFullProfile(StateVarKey <int> key)
        {
            HSFProfile <int> valueOut = new HSFProfile <int>();

            if (Idata.Count != 0)                         // Are there any Profiles in there?
            {
                if (Idata.TryGetValue(key, out valueOut)) //see if our key is in there
                {
                    if (Previous != null)                 // Check whether we are at the first state
                    {
                        return(HSFProfile <int> .MergeProfiles(valueOut, Previous.getFullProfile(key)));
                    }
                    return(valueOut);
                }
            }
            if (Previous != null)
            {
                return(Previous.getFullProfile(key)); // If no data, return profile from previous states
            }
            return(valueOut);                         //return empty profile
        }
Beispiel #8
0
 /// <summary>
 /// Returns the integer Profile matching the key given. If no Profile is found, it goes back one Event
 /// and checks again until it gets to the initial state.
 /// </summary>
 /// <typeparam name="T">The type of the profile we are getting</typeparam>
 /// <param name="_key">The state variable key that is being looked up.</param>
 /// <returns>Profile saved in the state.</returns>
 public HSFProfile <T> GetProfile <T>(StateVarKey <T> _key)
 {
     if (_key.GetType() == typeof(StateVarKey <int>))
     {
         HSFProfile <int> valueOut;
         if (Idata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Idata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     else if (_key.GetType() == typeof(StateVarKey <double>))
     {
         HSFProfile <double> valueOut;
         if (Ddata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Ddata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     else if (_key.GetType() == typeof(StateVarKey <bool>))
     {
         HSFProfile <bool> valueOut;
         if (Ddata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Bdata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     else if (_key.GetType() == typeof(StateVarKey <Matrix <double> >))
     {
         HSFProfile <Matrix <double> > valueOut;
         if (Ddata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Mdata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     else if (_key.GetType() == typeof(StateVarKey <Quat>))
     {
         HSFProfile <Quat> valueOut;
         if (Ddata.Count != 0)
         {                                              // Are there any Profiles in there?
             if (Qdata.TryGetValue(_key, out valueOut)) //see if our key is in there
             {
                 return((dynamic)valueOut);
             }
         }
         return(Previous.GetProfile(_key)); // This isn't the right profile, go back one and try it out!
     }
     throw new ArgumentException("Profile Type Not Found");
 }