[openrtm-commit:02926] r895 - tags/RELEASE_1_1_2/OpenRTM-aist-Python/OpenRTM_aist

openrtm @ openrtm.org openrtm @ openrtm.org
2017年 11月 20日 (月) 11:21:58 JST


Author: miyamoto
Date: 2017-11-20 11:21:58 +0900 (Mon, 20 Nov 2017)
New Revision: 895

Modified:
   tags/RELEASE_1_1_2/OpenRTM-aist-Python/OpenRTM_aist/RTCUtil.py
Log:
[incompat] add instantiateDataType.

Modified: tags/RELEASE_1_1_2/OpenRTM-aist-Python/OpenRTM_aist/RTCUtil.py
===================================================================
--- tags/RELEASE_1_1_2/OpenRTM-aist-Python/OpenRTM_aist/RTCUtil.py	2017-11-07 08:21:34 UTC (rev 894)
+++ tags/RELEASE_1_1_2/OpenRTM-aist-Python/OpenRTM_aist/RTCUtil.py	2017-11-20 02:21:58 UTC (rev 895)
@@ -16,7 +16,7 @@
 #     All rights reserved.
 
 from omniORB import CORBA
-
+import omniORB
 import RTC
 import OpenRTM
 
@@ -112,3 +112,54 @@
 def isMultiModeObject(obj):
   mmc = obj._narrow(RTC.MultiModeObject)
   return not CORBA.is_nil(mmc)
+
+
+
+
+#########################################################################
+#   F U N C T I O N S
+#
+#  DataType for CORBA
+#
+def instantiateDataType(dtype):
+    if isinstance(dtype, int) : desc = [dtype]
+    elif isinstance(dtype, tuple) : desc = dtype
+    else : 
+        desc=omniORB.findType(dtype._NP_RepositoryId) 
+
+    if desc[0] in [omniORB.tcInternal.tv_alias ]: return instantiateDataType(desc[2])
+
+    if desc[0] in [omniORB.tcInternal.tv_short, 
+                   omniORB.tcInternal.tv_long, 
+                   omniORB.tcInternal.tv_ushort, 
+                   omniORB.tcInternal.tv_ulong,
+                   omniORB.tcInternal.tv_boolean,
+                   omniORB.tcInternal.tv_char,
+                   omniORB.tcInternal.tv_octet,
+                   omniORB.tcInternal.tv_longlong,
+                   omniORB.tcInternal.tv_enum
+                  ]: return 0
+
+    if desc[0] in [omniORB.tcInternal.tv_float, 
+                   omniORB.tcInternal.tv_double,
+                   omniORB.tcInternal.tv_longdouble
+                  ]: return 0.0
+
+    if desc[0] in [omniORB.tcInternal.tv_sequence, 
+                   omniORB.tcInternal.tv_array,
+                  ]: return []
+
+
+    if desc[0] in [omniORB.tcInternal.tv_string ]: return ""
+    if desc[0] in [omniORB.tcInternal.tv_wstring,
+                   omniORB.tcInternal.tv_wchar
+                  ]: return u""
+
+    if desc[0] == omniORB.tcInternal.tv_struct:
+        arg = []
+        for i in  range(4, len(desc), 2):
+            attr = desc[i]
+            attr_type = desc[i+1]
+            arg.append(instantiateDataType(attr_type))
+        return desc[1](*arg)
+    return None
\ No newline at end of file



More information about the openrtm-commit mailing list