[Mobies-commit] [commit] r3741 - UDM/trunk/src/UdmCliGen

ksmyth at redhat1.isis.vanderbilt.edu ksmyth at redhat1.isis.vanderbilt.edu
Fri May 13 16:20:19 CDT 2011


Author: ksmyth
Date: Fri May 13 16:20:19 2011
New Revision: 3741

Log:
ICast to IUdmObject. Create{,Instance,Derived}. IUdmObject.instances archetype derived

Modified:
   UDM/trunk/src/UdmCliGen/Implementation.tmpl
   UDM/trunk/src/UdmCliGen/Initialize.tmpl
   UDM/trunk/src/UdmCliGen/Interface.tmpl
   UDM/trunk/src/UdmCliGen/UdmCliGen.py

Modified: UDM/trunk/src/UdmCliGen/Implementation.tmpl
==============================================================================
--- UDM/trunk/src/UdmCliGen/Implementation.tmpl	Fri May 13 16:19:07 2011	(r3740)
+++ UDM/trunk/src/UdmCliGen/Implementation.tmpl	Fri May 13 16:20:19 2011	(r3741)
@@ -29,24 +29,32 @@
             return Cast(((global::Udm.Native.UdmCliObject)o).backing);
         }
 
-        public global::System.Collections.Generic.IEnumerable<${fq_iname($c)}> instances
+        public static ${fq_iname($c)} ICast(global::Udm.IUdmObject o) {
+            return Cast(((global::Udm.Native.UdmCliObject)o).backing);
+        }
+
+        public static ${c.name} Create(global::Udm.IUdmObject parent, global::Udm.Native.Uml.CompositionChildRole role = null)
         {
-            get
+            if (role == null)
             {
-                return global::System.Linq.Enumerable.ToList(
-                    global::System.Linq.Enumerable.Select<global::Udm.Native.UdmObject, ${fq_iname($c)}>
-                    (backing.instances(), o => new ${c.name}(o)));
+                role = global::Udm.Native.Udm.NULLCHILDROLE;
             }
+            global::Udm.Native.UdmObject o = global::Udm.Native.UdmObject.Create(meta, ((global::Udm.Native.UdmCliObject)parent).backing, role);
+            return new ${c.name}(o);
         }
-        public global::System.Collections.Generic.IEnumerable<${fq_iname($c)}> derived
+
+#for $suffix, $isderived in (('Instance', 'false'), ('Derived', 'true'))
+        public ${c.name} Create${suffix}(global::Udm.IUdmObject parent, global::Udm.Native.Uml.CompositionChildRole role = null)
         {
-            get
+            if (role == null)
             {
-                return global::System.Linq.Enumerable.ToList(
-                    global::System.Linq.Enumerable.Select<global::Udm.Native.UdmObject, ${fq_iname($c)}>
-                    (backing.derived(), o => new ${c.name}(o)));
+                role = global::Udm.Native.Udm.NULLCHILDROLE;
             }
+            global::Udm.Native.UdmObject o = global::Udm.Native.UdmObject.Create(meta, (global::Udm.Native.UdmObject)parent, role, this.backing.__impl(), $isderived);
+            return new ${c.name}(o);
         }
+#end for
+
         public ${fq_iname($c)} this_downcasted
         {
             get
@@ -83,6 +91,34 @@
 #end for
 
 #def accessors($c)
+        ${fq_iname($c)} ${fq_iname($c)}.archetype
+        {
+            get
+            {
+                global::Udm.Native.UdmObject o = backing.archetype();
+                if (o.uniqueId() == 0) return null;
+                return new ${c.name}(o);
+            }
+        }
+        global::System.Collections.Generic.IEnumerable<${fq_iname($c)}> ${fq_iname($c)}.instances
+        {
+            get
+            {
+                return global::System.Linq.Enumerable.ToList(
+                    global::System.Linq.Enumerable.Select<global::Udm.Native.UdmObject, ${fq_iname($c)}>
+                    (backing.instances(), o => new ${c.name}(o)));
+            }
+        }
+        global::System.Collections.Generic.IEnumerable<${fq_iname($c)}> ${fq_iname($c)}.derived
+        {
+            get
+            {
+                return global::System.Linq.Enumerable.ToList(
+                    global::System.Linq.Enumerable.Select<global::Udm.Native.UdmObject, ${fq_iname($c)}>
+                    (backing.derived(), o => new ${c.name}(o)));
+            }
+        }
+
 #for $attr in $c.children(child_type=$uml.Attribute)
 #set type = $attr_typemap[$attr.attr('type')]
 #set meta_name = $fq_name($c) + "." + role_metaname(attr)

Modified: UDM/trunk/src/UdmCliGen/Initialize.tmpl
==============================================================================
--- UDM/trunk/src/UdmCliGen/Initialize.tmpl	Fri May 13 16:19:07 2011	(r3740)
+++ UDM/trunk/src/UdmCliGen/Initialize.tmpl	Fri May 13 16:20:19 2011	(r3741)
@@ -30,7 +30,7 @@
 #for $o in get_descendants($root)
 #if $o.type.name == "Class"
 ${fq_name($o)}.meta = classes["${get_path($o, "/")}"];
-downcasts.Add(${fq_name($o)}.meta, x=>${fq_name($o)}.Cast(x));
+downcasts.Add(${fq_name($o)}.meta, ${fq_name($o)}.Cast);
 #else if $o.type.name == "Attribute"
 ${fq_name($o.parent)}.$role_metaname($o) = attributes["${get_path($o, "/")}"];
 #end if

Modified: UDM/trunk/src/UdmCliGen/Interface.tmpl
==============================================================================
--- UDM/trunk/src/UdmCliGen/Interface.tmpl	Fri May 13 16:19:07 2011	(r3740)
+++ UDM/trunk/src/UdmCliGen/Interface.tmpl	Fri May 13 16:20:19 2011	(r3741)
@@ -9,6 +9,10 @@
         : global::Udm.IUdmObject
 #end if
     {
+        I$c.name archetype { get; }
+        System.Collections.Generic.IEnumerable<I$c.name> instances { get; }
+        System.Collections.Generic.IEnumerable<I$c.name> derived { get; }
+
 
 #for $attr in $c.children(child_type=$uml.Attribute)
         $attr_typemap[$attr.attr('type')] @$attr.name { get; set; }

Modified: UDM/trunk/src/UdmCliGen/UdmCliGen.py
==============================================================================
--- UDM/trunk/src/UdmCliGen/UdmCliGen.py	Fri May 13 16:19:07 2011	(r3740)
+++ UDM/trunk/src/UdmCliGen/UdmCliGen.py	Fri May 13 16:20:19 2011	(r3741)
@@ -10,6 +10,8 @@
 
 from Cheetah.Template import Template
 
+udm.Object.__nonzero__ = lambda(self) : self.id != 0
+
 def get_template(name, **kwargs):
     if hasattr(sys, "frozen"): #i.e. .exe generated by py2exe
         __import__(name)


More information about the Mobies-commit mailing list