/// <summary>
 /// Adds an item to the collection.
 /// </summary>
 /// <param name="item">The item to add to the collection.</param>
 /// <returns></returns>
 public KmlValue Add(KmlValue item)
 {
     List.Add(item);
     item.Parent = Parent;
     return item;
 }
Esempio n. 2
0
        public KmlValue Clone()
        {
            KmlValue newKmlValue = new KmlValue(this._Value, this.IsString, StartPosition.Clone(), EndPosition.Clone());

            if (StartPosition != null)
            {
                newKmlValue.StartPosition = StartPosition.Clone();
            }
            if (EndPosition != null)
            {
                newKmlValue.EndPosition = EndPosition.Clone();
            }

            //comments
            foreach (KmlComment comment in Comments)
            {
                newKmlValue.Comments.Add(comment.Clone());
            }

            return newKmlValue;
        }
 /// <summary>
 /// Removes the item from the collection.
 /// </summary>
 /// <param name="item"></param>
 public void Remove(KmlValue item)
 {
     if (List.Contains(item))
     {
         List.Remove(item);
         item.Parent = null;
     }
 }
 /// <summary>
 /// Sets the item at the specified index in the collection.
 /// </summary>
 /// <param name="index">The index to set.</param>
 /// <param name="item">The item to set.</param>
 public void Set(int index, KmlValue item)
 {
     List[index] = item;
     item.Parent = Parent;
 }
 /// <summary>
 /// Gets the index of the specified item.
 /// </summary>
 /// <param name="item">The item to get the index of.</param>
 /// <returns></returns>
 public int IndexOf(KmlValue item)
 {
     return List.IndexOf(item);
 }
 /// <summary>
 /// Copies the collection to an array starting at a specified index.
 /// </summary>
 /// <param name="array">The array to copy the collection to.</param>
 /// <param name="index">The index to start copying from.</param>
 public void CopyTo(KmlValue[] array, int index)
 {
     List.CopyTo(array, index);
 }
 /// <summary>
 /// Checks if the collection contains the specified item.
 /// </summary>
 /// <param name="item">The item to check for.</param>
 /// <returns></returns>
 public bool Contains(KmlValue item)
 {
     return List.Contains(item);
 }
 /// <summary>
 /// Adds a range of items to the collection
 /// </summary>
 /// <param name="range">The range of values to add to the collection.</param>
 public void AddRange(KmlValue[] range)
 {
     foreach (KmlValue value in range)
     {
         List.Add(value);
         value.Parent = Parent;
     }
 }
        public KmlNode ReadNode(KmlNode Parent)
        {
            StringBuilder buffer = new StringBuilder();
            bool end = false;
            bool readingValue = false;

            //record start position
            CharPosition nodeStartPosition = GetCurrentPosition();
            CharPosition valueStartPosition = GetCurrentPosition();

            //node to store values in
            KmlNode node = new KmlNode(nodeStartPosition);

            //unload comments
            node.Comments.AddRange(CommentBuffer);
            CommentBuffer.Clear();
            while (!end)
            {
                //check if we are at end of stream
                if (reader.Peek() < 0)
                {
                    throw new InvalidKmlSyntaxException(GetCurrentPosition(), new UnclosedNodeException(nodeStartPosition));
                }
                char c = (char)reader.Read();
                //keep track of characters read
                TrackPosition(c);
                //check for comment
                if (c == COMMENT_CHAR)
                {
                    ReadComment(node);
                    continue;
                }
                //check if we are reading whitespace
                if (Char.IsWhiteSpace(c) || Char.IsSeparator(c) || c== CLOSE_NODE_CHAR)
                {
                    //check if we have finished reading the node
                    if (c == CLOSE_NODE_CHAR)
                    {
                        //end reading
                        end = true;
                    }
                    //check if we have been reading a value
                    if (readingValue)
                    {
                        //create new value
                        KmlValue val = new KmlValue(buffer.ToString(), false, valueStartPosition, GetCurrentPosition());
                        //give it out comments
                        val.Comments.AddRange(CommentBuffer);
                        //clear out our comments
                        CommentBuffer.Clear();
                        //put the buffer into a value
                        node.Values.Add(val);
                        //finished reading value
                        readingValue = false;
                        //clear buffer
                        buffer = new StringBuilder();
                    }
                    //if not ignore
                }
                else
                {

                    //check if theres another node to read
                    if (c == OPEN_NODE_CHAR)
                    {
                        //read the node and add to child nodes
                        KmlNode rn = ReadNode(null);
                        node.ChildNodes.Add(rn);
                    }
                    //check if theres a string to read
                    else if (c == QUOTE_CHAR)
                    {
                        //end pos
                        CharPosition valueEndPosition = GetCurrentPosition();
                        //create our value
                        KmlValue val = new KmlValue(ReadString(), true, valueStartPosition, valueEndPosition);

                        //give it out comments
                        val.Comments.AddRange(CommentBuffer);
                        //clear out our comments
                        CommentBuffer.Clear();
                        //read the string and add it to values
                        node.Values.Add(val);
                    }
                    else
                    {
                        //check if we are reading a value
                        if (!readingValue)
                        {
                            //we arnt reading a value - but we are now
                            readingValue = true;
                            //set value start post
                            valueStartPosition = GetCurrentPosition();
                        }
                        //add the character to the buffer
                        buffer.Append(c);
                        //MessageBox.Show(c.ToString());
                    }
                }
            }

            node.EndPosition = new CharPosition(Position.Row, Position.Column + 1, Position.Offset + 1);

            return node;
        }