/// <summary> /// Sets or unsets the value at the specified index. /// </summary> /// <param name="index">The index.</param> /// <param name="v">if <c>true</c> the value is set, otherwise it is unset.</param> public void Set(FeatureValue value, bool v) { if (value.FeatureBundleIndex < ULONG_BITS) { ulong mask = 1UL << value.FeatureBundleIndex; if (v) { m_flags1 |= mask; } else { m_flags1 &= ~mask; } } else { ulong mask = 1UL << value.FeatureBundleIndex - ULONG_BITS; if (v) { m_flags2 |= mask; } else { m_flags2 &= ~mask; } } }
/// <summary> /// Adds the feature value. /// </summary> /// <param name="value">The feature value.</param> /// <exception cref="System.InvalidOperationException">Thrown when the current number of feature values is equal to the maximum /// and this feature system does not contain the specified value.</exception> public void AddValue(FeatureValue value) { if (!m_values.Contains(value) && m_values.Count == FeatureBundle.MAX_NUM_VALUES) { throw new InvalidOperationException(HCStrings.kstidTooManyFeatValues); } value.FeatureBundleIndex = m_values.Count; m_values.Add(value); }
/// <summary> /// Adds the specified value to the specified variable. /// </summary> /// <param name="variableName">Name of the variable.</param> /// <param name="value">The value.</param> /// <exception cref="System.ArgumentException">Thrown when the specified variable is not defined.</exception> public void Add(string variableName, FeatureValue value) { List <FeatureValue> values; if (!m_values.TryGetValue(variableName, out values)) { throw new ArgumentException(string.Format(HCStrings.kstidUnknownVar, variableName), "variableName"); } values.Add(value); }
/// <summary> /// Determines if the value at the specified index is set. /// </summary> /// <param name="index">The index.</param> /// <returns><c>true</c> if the value is set, otherwise <c>false</c></returns> public bool Get(FeatureValue value) { if (value.FeatureBundleIndex < ULONG_BITS) { return((m_flags1 & (1UL << value.FeatureBundleIndex)) != 0); } else { return((m_flags2 & (1UL << (value.FeatureBundleIndex - ULONG_BITS))) != 0); } }
internal static FeatureStruct AntiFeatureStruct(this FeatureStruct fs) { // TODO: handle reentrancy properly var result = new FeatureStruct(); foreach (Feature feature in fs.Features) { FeatureValue value = fs.GetValue(feature); var childFS = value as FeatureStruct; FeatureValue newValue; if (childFS != null) { newValue = HCFeatureSystem.Instance.ContainsFeature(feature) ? childFS.DeepClone() : childFS.AntiFeatureStruct(); } else { var childSfv = (SimpleFeatureValue)value; newValue = HCFeatureSystem.Instance.ContainsFeature(feature) ? childSfv.DeepClone() : childSfv.Negation(); } result.AddValue(feature, newValue); } return(result); }
/// <summary> /// Adds the specified value to the specified variable. /// </summary> /// <param name="variableName">Name of the variable.</param> /// <param name="value">The value.</param> /// <exception cref="System.ArgumentException">Thrown when the specified variable is not defined.</exception> public void Add(string variableName, FeatureValue value) { List<FeatureValue> values; if (!m_values.TryGetValue(variableName, out values)) { throw new ArgumentException(string.Format(HCStrings.kstidUnknownVar, variableName), "variableName"); } values.Add(value); }
public ClosedValueInstance(FeatureValue value) { m_values = new HCObjectSet <FeatureValue>(); m_values.Add(value); }
/// <summary> /// Adds the value. /// </summary> /// <param name="value">The value.</param> /// <param name="isDefault">if <c>true</c> this value is a default value.</param> public void AddPossibleValue(FeatureValue value) { value.Feature = this; m_possibleValues.Add(value); }
Feature LoadFeature(XmlElement featDefNode, XmlElement featSysNode, FeatureSystem featSys) { XmlElement featElem = featDefNode.SelectSingleNode("Feature") as XmlElement; string featId = featElem.GetAttribute("id"); Feature feature = featSys.GetFeature(featId); if (feature != null) return feature; string featureName = featElem.InnerText; string defValId = featElem.GetAttribute("defaultValue"); feature = new Feature(featId, featureName, m_curMorpher); XmlNode valueListNode = featDefNode.SelectSingleNode("ValueList"); if (valueListNode != null) { XmlNodeList valueList = valueListNode.SelectNodes("Value"); foreach (XmlNode valueNode in valueList) { XmlElement valueElem = valueNode as XmlElement; string valueId = valueElem.GetAttribute("id"); FeatureValue value = new FeatureValue(valueId, valueElem.InnerText, m_curMorpher); try { featSys.AddValue(value); feature.AddPossibleValue(value); } catch (InvalidOperationException ioe) { throw new LoadException(LoadException.LoadErrorType.TOO_MANY_FEATURE_VALUES, this, HCStrings.kstidTooManyFeatValues, ioe); } } if (!string.IsNullOrEmpty(defValId)) feature.DefaultValue = new ClosedValueInstance(feature.GetPossibleValue(defValId)); } else { XmlElement featListElem = featDefNode.SelectSingleNode("FeatureList") as XmlElement; string featDefIdsStr = featListElem.GetAttribute("features"); string[] featDefIds = featDefIdsStr.Split(' '); foreach (string featDefId in featDefIds) { XmlNode subFeatDefNode = featSysNode.SelectSingleNode(string.Format("FeatureDefinition[@id = '{0}']", featDefId)); Feature subFeature = LoadFeature(subFeatDefNode as XmlElement, featSysNode, featSys); feature.AddSubFeature(subFeature); } } featSys.AddFeature(feature); return feature; }
public ClosedValueInstance(FeatureValue value) { m_values = new HCObjectSet<FeatureValue>(); m_values.Add(value); }
/// <summary> /// Sets or unsets the value at the specified index. /// </summary> /// <param name="index">The index.</param> /// <param name="v">if <c>true</c> the value is set, otherwise it is unset.</param> public void Set(FeatureValue value, bool v) { if (value.FeatureBundleIndex < ULONG_BITS) { ulong mask = 1UL << value.FeatureBundleIndex; if (v) m_flags1 |= mask; else m_flags1 &= ~mask; } else { ulong mask = 1UL << value.FeatureBundleIndex - ULONG_BITS; if (v) m_flags2 |= mask; else m_flags2 &= ~mask; } }
/// <summary> /// Determines if the value at the specified index is set. /// </summary> /// <param name="index">The index.</param> /// <returns><c>true</c> if the value is set, otherwise <c>false</c></returns> public bool Get(FeatureValue value) { if (value.FeatureBundleIndex < ULONG_BITS) return (m_flags1 & (1UL << value.FeatureBundleIndex)) != 0; else return (m_flags2 & (1UL << (value.FeatureBundleIndex - ULONG_BITS))) != 0; }
/// <summary> /// Adds the feature value. /// </summary> /// <param name="value">The feature value.</param> /// <exception cref="System.InvalidOperationException">Thrown when the current number of feature values is equal to the maximum /// and this feature system does not contain the specified value.</exception> public void AddValue(FeatureValue value) { if (!m_values.Contains(value) && m_values.Count == FeatureBundle.MAX_NUM_VALUES) throw new InvalidOperationException(HCStrings.kstidTooManyFeatValues); value.FeatureBundleIndex = m_values.Count; m_values.Add(value); }