generic parent object handling
[potlatch2.git] / net / systemeD / halcyon / connection / Entity.as
index 6b52c647205af1e54994543669efa7059e751f99..7e5e8a6b5720ef98875c0b193b663b516089cfcf 100644 (file)
@@ -1,12 +1,14 @@
 package net.systemeD.halcyon.connection {
 
     import flash.events.EventDispatcher;
+    import flash.utils.Dictionary;
 
     public class Entity extends EventDispatcher {
         private var _id:Number;
         private var _version:uint;
         private var tags:Object = {};
         private var modified:Boolean = false;
+               private var parents:Dictionary = new Dictionary();
 
         public function Entity(id:Number, version:uint, tags:Object) {
             this._id = id;
@@ -23,6 +25,8 @@ package net.systemeD.halcyon.connection {
             return _version;
         }
 
+               // Tag-handling methods
+
         public function hasTags():Boolean {
             for (var key:String in tags)
                 return true;
@@ -66,6 +70,12 @@ package net.systemeD.halcyon.connection {
             return copy;
         }
 
+               public function getTagsHash():Object {
+                       // hm, not sure we should be doing this, but for read-only purposes
+                       // it's faster than using getTagsCopy
+                       return tags;
+               }
+
         public function getTagArray():Array {
             var copy:Array = [];
             for (var key:String in tags )
@@ -73,6 +83,8 @@ package net.systemeD.halcyon.connection {
             return copy;
         }
 
+               // Clean/dirty methods
+
         public function get isDirty():Boolean {
             return modified;
         }
@@ -87,6 +99,40 @@ package net.systemeD.halcyon.connection {
             modified = true;
         }
 
+               // Parent handling
+               
+               public function addParent(parent:Entity):void {
+                       parents[parent]=true;
+               }
+
+               public function removeParent(parent:Entity):void {
+                       delete parents[parent];
+               }
+               
+               public function get parentWays():Array {
+                       var a:Array=[];
+                       for (var o:Object in parents) {
+                               if (o is Way) { a.push(o); }
+                       }
+                       return a;
+               }
+               
+               public function get parentRelations():Array {
+                       var a:Array=[];
+                       for (var o:Object in parents) {
+                               if (o is Relation) { a.push(o); }
+                       }
+                       return a;
+               }
+               
+               public function get parentObjects():Array {
+                       var a:Array=[];
+                       for (var o:Object in parents) { a.push(o); }
+                       return a;
+               }
+
+               // To be overridden
+
         public function getType():String {
             return '';
         }