[cig-commits] r13919 - in short/3D/PyLith/branches/pylith-swig/modulesrc: . include
brad at geodynamics.org
brad at geodynamics.org
Thu Jan 22 08:07:42 PST 2009
Author: brad
Date: 2009-01-22 08:07:42 -0800 (Thu, 22 Jan 2009)
New Revision: 13919
Added:
short/3D/PyLith/branches/pylith-swig/modulesrc/include/
short/3D/PyLith/branches/pylith-swig/modulesrc/include/chararray.i
Log:
Added missing directory.
Added: short/3D/PyLith/branches/pylith-swig/modulesrc/include/chararray.i
===================================================================
--- short/3D/PyLith/branches/pylith-swig/modulesrc/include/chararray.i (rev 0)
+++ short/3D/PyLith/branches/pylith-swig/modulesrc/include/chararray.i 2009-01-22 16:07:42 UTC (rev 13919)
@@ -0,0 +1,99 @@
+// -*- C++ -*-
+//
+// ======================================================================
+//
+// Brad T. Aagaard
+// U.S. Geological Survey
+//
+// {LicenseText}
+//
+// ======================================================================
+//
+
+// Treat const char** as a special case.
+%typemap(in) (const char** string_list) {
+ // Check to make sure input is a list.
+ if (PyList_Check($input)) {
+ const int size = PyList_Size($input);
+ $1 = (size > 0) ? new char*[size] : 0;
+ for (int i = 0; i < size; i++) {
+ PyObject *s = PyList_GetItem($input,i);
+ if (PyString_Check(s))
+ $1[i] = PyString_AsString(PyList_GetItem($input,i));
+ else {
+ PyErr_SetString(PyExc_TypeError, "List must contain strings.");
+ delete[] $1;
+ return NULL;
+ } // else
+ } // for
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Expected list of strings.");
+ return NULL;
+ } // if/else
+} // typemap(in) const char**
+
+// This cleans up the char** array we malloc'd before the function call
+%typemap(freearg) (const char** string_list) {
+ delete[] $1;
+}
+
+
+// Treat const char** as a special case.
+%typemap(in) (const char** string_list, const int list_len) {
+ // Check to make sure input is a list.
+ if (PyList_Check($input)) {
+ const int size = PyList_Size($input);
+ $2 = size;
+ $1 = (size > 0) ? new char*[size] : 0;
+ for (int i = 0; i < size; i++) {
+ PyObject *s = PyList_GetItem($input,i);
+ if (PyString_Check(s))
+ $1[i] = PyString_AsString(PyList_GetItem($input,i));
+ else {
+ PyErr_SetString(PyExc_TypeError, "List must contain strings.");
+ delete[] $1;
+ return NULL;
+ } // else
+ } // for
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Expected list of strings.");
+ return NULL;
+ } // if/else
+} // typemap(in) const char**
+
+// This cleans up the char** array we malloc'd before the function call
+%typemap(freearg) (const char** string_list, const int list_len) {
+ delete[] $1;
+}
+
+
+// Treat char** as a special case.
+%typemap(in) (int argc, char** argv) {
+ // Check to make sure input is a list.
+ if (PyList_Check($input)) {
+ const int size = PyList_Size($input);
+ $1 = size;
+ $2 = (size > 0) ? new char*[size] : 0;
+ for (int i = 0; i < size; i++) {
+ PyObject *s = PyList_GetItem($input,i);
+ if (PyString_Check(s))
+ $2[i] = PyString_AsString(PyList_GetItem($input,i));
+ else {
+ PyErr_SetString(PyExc_TypeError, "List must contain strings.");
+ delete[] $2;
+ return NULL;
+ } // else
+ } // for
+ } else {
+ PyErr_SetString(PyExc_TypeError, "Expected list of strings.");
+ return NULL;
+ } // if/else
+} // typemap(in) char**
+
+// This cleans up the char** array we malloc'd before the function call
+%typemap(freearg) (int argc, char** argv) {
+ delete[] $2;
+}
+
+
+// End of file
More information about the CIG-COMMITS
mailing list