certi-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[certi-cvs] applications/PyHLA doc/omt/module.tex doc/rti/f...


From: certi-cvs
Subject: [certi-cvs] applications/PyHLA doc/omt/module.tex doc/rti/f...
Date: Mon, 13 Oct 2008 17:15:42 +0000

CVSROOT:        /sources/certi
Module name:    applications
Changes by:     Petr Gotthard <gotthardp>       08/10/13 17:15:42

Modified files:
        PyHLA/doc/omt  : module.tex 
        PyHLA/doc/rti  : federateambassador.tex module.tex 
                         rtiambassador.tex 
        PyHLA/hla/omt  : __init__.py array.py record.py 
Added files:
        PyHLA/hla/omt  : enumerated.py 

Log message:
        HLAenumerated and HLAvariantRecord implemented

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/doc/omt/module.tex?cvsroot=certi&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/doc/rti/federateambassador.tex?cvsroot=certi&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/doc/rti/module.tex?cvsroot=certi&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/doc/rti/rtiambassador.tex?cvsroot=certi&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/hla/omt/__init__.py?cvsroot=certi&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/hla/omt/array.py?cvsroot=certi&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/hla/omt/record.py?cvsroot=certi&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/hla/omt/enumerated.py?cvsroot=certi&rev=1.1

Patches:
Index: doc/omt/module.tex
===================================================================
RCS file: /sources/certi/applications/PyHLA/doc/omt/module.tex,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- doc/omt/module.tex  26 Sep 2008 14:12:00 -0000      1.2
+++ doc/omt/module.tex  13 Oct 2008 17:15:35 -0000      1.3
@@ -83,11 +83,38 @@
 \end{verbatim}
 \end{classdesc}
 
-\begin{classdesc}{HLAfixedArray}{typename, cardinality}
+\begin{classdesc}{HLAenumerated}{name, representation, 
\{enumeratorName:value\}}
+Defines an enumeration.
+
+\begin{verbatim}
+HLAboolean = fom.HLAenumerated("HLAboolean",
+    HLAinteger32BE, {"HLAfalse":0, "HLAtrue":1})
+\end{verbatim}
+is equivalent to the following OMT DIF
+\begin{verbatim}
+<enumeratedData name="HLAboolean" representation="HLAinteger32BE">
+    <enumerator name="HLAfalse" values="0"/>
+    <enumerator name="HLAtrue" values="1"/>
+</enumeratedData>
+\end{verbatim}
+
+The enumerators are accessible via attributes. The values behave like integers,
+but don't support arithmetic.
+\begin{verbatim}
+print HLAboolean.HLAtrue
+\end{verbatim}
+
+The \method{pack} function takes an enumerator, or an integer value.
+\begin{verbatim}
+encodedValue = fom.HLAboolean.pack(HLAboolean.HLAtrue)
+\end{verbatim}
+\end{classdesc}
+
+\begin{classdesc}{HLAfixedArray}{name, elementType, cardinality}
 Defines a fixed-length array.
 
 \begin{verbatim}
-arrayType = fom.HLAfixedArray(fom.HLAfloat32LE, 3)
+arrayType = fom.HLAfixedArray("arrayType", fom.HLAfloat32LE, 3)
 \end{verbatim}
 is equivalent to the following OMT DIF
 \begin{verbatim}
@@ -101,11 +128,13 @@
 \end{verbatim}
 \end{classdesc}
 
-\begin{classdesc}{HLAvariableArray}{typename, cardinality = None}
+\begin{classdesc}{HLAvariableArray}{name, elementType, cardinality = None}
 Defines a variable-length array.
 
+Dynamic cardinality is represented by the \class{None} value.
+
 \begin{verbatim}
-newType = fom.HLAvariableArray(fom.HLAinteger16BE, None)
+newType = fom.HLAvariableArray("newType", fom.HLAinteger16BE, None)
 \end{verbatim}
 is equivalent to the following OMT DIF
 \begin{verbatim}
@@ -114,11 +143,11 @@
 \end{verbatim}
 \end{classdesc}
 
-\begin{classdesc}{HLAfixedRecord}{[(fieldName, fieldType)]}
-Defines a fixed array.
+\begin{classdesc}{HLAfixedRecord}{name, [(fieldName, fieldType)]}
+Defines a fixed record.
 
 \begin{verbatim}
-recordType = fom.HLAfixedRecord(
+recordType = fom.HLAfixedRecord("recordType",
     [('X',fom.HLAinteger16BE), ('Y',fom.HLAfloat32BE)])
 \end{verbatim}
 is equivalent to the following OMT DIF
@@ -135,4 +164,28 @@
 \end{verbatim}
 \end{classdesc}
 
-% $Id: module.tex,v 1.2 2008/09/26 14:12:00 gotthardp Exp $
+\begin{classdesc}{HLAvariantRecord}{name, (discriminant, dataType), 
[([enumerators], altName, altType)]}
+Defines a variant record.
+
+\begin{verbatim}
+recordType = fom.HLAvariantRecord("recordType", ("Axis",AxisEnum),
+    [(["TX"],"X",HLAinteger32LE), (["TY",None],"Y",HLAinteger32LE)])
+\end{verbatim}
+is equivalent to the following OMT DIF
+\begin{verbatim}
+<variantRecordData name="recordType"
+    encoding="HLAvariantRecord" dataType="AxisEnum" discriminant="Axis">
+    <alternative enumerator="TX" name="X" dataType="HLAinteger32LE"/>
+    <alternative enumerator="TY,HLAother" name="Y" dataType="HLAinteger32LE"/>
+</variantRecordData>
+\end{verbatim}
+
+The \constant{HLAother} enumerator is represented by the \class{None} value.
+
+The \method{pack} function takes a mapping object.
+\begin{verbatim}
+encodedValue = fom.recordType.pack({'Axis':AxisEnum.TX, 'X':7.2})
+\end{verbatim}
+\end{classdesc}
+
+% $Id: module.tex,v 1.3 2008/10/13 17:15:35 gotthardp Exp $

Index: doc/rti/federateambassador.tex
===================================================================
RCS file: /sources/certi/applications/PyHLA/doc/rti/federateambassador.tex,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- doc/rti/federateambassador.tex      26 Sep 2008 14:12:00 -0000      1.2
+++ doc/rti/federateambassador.tex      13 Oct 2008 17:15:37 -0000      1.3
@@ -5,8 +5,9 @@
 \class{FederateAmbassador} and implement some of the federate ambassador
 services.
 
+For example
 \begin{verbatim}
-class MyAmbassador(hla.rti.FederateAmbassador):
+class MyAmbassador(hla.FederateAmbassador):
     def discoverObjectInstance(self, object, objectClass, objectName):
         print "DISCOVERED", objectName
 \end{verbatim}
@@ -14,6 +15,7 @@
 A federate ambassador object is passed to the \method{joinFederationExecution}
 service.
 
+For example
 \begin{verbatim}
 fed = MyAmbassador()
 rtia.joinFederationExecution("python-01", "MyFederation", fed)
@@ -108,6 +110,8 @@
 \begin{methoddesc}{reflectAttributeValues}{object, \{attribute:value\}, tag, 
orderType, transportType\optional{, time, eventRetraction}}
 Received attribute values are received in a dictionary. Attribute handle is 
used as key.
 The value can be unpacked using the \module{hla.omt} functions.
+
+For example
 \begin{verbatim}
 def reflectAttributeValues(self, object, attributes, tag, order, transport):
     location, size = 
fom.WorldLocationStruct.unpack(attributes[self.wordLocationHandle])
@@ -282,4 +286,4 @@
 
 \end{classdesc}
 
-% $Id: federateambassador.tex,v 1.2 2008/09/26 14:12:00 gotthardp Exp $
+% $Id: federateambassador.tex,v 1.3 2008/10/13 17:15:37 gotthardp Exp $

Index: doc/rti/module.tex
===================================================================
RCS file: /sources/certi/applications/PyHLA/doc/rti/module.tex,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- doc/rti/module.tex  26 Sep 2008 14:12:00 -0000      1.2
+++ doc/rti/module.tex  13 Oct 2008 17:15:38 -0000      1.3
@@ -6,13 +6,13 @@
 
 First, import the module functions
 \begin{verbatim}
-import hla.rti
+import hla.rti as hla
 \end{verbatim}
 
 Each federate should subclass the \class{FederateAmbassador} and implement some
 of the federate ambassador services.
 \begin{verbatim}
-class MyAmbassador(hla.rti.FederateAmbassador):
+class MyAmbassador(hla.FederateAmbassador):
     def discoverObjectInstance(self, object, objectClass, objectName):
         print "DISCOVERED", objectName
 \end{verbatim}
@@ -22,7 +22,7 @@
 \begin{verbatim}
 fed = MyAmbassador()
 
-rtia = hla.rti.RTIAmbassador()
+rtia = hla.RTIAmbassador()
 rtia.joinFederationExecution("python-01", "MyFederation", fed)
 ...
 
@@ -38,4 +38,4 @@
 \input{rti/rtiambassador}
 \input{rti/federateambassador}
 
-% $Id: module.tex,v 1.2 2008/09/26 14:12:00 gotthardp Exp $
+% $Id: module.tex,v 1.3 2008/10/13 17:15:38 gotthardp Exp $

Index: doc/rti/rtiambassador.tex
===================================================================
RCS file: /sources/certi/applications/PyHLA/doc/rti/rtiambassador.tex,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- doc/rti/rtiambassador.tex   9 Oct 2008 16:50:58 -0000       1.4
+++ doc/rti/rtiambassador.tex   13 Oct 2008 17:15:38 -0000      1.5
@@ -3,8 +3,9 @@
 \begin{classdesc}{RTIAmbassador}{}
 Provides RTI ambassador services.
 
+For example
 \begin{verbatim}
-rtia = hla.rti.RTIAmbassador()
+rtia = hla.RTIAmbassador()
 rtia.joinFederationExecution("python-01", "MyFederation", fed)
 \end{verbatim}
 
@@ -37,11 +38,12 @@
 
 \begin{methoddesc}{createFederationExecution}{executionName, FED}
 
+For example
 \begin{verbatim} 
 try:
     rtia.createFederationExecution("MyFederation", "model.fed")
     print "Federation created."
-except hla.rti.FederationExecutionAlreadyExists:
+except hla.FederationExecutionAlreadyExists:
     print "Federation already exists."
 \end{verbatim}
 
@@ -75,6 +77,26 @@
 \end{methoddesc}
 
 \begin{methoddesc}{resignFederationExecution}{resignAction}
+The \class{ResignAction} class provides different resign actions.
+
+\begin{tableii}{l|l}{constant}{resignAction}{Description}
+\lineii{ReleaseAttributes}
+    {The resigning federate releases control of all owned attributes.}
+\lineii{DeleteObjects}
+    {The resigning federate deletes all objects for which it holds the
+    privilege to delete.}
+\lineii{DeleteObjectsAndReleaseAttributes}
+    {The resigning federate deletes all objects for which it holds the
+    privilege to delete and then releases ownership of any remaining
+    owned attributes.}
+\lineii{NoAction}
+    {The attributes and objects owned by the federate become "orphaned".}
+\end{tableii}
+
+For example
+\begin{verbatim} 
+rtia.resignFederationExecution(hla.ResignAction.DeleteObjects)
+\end{verbatim}
 
 May raise
 \exception{FederateOwnsAttributes},
@@ -139,6 +161,7 @@
 \begin{methoddesc}{getObjectClassHandle}{objectName}
 Returns object class handle.
 
+For example
 \begin{verbatim} 
 aircraftHandle = rtia.getObjectClassHandle("Aircraft")
 \end{verbatim}
@@ -161,6 +184,7 @@
 \begin{methoddesc}{getAttributeHandle}{attributeName, objectClass}
 Returns class attribute handle.
 
+For example
 \begin{verbatim} 
 aircraftHandle = rtia.getObjectClassHandle("Aircraft")
 wordLocationHandle = rtia.getAttributeHandle("WorldLocation", aircraftHandle)
@@ -185,6 +209,7 @@
 
 \begin{methoddesc}{publishObjectClass}{objectClass, (attribute)}
 
+For example
 \begin{verbatim} 
 wordLocationHandle = rtia.getAttributeHandle("WorldLocation", aircraftHandle)
 rtia.publishObjectClass(aircraftHandle, [wordLocationHandle])
@@ -214,6 +239,7 @@
 
 \begin{methoddesc}{subscribeObjectClassAttributes}{objectClass, (attribute), 
active=True}
 
+For example
 \begin{verbatim} 
 wordLocationHandle = rtia.getAttributeHandle("WorldLocation", aircraftHandle)
 rtia.subscribeObjectClassAttributes(aircraftHandle, [wordLocationHandle])
@@ -400,6 +426,7 @@
 
 Returns eventRetraction handle.
 
+For example
 \begin{verbatim} 
 rtia.updateAttributeValues(thisObject,
     {wordLocationHandle:fom.WorldLocationStruct.pack({"X":1,"Y":2,"Z":3})},
@@ -1567,4 +1594,4 @@
 
 \end{classdesc}
 
-% $Id: rtiambassador.tex,v 1.4 2008/10/09 16:50:58 gotthardp Exp $
+% $Id: rtiambassador.tex,v 1.5 2008/10/13 17:15:38 gotthardp Exp $

Index: hla/omt/__init__.py
===================================================================
RCS file: /sources/certi/applications/PyHLA/hla/omt/__init__.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- hla/omt/__init__.py 25 Sep 2008 17:17:42 -0000      1.1
+++ hla/omt/__init__.py 13 Oct 2008 17:15:39 -0000      1.2
@@ -11,17 +11,20 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # Lesser General Public License for more details.
 #
-# $Id: __init__.py,v 1.1 2008/09/25 17:17:42 gotthardp Exp $
+# $Id: __init__.py,v 1.2 2008/10/13 17:15:39 gotthardp Exp $
 
 import xml.sax.handler
 
 from hla._omt import *
+from enumerated import HLAenumerated
 from array import HLAfixedArray, HLAvariableArray
 from record import HLAfixedRecord, HLAvariantRecord
 
 class TypeParser(xml.sax.handler.ContentHandler):
     def __init__(self):
-        self.inRecord = False
+        self.inEnumerated = False
+        self.inFixedRecord = False
+        self.inVariantRecord = False
 
     def startElement(self, name, attributes):
 
@@ -30,7 +33,15 @@
             globals()[attributes["name"]] = 
HLAencoding(attributes["representation"])
 
         elif name == "enumeratedData":
-            pass
+            self.inEnumerated = True
+            self.enumName = attributes["name"]
+            self.enumRepresentation = HLAencoding(attributes["representation"])
+            self.enumEnumerators = []
+
+        elif name == "enumerator":
+            if not self.inEnumerated:
+                return
+           self.enumEnumerators += 
[(attributes["name"],int(attributes["values"]))]
 
         elif name == "arrayData":
             if(attributes["cardinality"].lower() == "dynamic"):
@@ -38,39 +49,66 @@
             else:
                 cardinality = attributes["cardinality"]
 
-            # name = HLAfixedArray(HLAinteger32LE, 3)
-            globals()[attributes["name"]] = HLAencoding(
-                attributes["encoding"], (HLAencoding(attributes["dataType"]), 
cardinality))
+            # name = HLAfixedArray("name", HLAinteger32LE, 3)
+            globals()[attributes["name"]] = HLAencoding(attributes["encoding"],
+                (attributes["name"], HLAencoding(attributes["dataType"]), 
cardinality))
 
         elif name == "fixedRecordData":
-            self.inRecord = True
+            self.inFixedRecord = True
            self.recordName = attributes["name"]
            self.recordFields = []
 
         elif name == "field":
-            if not self.inRecord:
+            if not self.inFixedRecord:
                 return
            self.recordFields += [(attributes["name"], 
HLAencoding(attributes["dataType"]))]
 
         elif name == "variantRecordData":
-            pass
+            self.inVariantRecord = True
+            self.recordName = attributes["name"]
+            self.recordEncoding = attributes["encoding"]
+            self.recordDiscriminant = (attributes["discriminant"], 
attributes["dataType"])
+            self.recordFields = []
 
         elif name == "alternative":
-            pass
+            if not self.inVariantRecord:
+                return
+            self.recordFields += [(attributes["enumerator"].split(','),
+                attributes["name"], HLAencoding(attributes["dataType"]))]
 
     def endElement(self, name):
 
-        if name == "fixedRecordData":
-            if not self.inRecord:
+        if name == "enumeratedData":
+            if not self.inEnumerated:
+                return
+
+            # name = HLAenumerated("name",
+            #     HLAinteger32BE, {"HLAfalse":0, "HLAtrue":1})
+            globals()[self.enumName] = HLAenumerated(
+                self.enumName, self.enumRepresentation, 
dict(self.enumEnumerators))
+            self.inEnumerated = False
+
+        elif name == "fixedRecordData":
+            if not self.inFixedRecord:
+                return
+
+            # name = HLAfixedRecord("name", [("X",HLAinteger32LE), 
("Y",HLAinteger32LE)])
+            globals()[self.recordName] = HLAfixedRecord(self.recordName, 
self.recordFields)
+            self.inFixedRecord = False
+
+        elif name == "variantRecordData":
+            if not self.inVariantRecord:
                 return
 
-            # name = HLAfixedRecord([("X",HLAinteger32LE), 
("Y",HLAinteger32LE)])
-            globals()[self.recordName] = HLAfixedRecord(self.recordFields)
-            self.inRecord = False
+            # name = HLAvariantRecord("name", ("Axis",AxisEnum),
+            #     [(["TX"],"X",HLAinteger32LE), (["TY"],"Y",HLAinteger32LE)])
+            globals()[self.recordName] = HLAencoding(self.recordEncoding,
+                (self.recordName, self.recordDiscriminant, self.recordFields))
+            self.inVariantRecord = False
 
 class HLAencoding:
-    def __init__(self, typeName, typeParameters = None):
-        self.typeName = typeName
+    def __init__(self, representation, typeParameters = None):
+        self.representation = representation
         self.typeParameters = typeParameters
         self._encoding = None
 
@@ -78,9 +116,9 @@
     def encoding(self):
         if(self._encoding == None):
             if(self.typeParameters == None):
-                self._encoding = globals()[self.typeName]
+                self._encoding = globals()[self.representation]
             else:
-                self._encoding = globals()[self.typeName](self.typeParameters)
+                self._encoding = 
globals()[self.representation](self.typeParameters)
         return self._encoding;
 
     @property
@@ -100,4 +138,4 @@
     parser.setContentHandler(handler)
     parser.parse(filename)
 
-# $Id: __init__.py,v 1.1 2008/09/25 17:17:42 gotthardp Exp $
+# $Id: __init__.py,v 1.2 2008/10/13 17:15:39 gotthardp Exp $

Index: hla/omt/array.py
===================================================================
RCS file: /sources/certi/applications/PyHLA/hla/omt/array.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- hla/omt/array.py    25 Sep 2008 17:17:43 -0000      1.1
+++ hla/omt/array.py    13 Oct 2008 17:15:39 -0000      1.2
@@ -11,7 +11,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # Lesser General Public License for more details.
 #
-# $Id: array.py,v 1.1 2008/09/25 17:17:43 gotthardp Exp $
+# $Id: array.py,v 1.2 2008/10/13 17:15:39 gotthardp Exp $
 
 from hla._omt import *
 from basic import *
@@ -26,7 +26,7 @@
 # +-------------+----------------+-------------+-----------------+-----------+
 
 class HLAfixedArray:
-    def __init__(self, elementType, cardinality):
+    def __init__(self, typeName, elementType, cardinality):
         self.elementType = elementType
         if(cardinality == None):
             raise TypeError("HLAfixedArray cannot have dynamic cardinality")
@@ -60,7 +60,7 @@
 class HLAvariableArray:
     # if cardinality = None, any cardinality is accepted (Dynamic cardinality)
     # note: we support HLAvariableArray encoding with fixed cardinality
-    def __init__(self, elementType, cardinality = None):
+    def __init__(self, typeName, elementType, cardinality = None):
         self.elementType = elementType
         self.cardinality = cardinality
 
@@ -92,4 +92,4 @@
 
         return value, size
 
-# $Id: array.py,v 1.1 2008/09/25 17:17:43 gotthardp Exp $
+# $Id: array.py,v 1.2 2008/10/13 17:15:39 gotthardp Exp $

Index: hla/omt/record.py
===================================================================
RCS file: /sources/certi/applications/PyHLA/hla/omt/record.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- hla/omt/record.py   9 Oct 2008 16:49:47 -0000       1.2
+++ hla/omt/record.py   13 Oct 2008 17:15:41 -0000      1.3
@@ -11,7 +11,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # Lesser General Public License for more details.
 #
-# $Id: record.py,v 1.2 2008/10/09 16:49:47 gotthardp Exp $
+# $Id: record.py,v 1.3 2008/10/13 17:15:41 gotthardp Exp $
 
 from hla._omt import *
 from basic import *
@@ -30,7 +30,7 @@
 # 
+-------------+---------+--------------+-----------+----------------+-----------+
 
 class HLAfixedRecord:
-    def __init__(self, fields):
+    def __init__(self, typeName, fields):
         self.fields = fields
         # to enable late binding, the octetBoundary cannot be evaluated now
         self._octetBoundary = None
@@ -72,7 +72,7 @@
 
 # Enumerator = None ... HLAother
 class HLAvariantRecord:
-    def __init__(self, discriminant, alternatives):
+    def __init__(self, typeName, discriminant, alternatives):
         self.discriminantName, self.discriminantType = discriminant
         self.alternatives = alternatives
         # to enable late binding, the octetBoundary cannot be evaluated now
@@ -121,4 +121,4 @@
             buffer += padding(len(buffer), self.octetBoundary)*'\0'
         return value, size
 
-# $Id: record.py,v 1.2 2008/10/09 16:49:47 gotthardp Exp $
+# $Id: record.py,v 1.3 2008/10/13 17:15:41 gotthardp Exp $

Index: hla/omt/enumerated.py
===================================================================
RCS file: hla/omt/enumerated.py
diff -N hla/omt/enumerated.py
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ hla/omt/enumerated.py       13 Oct 2008 17:15:40 -0000      1.1
@@ -0,0 +1,66 @@
+#
+# Python Language HLA API
+# Copyright (C) 2008  Petr Gotthard <address@hidden>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1, as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# $Id: enumerated.py,v 1.1 2008/10/13 17:15:40 gotthardp Exp $
+
+# For example:
+# +------------+----------------+------------+--------+-----------+
+# | Name       | Representation | Enumerator | Values | Semantics |
+# +------------+----------------+------------+--------+-----------+
+# |            |                | HLAfalse   | 0      |           |
+# | HLAboolean | HLAinteger32BE +------------+--------+-----------+
+# |            |                | HLAfalse   | 1      |           |
+# +------------+----------------+------------+--------+-----------+
+
+class HLAenumerator(int):
+    def __new__(cls, typeName, name, value):
+        return super(HLAenumerator, cls).__new__(cls, value)
+
+    def __init__(self, typeName, name, value):
+        self.__typeName = typeName
+        self.__name = name
+
+    def __repr__(self):
+        return "<%s.%s=%d>" % (self.__typeName, self.__name, self)
+
+    def __str__(self):
+        return "%s.%s" % (self.__typeName, self.__name)
+
+class HLAenumerated:
+    def __init__(self, typeName, representation, enumerators):
+        self.representation = representation
+        self.enumerators = {}
+        # initialize enumerators
+        for key in enumerators.keys():
+            self.enumerators[key] = HLAenumerator(typeName, key, 
enumerators[key])
+
+    def __getattr__(self, name):
+        return self.enumerators[name]
+
+    @property
+    def octetBoundary(self):
+        return self.representation.octetBoundary()
+
+    def pack(self, value):
+        return self.representation.pack(value)
+
+    def unpack(self, buffer, offset = 0):
+        value, size = self.representation.unpack(buffer, offset)
+        # find a corresponding enumerator
+        for name, enum in self.enumerators.items():
+            if enum == value:
+                return enum, size
+        # if not found
+        return value, size
+
+# $Id: enumerated.py,v 1.1 2008/10/13 17:15:40 gotthardp Exp $




reply via email to

[Prev in Thread] Current Thread [Next in Thread]