// If this object is a variable, set it's value to newObj but retain the old modifier public void OverrideNew(eeObject newObj) { // the two objects should be the same type, but this function doesn't handle that directly. this.value = newObj.value; this.methods = newObj.methods; this.attributes = newObj.attributes; }
public bool IsEqualTo(eeObject obj) { // eeNumber has a separate object comparason if (this.type == eeObjectType.NUMBER && obj.type == eeObjectType.NUMBER) { return(((eeNumber)this.value) == ((eeNumber)obj.value)); } else if (this.type == eeObjectType.LIST && obj.type == eeObjectType.LIST) { List <eeObject> listA = this.AsList(), listB = obj.AsList(); if (listA.Count() != listB.Count()) { return(false); } for (int i = 0; i < listA.Count(); i++) { if (listA[i].IsNotEqualTo(listB[i])) { return(false); } } return(true); } else // all other underlying native c# objects can be compared as usual { return(this.type == obj.type && this.value.Equals(obj.value)); } }
// returns a copy of this object; using CopyFrom because it's already implemented public eeObject Copy() { eeObject newObject = new eeObject(); newObject.CopyFrom(this); return(newObject); }
public eeObject Divide(eeObject exp) { if (this.type != eeObjectType.NUMBER || exp.type != eeObjectType.NUMBER) { throw new InvalidOperationError("division", type, exp.type); } return(eeObject.newNumberObject(this.AsNumber() / exp.AsNumber())); }
public void assignVar(string name, eeObject val) { // Var doesn't exist if (!scopeVars.ContainsKey(name)) { scopeVars.Add(name, val); } // Var exists; reassign else { scopeVars[name] = val; } }
public static eeObject newStringObject(string str) { var newObj = new eeObject(str) { type = eeObjectType.STRING, methods = DefaultMethods.stringBuiltInMethods }; newObj.attributes.Add( "length", newNumberObject(new eeNumber(str.Length)) ); return(newObj); }
// Methods in Eeloo will be passed as an internal_EXPRLIST ICollection object to the method handler. public eeObject CallMethod(string name, eeObject parameters) { // Extract the expressions ICollection <eeObject> expressions = parameters != null?parameters.AsEXPRLIST() : new List <eeObject>(); // Run the method var returnVal = this.methods[name](this, expressions); // Verify this object Verify(); // Return method's return value return(returnVal); }
public static eeObject newListObject(ICollection <eeObject> expressions, string modifier = null) { // Encapsulate the List object into an eeObject var newObj = new eeObject(expressions.ToList()) { type = eeObjectType.LIST, methods = DefaultMethods.listBuiltInMethods, modifier = modifier, }; newObj.attributes.Add( "length", newNumberObject(new eeNumber(expressions.Count)) ); return(newObj); }
/* Note: the eeObject.value for eeListObject must always be a List<eeObject> */ // Constructor passed an internal_EXPRLIST eeObject public static eeObject newListObject(eeObject exprlist, string modifier = null) { ICollection <eeObject> expressions; if (exprlist == null) { expressions = new List <eeObject>(); } else { // Extract the expressions expressions = exprlist.AsEXPRLIST(); } return(newListObject(expressions)); }
public bool IsGreaterThan(eeObject obj) { switch (this.type) { case eeObjectType.NUMBER: return(this.AsNumber() > obj.AsNumber()); case eeObjectType.LIST: return(ListMathHelpers.GreaterThan(this, obj)); case eeObjectType.STRING: return(StringMathHelpers.GreaterThan(this, obj)); case eeObjectType.BOOL: default: throw new InvalidOperationException("TO DO"); } }
public eeObject Multiply(eeObject exp) { if (this.type == eeObjectType.STRING || exp.type == eeObjectType.STRING) { return(StringMathHelpers.Multiply(this, exp)); } else if (this.type == eeObjectType.LIST || exp.type == eeObjectType.LIST) { return(ListMathHelpers.Multiply(this, exp)); } else if (this.type == eeObjectType.NUMBER && exp.type == eeObjectType.NUMBER) // regular arithmetic { return(eeObject.newNumberObject(this.AsNumber() * exp.AsNumber())); } else { throw new InvalidOperationError("multiplication", type, exp.type); } }
public eeObject Subtract(eeObject exp) { if (this.type == eeObjectType.STRING || exp.type == eeObjectType.STRING) // string math { return(StringMathHelpers.Subtract(this, exp)); } else if (this.type == eeObjectType.LIST || exp.type == eeObjectType.LIST) // list math { return(ListMathHelpers.Subtract(this, exp)); } else if (this.type == eeObjectType.NUMBER && exp.type == eeObjectType.NUMBER) // regular arithmetic { return(eeObject.newNumberObject(this.AsNumber() - exp.AsNumber())); } else { throw new InvalidOperationError("subtraction", type, exp.type); } }
// If this object is an element of a list, this method with replace it with another value public void CopyFrom(eeObject fromObj, bool asArrayElement = false) { switch (fromObj.type) { case eeObjectType.NUMBER: this.value = fromObj.AsNumber().Copy(); break; default: // all other types are natively constants so we dont need to explicity copy them this.value = fromObj.value; break; } this.attributes = fromObj.attributes; this.methods = fromObj.methods; this.type = fromObj.type; // Array elements do not get modifiers if (asArrayElement) { modifier = null; } }
public bool IsLessThanOrEqualTo(eeObject obj) { return(!IsGreaterThan(obj)); }
public bool IsGreaterThanOrEqualTo(eeObject obj) { return(IsGreaterThan(obj) || IsEqualTo(obj)); }
public bool IsNotEqualTo(eeObject obj) { return(!IsEqualTo(obj)); }