abbr works only on full words; changes on nodes don't work
[osm-helpers.git] / OsmObject.cs
blobc5493b9c4b9a9d5f5e5744a3e3216d296d66c617
1 /*
2 * Author: Paolo Molaro
3 * Copyright (c) 2008 Paolo Molaro lupus@oddwiz.org
4 * License: MIT/X11, see the MIT.X11 file.
5 */
6 using System;
7 using System.Collections;
8 using System.Collections.Generic;
9 using System.Xml;
10 using System.Collections.Specialized;
12 namespace OpenStreetMap {
14 public abstract class OsmObject {
15 StringDictionary tags;
16 string user;
17 string timestamp;
18 long id;
19 bool visible;
20 bool changed;
22 public abstract string ObjectType {
23 get;
26 public virtual void WriteXml (XmlTextWriter writer)
30 public long ID {
31 get {
32 return id;
34 set {
35 id = value;
36 changed = true;
40 public bool Visible {
41 get {
42 return visible;
44 set {
45 visible = value;
46 changed = true;
50 public bool Changed {
51 get {
52 return changed;
54 set {
55 changed = value;
59 public string User {
60 get {
61 return user;
63 set {
64 user = value;
65 changed = true;
69 public string TimeStamp {
70 get {
71 return timestamp;
73 set {
74 timestamp = value;
75 changed = true;
79 public string this [string key] {
80 get {
81 if (tags == null)
82 return null;
83 return tags [key];
85 set {
86 if (tags == null)
87 tags = new StringDictionary ();
88 tags [key] = value;
89 changed = true;
93 public void RemoveTag (string tag)
95 if (tags == null)
96 return;
97 tags.Remove (tag);
100 public ICollection Tags {
101 get {
102 if (tags == null)
103 return new string [0];
104 return tags.Keys;
108 public void WriteCommonAttrs (XmlTextWriter writer)
110 writer.WriteAttributeString ("id", ID.ToString ());
111 writer.WriteAttributeString ("user", User);
112 writer.WriteAttributeString ("timestamp", TimeStamp);
113 writer.WriteAttributeString ("visible", Visible? "true": "false");
116 public void WriteTags (XmlTextWriter writer)
118 if (tags == null)
119 return;
120 foreach (string k in tags.Keys) {
121 writer.WriteStartElement ("tag");
122 writer.WriteAttributeString ("k", k);
123 writer.WriteAttributeString ("v", tags [k]);
124 writer.WriteEndElement ();