Beispiel #1
0
 public Node getNextNode(Node curr)
 {
     bool flag = (curr == null);
     foreach (object i in content)
     {
         if (i is Node)
         {
             if (flag)
             {
                 return (Node)i;
             }
             else if ((Node)i == curr)
             {
                 flag = true;
             }
         }
     }
     return null;
 }
Beispiel #2
0
        public Path(System.IO.Stream stream)
        {
            int id;
            object[] content;
            try
            {
                byte[] array1 = new byte[sizeof(int) * 2];
                stream.Read(array1, 0, array1.Length);
            //                ByteBuffer buffer1 = new ByteBuffer(array1);
                MemoryStream ms = new MemoryStream(array1);
                BinaryReader buffer1 = new BinaryReader(ms);

                id = buffer1.ReadInt32();
                int count = buffer1.ReadInt32();
                content = new object[count];
                for (int i = 0; i < count; i++)
                {
                    int type = stream.ReadByte();
                    if (type == 0)
                    {
                        content[i] = new Node(stream);
                    }
                    else
                    {
                        content[i] = new Tag(stream);
                    }
                }
            }
            catch (Exception e)
            {
                id = 0;
                content = new object[0];
            }
            this.id = id;
            this.content = content;
        }
Beispiel #3
0
        public XMLHandler()
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments = true;
            XmlReader reader = XmlReader.Create("map.xml", settings);
            reader.MoveToContent();

            paths = new Collection<Path>();
            nodeMap = new Dictionary<string, Node>();
            nodes = new List<Node>();
            content = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
            //                        Console.Write("<{0}>", reader.Name);
                        if (reader.Name.CompareTo("node") == 0)
                        {
                            string id = reader.GetAttribute("id");
                            string slat = reader.GetAttribute("lat");
                            string slon = reader.GetAttribute("lon");
                            double lat = Double.Parse(slat);
                            double lon = Double.Parse(slon);
                            Node node = new Node(0, lat, lon);
                            nodes.Add(node);
                            if (id != null)
                            {
                                nodeMap.Add(id, node);
                            }

                            content = new List<object>();
                            content.Add(node);
                        }
                        else if (reader.Name.CompareTo("path") == 0)
                        {
                            content = new List<object>();
                        }

                        else if (reader.Name.CompareTo("tag") == 0)
                        {
                            string key = reader.GetAttribute("k");
                            string value = reader.GetAttribute("v");

                            Tag tag = new Tag(key, value);
                            content.Add(tag);
                        }

                        else if(reader.Name.CompareTo("nd") == 0)
                        {
                            string myref = reader.GetAttribute("ref");
                            Node node = nodeMap[myref];
                            content.Add(node);
                        }

                        break;
                    case XmlNodeType.EndElement:
            //                        Console.Write("</{0}>", reader.Name);
                        if(reader.Name.CompareTo("node") == 0)
                        {
                            if(content.Count > 1)
                            {
                                Path path = new Path(0, content);
                                paths.Add(path);
                            }
                        }

                        else if (reader.Name.CompareTo("path") == 0)
                        {
                            Path path = new Path(0, content);
                            paths.Add(path);
                            content = null;
                        }

                        else if (reader.Name.CompareTo("tag") == 0)
                        {
                        }

                        else if (reader.Name.CompareTo("nd") == 0)
                        {
                        }

                        break;
                }
            }

            for (int i = 0; i < nodes.Count; i++)
            {
                nodes[i].id = i;
            }

            for (int i = 0; i < paths.Count; i++)
            {
                paths[i].id = i;
            }
        }