/// <summary> /// 增加属性值 /// </summary> /// <param name="lpValue"></param> /// <returns></returns> private CPropertyValue Add(CPropertyValue lpValue) { CPropertyValue lpLastPos = null; if (null != m_lpPrev) { return(null); } lpLastPos = this; while (true) { if (null == lpLastPos.m_lpNext) { break; } lpLastPos = lpLastPos.m_lpNext; } if (null == lpLastPos.m_lpNext) { lpValue.m_lpPrev = lpLastPos; lpLastPos.m_lpNext = lpValue; } Calculation(); return(lpValue); }
/// <summary> /// 删除 /// </summary> /// <param name="value"></param> public void Remove(float value, eValueType type) { CPropertyValue cp = Find(value, type); if (cp != null) { cp.Unlink(); } }
/// <summary> /// 移除自身 /// </summary> public void Remove() { CPropertyValue root = GetRoot(); if (root != null) { root.Remove(this); } }
private float m_MinData; //最小值 //////////////////////////////////////////////////////////////////////////////////////////////////// // public CPropertyValue(float Value) { this.m_eValueType = eValueType.VALUE; this.m_Value = Value; this.m_FinalValue = Value; this.m_MinData = 0; this.m_MaxData = 0; this.m_lpNext = null; this.m_lpPrev = null; }
/// <summary> /// 增加值 /// </summary> /// <param name="lpValue"></param> /// <returns></returns> public CPropertyValue AddValue(CPropertyValue lpValue) { if (null == lpValue) { return(null); } lpValue.m_eValueType = eValueType.VALUE; return(Add(lpValue)); }
/// <summary> /// 清除所有数据 /// </summary> public void Clear() { CPropertyValue lpNextValue = m_lpNext; while (null != lpNextValue) { CPropertyValue lpTmp = lpNextValue.m_lpNext; lpNextValue.Unlink(); lpNextValue = lpTmp; } }
/// <summary> /// 获取父节点 /// </summary> /// <returns></returns> public CPropertyValue GetRoot() { CPropertyValue lpPrev = this; while (lpPrev != null) { if (null == lpPrev.m_lpPrev) { return(lpPrev); } lpPrev = lpPrev.m_lpPrev; } return(null); }
/// <summary> /// 重新计算 /// </summary> public void Calculation() { m_FinalValue = m_Value; CPropertyValue lpNextValue = m_lpNext; while (null != lpNextValue) { switch (lpNextValue.m_eValueType) { case eValueType.VALUE: m_FinalValue += lpNextValue.GetData(); break; case eValueType.RATE: m_FinalValue += m_Value * lpNextValue.GetData(); break; } lpNextValue = lpNextValue.m_lpNext; } }
/// <summary> /// 包含属性 /// </summary> /// <param name="lp"></param> /// <returns></returns> public bool Contains(CPropertyValue lp) { //向上遍历 CPropertyValue lpPrev = this; while (lpPrev != null) { if (lpPrev == lp) { return(true); } if (null == lpPrev.m_lpPrev) { break; } lpPrev = lpPrev.m_lpPrev; } //向下遍历 CPropertyValue lpnext = this; while (lpnext != null) { if (lpnext == lp) { return(true); } if (null == lpnext.m_lpNext) { break; } lpnext = lpnext.m_lpNext; } return(false); }
/// <summary> /// 寻找比率 /// </summary> /// <param name="value"></param> /// <returns></returns> public CPropertyValue Find(float value, eValueType type) { //向上遍历 CPropertyValue lpPrev = this; while (lpPrev != null) { if (Math.Abs(lpPrev.m_Value - value) < 0.00001f && (int)lpPrev.m_eValueType == (int)type) { return(lpPrev); } if (null == lpPrev.m_lpPrev) { break; } lpPrev = lpPrev.m_lpPrev; } //向下遍历 CPropertyValue lpnext = this; while (lpnext != null) { if (Math.Abs(lpnext.m_Value - value) < 0.000001f && (int)lpnext.m_eValueType == (int)type) { return(lpnext); } if (null == lpnext.m_lpNext) { break; } lpnext = lpnext.m_lpNext; } return(null); }
/// <summary> /// 删除自身与链表连接 /// </summary> private void Unlink() { CPropertyValue lpNext = m_lpNext; CPropertyValue lpPrev = m_lpPrev; CPropertyValue lpRoot = GetRoot(); if (null != m_lpPrev) { m_lpPrev.m_lpNext = m_lpNext; } if (null != m_lpNext) { m_lpNext.m_lpPrev = m_lpPrev; } m_lpNext = m_lpPrev = null; if (null != lpRoot) { lpRoot.Calculation(); } }
/// <summary> /// 删除属性 /// </summary> /// <param name="lpValue"></param> /// <returns></returns> public void Remove(CPropertyValue lpValue) { Remove(lpValue.m_Value, lpValue.m_eValueType); }