Beispiel #1
0
        public static void ParseInto(string s, object o, ZXPProxy zpp)
        {
            List <DIndices> delimiters = Delimiter.Delimit(s, DelimitType.Any);

            for (int i = 0; i < delimiters.Count;)
            {
                switch (delimiters[i].Type)
                {
                // Plain Data That Should Be Able To Be Parsed In
                case DelimitType.Bracket:
                    ParseSimpleData(o, zpp, s, delimiters, ref i);
                    break;

                // This Is A Special Type
                case DelimitType.Angled:
                    ParseComplexData(o, zpp, s, delimiters, ref i);
                    break;

                // This Is A Function
                case DelimitType.Paranthesis:
                    // Find The Key
                    ParseFunction(o, zpp, s, delimiters, ref i);
                    break;
                }
                i++;
            }
            return;
        }
Beispiel #2
0
 public ExportFile(Delimiter type)
 {
     deltype = type;
     delvalue = DelimiterValue();
 }
Beispiel #3
0
        private string delvalue; // delimiter value

        #endregion Fields

        #region Constructors

        public ExportFile()
        {
            deltype = Delimiter.Tab;
            delvalue = DelimiterValue();
        }
Beispiel #4
0
        private static bool ParseArray(Type eType, string sArray, out object val)
        {
            val = null;
            IZXPConverter etConv;

            ZXParser.GetConverter(eType, out etConv);

            var nl = Delimiter.Delimit(sArray, DelimitType.Angled | DelimitType.Curly);

            // Create Parameters
            object element;
            var    elements = new List <object>();

            for (int ai = 0; ai < nl.Count;)
            {
                if (nl[ai].Type == DelimitType.Angled)
                {
                    if (ai >= nl.Count - 1 || nl[ai + 1].Type != DelimitType.Curly)
                    {
                        ai++;
                        continue;
                    }

                    // Get The Argument Type
                    string atValue = sArray.Substring(nl[ai].Start, nl[ai].Length);
                    if (string.IsNullOrWhiteSpace(atValue))
                    {
                        break;
                    }
                    Type aType = GetTypeFromString(atValue);
                    if (aType == null)
                    {
                        ai += 2;
                        continue;
                    }

                    // Get The Argument
                    string        sValue = sArray.Substring(nl[ai + 1].Start, nl[ai + 1].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out element))
                    {
                        elements.Add(element);
                    }
                    ai += 2;
                }
                else
                {
                    // Simple Parse
                    string sValue = sArray.Substring(nl[ai].Start, nl[ai].Length);
                    if (ReadValue(sValue, etConv, eType, out element))
                    {
                        elements.Add(element);
                    }
                    ai++;
                }
            }

            if (elements.Count < 1)
            {
                return(true);
            }
            var valArr = Array.CreateInstance(eType, elements.Count);

            for (int i = 0; i < elements.Count; i++)
            {
                valArr.SetValue(elements[i], i);
            }
            val = valArr;
            return(true);
        }
Beispiel #5
0
        private static void ParseFunction(object o, ZXPProxy zpp, string s, List <DIndices> ld, ref int li)
        {
            // Check If A Key Is Available
            string key = GetKeyString(s, ld, li);

            if (string.IsNullOrWhiteSpace(key))
            {
                return;
            }

            // Find The Method That Matches To This Key
            ZXPFunc    func;
            MethodInfo method = null;

            if (!zpp.FuncsDict.TryGetValue(key, out func))
            {
                return;
            }
            method = func.Method;

            // Check For Simple Invoke
            ParameterInfo[] paramInfo = method.GetParameters();
            if (paramInfo.Length < 1 || paramInfo == null)
            {
                method.Invoke(o, null);
                return;
            }

            // Parse Parameters
            string sArgs = s.Substring(ld[li].Start, ld[li].Length);

            object[] args = new object[paramInfo.Length];
            var      nl   = Delimiter.Delimit(sArgs, DelimitType.Angled | DelimitType.Curly);

            // Check Number Of Arguments
            int ca = 0;

            foreach (var ndi in nl)
            {
                if (ndi.Type == DelimitType.Curly)
                {
                    ca++;
                }
            }
            if (ca != args.Length)
            {
                return;
            }

            // Create Parameters
            int ai = 0, pi = 0;

            for (; pi < args.Length;)
            {
                if (nl[ai].Type == DelimitType.Angled)
                {
                    if (ai >= nl.Count - 1 || nl[ai + 1].Type != DelimitType.Curly)
                    {
                        ai++;
                        continue;
                    }

                    // Get The Argument Type
                    string atValue = sArgs.Substring(nl[ai].Start, nl[ai].Length);
                    if (string.IsNullOrWhiteSpace(atValue))
                    {
                        break;
                    }
                    Type aType = GetTypeFromString(atValue);
                    if (aType == null)
                    {
                        break;
                    }


                    // Get The Argument
                    string        sValue = sArgs.Substring(nl[ai + 1].Start, nl[ai + 1].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out args[pi]))
                    {
                        pi++;
                    }
                    ai += 2;
                }
                else
                {
                    // Simple Parse
                    Type          aType  = paramInfo[pi].ParameterType;
                    string        sValue = sArgs.Substring(nl[ai].Start, nl[ai].Length);
                    IZXPConverter conv;
                    ZXParser.GetConverter(aType, out conv);
                    if (ReadValue(sValue, conv, aType, out args[pi]))
                    {
                        pi++;
                    }
                    ai++;
                }
            }
            // Check That All Arguments Are OK
            if (pi == args.Length)
            {
                method.Invoke(o, args);
            }
        }
Beispiel #6
0
 private string GetTerminatorString(Delimiter delim)
 {
     switch (delim)
     {
         case Delimiter.LF:
             return "\r";
         case Delimiter.CF:
             return "\n";
         case Delimiter.LFCF:
             return "\r\n";
         case Delimiter.None:
             return "";
         default:
             throw new ArgumentOutOfRangeException();
     }
 }
Beispiel #7
0
        private Delimiter ReadDelimiter()
        {
            Delimiter d = new Delimiter();
            d.direction = (DelimiterDirection)br.ReadByte();
            d.z = br.ReadSByte();
            d.graphic = br.ReadUInt16();
            d.unk=br.ReadByte();

            if (mp.offsetx != 63 && mp.offsetx != 0 && mp.offsety != 63 && mp.offsety != 0)
            {
                WriteFileErr("FileID=" + fileid + ", X=" + mp.x + " (offset " + mp.offsetx + "), Y=" + mp.y + " (offset " + mp.offsety + "), error delimiter!");
            }

            return d;
        }
Beispiel #8
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        /// 
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            #region INPUTS

            Vector3d startVec = new Vector3d(0, 0, 0);
            if (!DA.GetData(0, ref startVec)) return;
            double startSpeed = 0;
            if (!DA.GetData(1, ref startSpeed)) return;
            double startPress = 0;
            if (!DA.GetData(2, ref startPress)) return;

            Vector3d endVec = new Vector3d(0, 0, 0);
            if (!DA.GetData(3, ref endVec)) return;
            double endSpeed = 0;
            if (!DA.GetData(4, ref endSpeed)) return;
            double endPress = 0;
            if (!DA.GetData(5, ref endPress)) return;

            double travelspeed = 0;
            if (!DA.GetData(6, ref travelspeed)) return;
            #endregion

            //If All Inputs are Empty

            Delimiter sDelimiter = new Delimiter();

            //If Start and End Defined

            if (!startVec.IsZero && !endVec.IsZero)
            {
                sDelimiter = new Delimiter(startVec, endVec, startSpeed, endSpeed, startPress, endPress, travelspeed);
            }

            //If Start Defined
            if (!startVec.IsZero && endVec.IsZero)
            {
                sDelimiter = new Delimiter(startVec, startSpeed, startPress, travelspeed);
            }
            //If End Defined
            if (startVec.IsZero && !endVec.IsZero)
            {
                sDelimiter = new Delimiter(endSpeed, endPress, endVec, travelspeed);
            }

            //OUTPUT
            DA.SetData(0, sDelimiter);
        }