Example #1
0
        public static LabelStack FromBytes(byte[] bytes)// zwraca NULL, jeśli stos jest błędny
        {
            LabelStack stack = new LabelStack();
            int        i     = 0;

            try
            {
                while (bytes[i] != 0x00)                                                       //wykonuje się aż nie napotka na flagę końca
                {
                    stack.labels.Push(new Label((short)((bytes[i + 2] << 8) + bytes[i + 1]))); //konwertuje 2 bajty na shorta
                    i += 3;                                                                    //idzie do kolejnej flagi
                }
            }
            catch
            {
                stack = null;//jeśli coś pójdzie nie tak, czyli np. coś jest nie tak, to ustawia nulla do zwrotu, choć mógłby rzucać po prostu wyjątek
            }
            return(stack);

            /*LabelStack output = new LabelStack();
             * while (stack.labels.Count != 0)
             * {
             *  output.labels.Push(stack.labels.Pop());
             * }
             * return output;*/
        }
Example #2
0
 public bool Equals(LabelStack stack)
 {
     //return labels.Equals(stack);
     if (GetLength() == 1 && stack.GetLength() == 1)
     {
         return(true);
     }
     else if (GetLength() != stack.GetLength())
     {
         return(false);
     }
     else
     {
         for (int i = 0; i < labels.Count; i++)
         {
             if (this.labels.ElementAt(i).Id != stack.labels.ElementAt(i).Id)
             {
                 return(false);
             }
         }
         return(true);
     }
 }