Example #1
0
 public void SetComplexFunctions(string functionString, NodeLabelCallback FunctionCallback, string seperator)
 {
     string[]     ss  = functionString.Split(new string[] { seperator }, StringSplitOptions.None);
     ICFunction[] cft = new ICFunction[ss.Length];
     for (int i = 0; i < ss.Length; i++)
     {
         cft[i] = BaseFunction.CreateNode(ss[i], FunctionCallback);
     }
     ComplexFunctions = cft;
 }
Example #2
0
 public static void SetCallbackFunction(ICFunction function, NodeLabelCallback callback)
 {
     if (function is OutsourcedFunction)
     {
         (function as OutsourcedFunction).Callback = callback;
     }
     foreach (ICFunction child in function.Children)
     {
         SetCallbackFunction(child, callback);
     }
 }
Example #3
0
        public static OutsourcedFunction CreateOutsourcedFunction(string name, NodeLabelCallback callBack)
        {
            // Check if a Var type function has been desclared with this name
            foreach (ICFunction icf in BaseFunction.AllNodes.Values)
            {
                if (icf.GetType().Equals(typeof(Var)) && name.Equals(icf.Name))
                {
                    Var v = icf as Var;
                    OutsourcedFunction ret = new OutsourcedFunction(name, v.Callback);
                    return(ret);
                }
            }
            OutsourcedFunction r = new OutsourcedFunction(name, callBack);

            return(r);
        }
Example #4
0
 public OutsourcedFunction(string name, NodeLabelCallback callback)
 {
     mName    = name;
     Callback = callback;
 }
Example #5
0
        public static ICFunction CreateNode(string label, NodeLabelCallback callBack)
        {
            label = removeWhitespace(label);
            ICFunction ret;

            // if it has an '=' then it's a variable.
            // Rearrange X = Y into Var(X,Y) format.
            if (label.Contains("="))
            {
                string[] pars = label.Split(new char[] { '=' });
                label = "Var(" + pars[0] + "," + pars[1] + ")";
            }

            // Split on first '('
            string[] split = label.Split(new char[] { '(' }, 2);
            ret = GetFunctionFromLabel(split[0]);
            // If null, then it's either a constant or node.
            if (split.Length < 2 || ret == null)
            {
                ret = ConstantFunction.CreateConstantFunction(label, split[0]);
                if (ret != null)
                    return AddNodeToList(ret);
                ret = OutsourcedFunction.CreateOutsourcedFunction(split[0], callBack);
                if (ret != null)
                    return AddNodeToList(ret);

            }
            // Now need to find children represented by remainder of split: split[1]
            // eg "4,5,Sub(3,4))"
            List<ICFunction> children = new List<ICFunction>();
            string child = "";
            int relevance = 0;
            foreach (char c in split[1])
            {
                if (c == '(') relevance++;
                if (c == ')') relevance--;
                child += c;
                if (relevance == 0)
                {
                    if (c == ')')
                    {
                        child = child.TrimEnd(new char[] { ')' });
                        if (child.Length > 0)
                        {
                            ICFunction icf = CreateNode(child, callBack);
                            children.Add(icf);
                        }
                        child = "";
                    }
                    if (c == ',')
                    {
                        child = child.TrimEnd(new char[] { ',' });
                        if (child.Length > 0)
                        {
                            ICFunction icf = CreateNode(child, callBack);
                            children.Add(icf);
                        }
                        child = "";
                    }
                }
            }
            child = child.TrimEnd(new char[] { ',', ')' });
            if (child.Length > 0)
            {
                ICFunction icff = CreateNode(child, callBack);
                children.Add(icff);
            }
            ret.Children = children;

            return AddNodeToList(ret);
        }
Example #6
0
 public void SetComplexFunctions(string functionString, NodeLabelCallback FunctionCallback, string seperator)
 {
     string[] ss = functionString.Split(new string[] { seperator }, StringSplitOptions.None);
     ICFunction[] cft = new ICFunction[ss.Length];
     for (int i = 0; i < ss.Length; i++)
     {
         cft[i] = BaseFunction.CreateNode(ss[i], FunctionCallback);
     }
     ComplexFunctions = cft;
 }
Example #7
0
 public static OutsourcedFunction CreateOutsourcedFunction(string name, NodeLabelCallback callBack)
 {
     // Check if a Var type function has been desclared with this name
     foreach (ICFunction icf in BaseFunction.AllNodes.Values)
     {
         if (icf.GetType().Equals(typeof(Var)) && name.Equals(icf.Name))
         {
             Var v = icf as Var;
             OutsourcedFunction ret = new OutsourcedFunction(name, v.Callback);
             return ret;
         }
     }
     OutsourcedFunction r = new OutsourcedFunction(name, callBack);
     return r;
 }
Example #8
0
 public OutsourcedFunction(string name, NodeLabelCallback callback)
 {
     mName = name;
     Callback = callback;
 }
Example #9
0
 public static void SetCallbackFunction(ICFunction function, NodeLabelCallback callback)
 {
     if (function is OutsourcedFunction)
         (function as OutsourcedFunction).Callback = callback;
     foreach (ICFunction child in function.Children)
         SetCallbackFunction(child, callback);
 }
Example #10
0
        public static ICFunction CreateNode(string label, NodeLabelCallback callBack)
        {
            label = removeWhitespace(label);
            ICFunction ret;

            // if it has an '=' then it's a variable.
            // Rearrange X = Y into Var(X,Y) format.
            if (label.Contains("="))
            {
                string[] pars = label.Split(new char[] { '=' });
                label = "Var(" + pars[0] + "," + pars[1] + ")";
            }

            // Split on first '('
            string[] split = label.Split(new char[] { '(' }, 2);
            ret = GetFunctionFromLabel(split[0]);
            // If null, then it's either a constant or node.
            if (split.Length < 2 || ret == null)
            {
                ret = ConstantFunction.CreateConstantFunction(label, split[0]);
                if (ret != null)
                {
                    return(AddNodeToList(ret));
                }
                ret = OutsourcedFunction.CreateOutsourcedFunction(split[0], callBack);
                if (ret != null)
                {
                    return(AddNodeToList(ret));
                }
            }
            // Now need to find children represented by remainder of split: split[1]
            // eg "4,5,Sub(3,4))"
            List <ICFunction> children = new List <ICFunction>();
            string            child    = "";
            int relevance = 0;

            foreach (char c in split[1])
            {
                if (c == '(')
                {
                    relevance++;
                }
                if (c == ')')
                {
                    relevance--;
                }
                child += c;
                if (relevance == 0)
                {
                    if (c == ')')
                    {
                        child = child.TrimEnd(new char[] { ')' });
                        if (child.Length > 0)
                        {
                            ICFunction icf = CreateNode(child, callBack);
                            children.Add(icf);
                        }
                        child = "";
                    }
                    if (c == ',')
                    {
                        child = child.TrimEnd(new char[] { ',' });
                        if (child.Length > 0)
                        {
                            ICFunction icf = CreateNode(child, callBack);
                            children.Add(icf);
                        }
                        child = "";
                    }
                }
            }
            child = child.TrimEnd(new char[] { ',', ')' });
            if (child.Length > 0)
            {
                ICFunction icff = CreateNode(child, callBack);
                children.Add(icff);
            }
            ret.Children = children;

            return(AddNodeToList(ret));
        }