/// <summary> /// Convert "status" enums to stateValues. Since status is a "superset" /// we can end up with "undefineds" a lot. /// </summary> /// <param name="val"></param> /// <returns></returns> private static stateValues StatusToStateValue(status val) { stateValues state = stateValues.isundefined; if (val == status.isfalse) { state = stateValues.isfalse; } else if (val == status.istrue) { state = stateValues.istrue; } return(state); }
/// <summary> /// We can initialize an element to 3 states: /// 0 / 1 / x /// </summary> /// <param name="type">"type" of value written, invariably "value"</param> /// <param name="state">the state of the value, 1/0/x</param> public Element(eType type, stateValues state) { this.elementType = type; switch (state) { case stateValues.istrue: this.elementValue = "1"; break; case stateValues.isfalse: this.elementValue = "0"; break; default: this.elementType = eType.unknown; this.elementValue = "x"; // undefined break; } }
/// <summary> /// handles our "single operand" operators, such as the ! operator /// and any others we define later. /// </summary> /// <param name="items"></param> /// <param name="startpos"></param> /// <param name="endpos"></param> /// <returns></returns> private static status ProcessSingleOperation(Elements items, int startpos, ref int endpos) { for (int i = startpos; i < endpos; i++) { if (items[i].Operation == Element.opType.Not) // found one! { status nstat = Evaluate(items[i + 1], items[i]); if (nstat != status.isfalse && nstat != status.istrue && nstat != status.isundefined) { return(nstat); // this is a problem` } try { items.RemoveAt(i); items.RemoveAt(i); } catch (System.ArgumentOutOfRangeException ex) { string msg = ex.Message; throw ex; } // replace the elements we stripped out with the evaluated value stateValues state = stateValues.isundefined; if (nstat == status.isfalse) { state = stateValues.isfalse; } else if (nstat == status.istrue) { state = stateValues.istrue; } Element e = new Element(Element.eType.value, state); items.InsertAt(i, e); endpos--; } } return(status.success); }