[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] applications/PyHLA/hla _omt/basicdata.cpp omt/_...
From: |
certi-cvs |
Subject: |
[certi-cvs] applications/PyHLA/hla _omt/basicdata.cpp omt/_... |
Date: |
Thu, 06 Nov 2008 08:17:29 +0000 |
CVSROOT: /sources/certi
Module name: applications
Changes by: Petr Gotthard <gotthardp> 08/11/06 08:17:29
Modified files:
PyHLA/hla/_omt : basicdata.cpp
PyHLA/hla/omt : __init__.py
Log message:
Added HLAoctet and HLAASCIIstring.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/hla/_omt/basicdata.cpp?cvsroot=certi&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/applications/PyHLA/hla/omt/__init__.py?cvsroot=certi&r1=1.2&r2=1.3
Patches:
Index: _omt/basicdata.cpp
===================================================================
RCS file: /sources/certi/applications/PyHLA/hla/_omt/basicdata.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- _omt/basicdata.cpp 12 Oct 2008 13:31:13 -0000 1.2
+++ _omt/basicdata.cpp 6 Nov 2008 08:17:28 -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: basicdata.cpp,v 1.2 2008/10/12 13:31:13 gotthardp Exp $
+ * $Id: basicdata.cpp,v 1.3 2008/11/06 08:17:28 gotthardp Exp $
*/
// note: you must include Python.h before any standard headers are included
@@ -128,7 +128,7 @@
template<class T>
const T*
-getUnpackBuffer(PyObject *args)
+getUnpackBuffer(PyObject *args, size_t *length = NULL)
{
const char *buffer;
int size;
@@ -139,6 +139,8 @@
PyErr_Format(PyExc_TypeError, "need at least %d bytes",
offset+sizeof(T));
return NULL;
}
+ if(length != NULL)
+ *length = size-offset;
return (T*)(buffer+offset);
}
@@ -459,6 +461,81 @@
{NULL} // sentinel
};
+/*
+ * HLAoctet
+ */
+static PyObject *
+HLAoctet_pack(PyObject *self, PyObject *args)
+{
+ char buffer;
+ if(!PyArg_ParseTuple(args, "c", &buffer))
+ return NULL;
+ return PyString_FromStringAndSize(&buffer, sizeof(char));
+}
+
+static PyObject *
+HLAoctet_unpack(PyObject *self, PyObject *args)
+{
+ const char *buffer = getUnpackBuffer<char>(args);
+ if(buffer == NULL)
+ return NULL;
+ return createObjectSizeTuple(PyString_FromStringAndSize(buffer,
sizeof(char)), sizeof(char));
+}
+
+static PyMethodDef HLAoctet_methods[] =
+{
+ {"pack", (PyCFunction)HLAoctet_pack, METH_VARARGS, NULL},
+ {"unpack", (PyCFunction)HLAoctet_unpack, METH_VARARGS, NULL},
+ {NULL} // sentinel
+};
+
+/*
+ * HLAASCIIstring
+ */
+static PyObject *
+HLAASCIIstring_pack(PyObject *self, PyObject *args)
+{
+ const char* value;
+ int length;
+ if(!PyArg_ParseTuple(args, "s#", &value, &length))
+ return NULL;
+
+ char *buffer = (char *)malloc(sizeof(int32_t)+length);
+ *(int32_t *)buffer = BigEndian<int32_t>()(length);
+ memcpy(buffer+sizeof(int32_t), value, length);
+
+ PyObject *result = PyString_FromStringAndSize(buffer,
sizeof(int32_t)+length);
+ free(buffer);
+
+ return result;
+}
+
+static PyObject *
+HLAASCIIstring_unpack(PyObject *self, PyObject *args)
+{
+ size_t size;
+ const int32_t *buffer = getUnpackBuffer<int32_t>(args, &size);
+ if(buffer == NULL)
+ return NULL;
+
+ int length = BigEndian<int32_t>()(*buffer);
+ if(size < sizeof(int32_t)+length) {
+ PyErr_Format(PyExc_TypeError, "need at least %d bytes",
sizeof(int32_t)+length);
+ return NULL;
+ }
+
+ return createObjectSizeTuple(
+ PyString_FromStringAndSize((const char *)buffer+sizeof(int32_t),
length),
+ sizeof(int32_t)+length);
+}
+
+static PyMethodDef HLAASCIIstring_methods[] =
+{
+ {"pack", (PyCFunction)HLAASCIIstring_pack, METH_VARARGS, NULL},
+ {"unpack", (PyCFunction)HLAASCIIstring_unpack, METH_VARARGS, NULL},
+ {NULL} // sentinel
+};
+
typedef struct {
const char* co_name;
long co_size;
@@ -481,6 +558,8 @@
#endif
{"HLAfloat32LE", sizeof(float), HLAfloat32LE_methods},
{"HLAfloat64LE", sizeof(double), HLAfloat64LE_methods},
+ {"HLAoctet", sizeof(char), HLAoctet_methods},
+ {"HLAASCIIstring", sizeof(char), HLAASCIIstring_methods},
{NULL} // sentinel
};
@@ -581,4 +660,4 @@
add_encoding(dict, pos->co_name, pos->co_size, pos->co_methods);
}
-// $Id: basicdata.cpp,v 1.2 2008/10/12 13:31:13 gotthardp Exp $
+// $Id: basicdata.cpp,v 1.3 2008/11/06 08:17:28 gotthardp Exp $
Index: omt/__init__.py
===================================================================
RCS file: /sources/certi/applications/PyHLA/hla/omt/__init__.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- omt/__init__.py 13 Oct 2008 17:15:39 -0000 1.2
+++ omt/__init__.py 6 Nov 2008 08:17:28 -0000 1.3
@@ -11,8 +11,9 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
-# $Id: __init__.py,v 1.2 2008/10/13 17:15:39 gotthardp Exp $
+# $Id: __init__.py,v 1.3 2008/11/06 08:17:28 gotthardp Exp $
+import types
import xml.sax.handler
from hla._omt import *
@@ -44,7 +45,11 @@
self.enumEnumerators +=
[(attributes["name"],int(attributes["values"]))]
elif name == "arrayData":
- if(attributes["cardinality"].lower() == "dynamic"):
+ # do not overwrite default datatypes
+ if attributes["name"] in ["HLAASCIIstring"]:
+ return
+
+ if attributes["cardinality"].lower() == "dynamic":
cardinality = None
else:
cardinality = attributes["cardinality"]
@@ -110,16 +115,13 @@
def __init__(self, representation, typeParameters = None):
self.representation = representation
self.typeParameters = typeParameters
- self._encoding = None
@property
def encoding(self):
- if(self._encoding == None):
- if(self.typeParameters == None):
- self._encoding = globals()[self.representation]
+ if self.parameters == None:
+ return globals()[self.representation]
else:
- self._encoding =
globals()[self.representation](self.typeParameters)
- return self._encoding;
+ return globals()[self.representation](*self.typeParameters)
@property
def octetBoundary(self):
@@ -138,4 +140,4 @@
parser.setContentHandler(handler)
parser.parse(filename)
-# $Id: __init__.py,v 1.2 2008/10/13 17:15:39 gotthardp Exp $
+# $Id: __init__.py,v 1.3 2008/11/06 08:17:28 gotthardp Exp $
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] applications/PyHLA/hla _omt/basicdata.cpp omt/_...,
certi-cvs <=