Example #1
0
        override protected bool IsEqual(CsvPart other)
        {
            CsvArray array = (CsvArray)other;

            if (array.Values.Length != Values.Length)
            {
                return(false);
            }

            for (int i = 0; i < Values.Length; i++)
            {
                if (!Values[i].EqualTo(array.Values[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        public static CsvFrame ParseOne(string value)
        {
            string[] infoSplit = value.Split(',');
            for (int i = 0; i < infoSplit.Length; i++)
            {
                infoSplit[i] = infoSplit[i].Trim();
            }

            const int expectedLength = Constants.NUMBER_OF_VARIABLES + 2; // Every letter of the alphabet plus the time and variable set owner.

            if (infoSplit.Length != expectedLength)
            {
                throw new CsvParseFailedException("Expected " + expectedLength + " nodes, got " + infoSplit.Length + " instead.");
            }

            if (!double.TryParse(infoSplit[0], out double time))
            {
                throw new CsvParseFailedException("Failed to get the time.");
            }

            string owner = infoSplit[1];

            CsvPart[] variableValues = new CsvPart[Constants.NUMBER_OF_VARIABLES];
            for (int i = 0; i < Constants.NUMBER_OF_VARIABLES; i++)
            {
                // Element is an array.
                if (infoSplit[i + 2][0] == '{' && infoSplit[i + 2].Last() == '}')
                {
                    // Trim the {}
                    string work = infoSplit[i + 2].Substring(1, infoSplit[i + 2].Length - 2);

                    // Split the array.
                    var      splitAt       = Regex.Matches(work, @";(?![^(]*\))");
                    string[] arrayElements = new string[splitAt.Count + 1];
                    for (int s = 0; s < splitAt.Count + 1; s++)
                    {
                        int start = 0, end = work.Length;
                        if (s > 0)
                        {
                            start = splitAt[s - 1].Index + 1;
                        }
                        if (s < splitAt.Count)
                        {
                            end = splitAt[s].Index;
                        }

                        arrayElements[s] = work.Substring(start, end - start).Trim();
                    }

                    // Get the values
                    CsvPart[] array;

                    // Check if it is an empty array
                    if (arrayElements.Length == 1 && arrayElements[0] == "")
                    {
                        array = new CsvPart[0];
                    }
                    else
                    {
                        array = new CsvPart[arrayElements.Length];

                        for (int a = 0; a < array.Length; a++)
                        {
                            array[a] = ParseValue(arrayElements[a]);
                        }
                    }

                    variableValues[i] = new CsvArray(array);
                }
                else
                {
                    variableValues[i] = ParseValue(infoSplit[i + 2]);
                }
            }
            return(new CsvFrame(time, owner, variableValues));
        }
Example #3
0
 override protected bool IsEqual(CsvPart other)
 {
     return(((CsvString)other).Value == Value);
 }
Example #4
0
 override protected bool IsEqual(CsvPart other)
 {
     return(((CsvVector)other).Value.EqualTo(Value));
 }
Example #5
0
 protected abstract bool IsEqual(CsvPart other);
Example #6
0
 public bool EqualTo(CsvPart other)
 {
     return(GetType() == other.GetType() && IsEqual(other));
 }
 override protected bool IsEqual(CsvPart other) => true;