Пример #1
0
 // 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;
 }
Пример #2
0
        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));
            }
        }
Пример #3
0
        // 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);
        }
Пример #4
0
        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()));
        }
Пример #5
0
        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;
            }
        }
Пример #6
0
        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);
        }
Пример #7
0
        // 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);
        }
Пример #8
0
        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);
        }
Пример #9
0
        /* 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));
        }
Пример #10
0
        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");
            }
        }
Пример #11
0
 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);
     }
 }
Пример #12
0
 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);
     }
 }
Пример #13
0
        // 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;
            }
        }
Пример #14
0
 public bool IsLessThanOrEqualTo(eeObject obj)
 {
     return(!IsGreaterThan(obj));
 }
Пример #15
0
 public bool IsGreaterThanOrEqualTo(eeObject obj)
 {
     return(IsGreaterThan(obj) || IsEqualTo(obj));
 }
Пример #16
0
 public bool IsNotEqualTo(eeObject obj)
 {
     return(!IsEqualTo(obj));
 }