/** * Adds a boolean 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 boolean Profile. */ public void addValue(StateVarKey <bool> key, HSFProfile <bool> profIn) { HSFProfile <bool> valueOut; if (!Bdata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one. { Bdata.Add(key, profIn); } else // Otherwise, add this data point to the existing Profile. { valueOut.Add(profIn); } }
/** * Returns the boolean 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 boolean state variable key that is being looked up. * @return The Profile saved in the state. */ public HSFProfile <bool> getProfile(StateVarKey <bool> key) { HSFProfile <bool> valueOut; if (Bdata.Count != 0) { // Are there any Profiles in there? if (Bdata.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! }
/** * Gets the boolean 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 boolean 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 boolean value. */ public KeyValuePair <double, bool> getValueAtTime(StateVarKey <bool> key, double time) { HSFProfile <bool> valueOut; if (Bdata.Count != 0) { // Are there any Profiles in there? if (Bdata.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 }
/* * Gets the last boolean 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 boolean state variable key that is being looked up. * @return A pair containing the last time the variable was set, and the boolean value. */ public KeyValuePair <double, bool> getLastValue(StateVarKey <bool> key) { HSFProfile <bool> valueOut; if (Bdata.Count != 0) { // Are there any Profiles in there? if (Bdata.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 }
/** * Adds a boolean 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 boolean Profile. */ public void addValue(StateVarKey <bool> key, KeyValuePair <double, bool> pairIn) { HSFProfile <bool> valueIn = new HSFProfile <bool>(pairIn); HSFProfile <bool> valueOut; if (!Bdata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one. { Bdata.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 } }
/** * Sets the boolean 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 boolean state variable key that is being set.\ * @param profIn The boolean Profile being saved. */ public void setProfile(StateVarKey <bool> key, HSFProfile <bool> profIn) { HSFProfile <bool> valueOut; if (!Bdata.TryGetValue(key, out valueOut)) // If there's no Profile matching that key, insert a new one. { Bdata.Add(key, profIn); } else // Otherwise, erase whatever is there, and insert a new one. { Bdata.Remove(key); Bdata.Add(key, profIn); } }
/* * Returns the boolean Profile for this state and all previous states merged into one Profile * @param key The boolean state variable key that is being looked up. * @return The full Profile */ public HSFProfile <bool> getFullProfile(StateVarKey <bool> key) { HSFProfile <bool> valueOut = new HSFProfile <bool>(); if (Bdata.Count != 0) { // Are there any Profiles in there? if (Bdata.TryGetValue(key, out valueOut)) { //see if our key is in there if (Previous != null) // Check whether we are at the first state { return(HSFProfile <bool> .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 }
/// <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"); }