[cig-commits] r12960 - in cs/cigma/trunk: . pysrc pysrc/tests

luis at geodynamics.org luis at geodynamics.org
Wed Sep 24 04:10:53 PDT 2008


Author: luis
Date: 2008-09-24 04:10:53 -0700 (Wed, 24 Sep 2008)
New Revision: 12960

Added:
   cs/cigma/trunk/pysrc/
   cs/cigma/trunk/pysrc/Makefile.am
   cs/cigma/trunk/pysrc/README
   cs/cigma/trunk/pysrc/pycigma.cpp
   cs/cigma/trunk/pysrc/pyhello.cpp
   cs/cigma/trunk/pysrc/setup.py
   cs/cigma/trunk/pysrc/tests/
   cs/cigma/trunk/pysrc/tests/test_cigma.py
   cs/cigma/trunk/pysrc/tests/test_hello.py
Log:
C++ bindings for _cigma python module (testing with DataPath class)

Added: cs/cigma/trunk/pysrc/Makefile.am
===================================================================
--- cs/cigma/trunk/pysrc/Makefile.am	                        (rev 0)
+++ cs/cigma/trunk/pysrc/Makefile.am	2008-09-24 11:10:53 UTC (rev 12960)
@@ -0,0 +1,31 @@
+###############################################################################
+# python module
+
+#lib_LTLIBRARIES += libcigma.la
+#libpycigma_la_SOURCES = foo.cpp
+#libpycigma_la_CPPFLAGS = $(libcigma_a_CPPFLAGS) $(PYTHON_INCLUDE_DIR)
+
+pyexec_PROGRAMS = _cigma.so
+
+clean-local:
+	rm -rf pybuild
+
+_cigma.so: $(_cigma_so_SOURCES) $(_cigma_so_DEPENDENCIES)
+	BUILD_DIR=`cd $(top_builddir); pwd`; \
+	(cd $(srcdir); \
+	CFLAGS="$(CPPFLAGS) -I$(srcdir) $(libcigma_a_CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)" \
+	LDFLAGS="$(LDFLAGS) -L$$BUILD_DIR/.libs" \
+	ARCHFLAGS="$(ARCHFLAGS)" PYLIBS="$(PYLIBS)" \
+	$(PYTHON_BIN) setup.py build --build-lib=$$BUILD_DIR/ --build-temp=$$BUILD_DIR/pybuild -f)
+
+_cigma_so_CXXFLAGS =
+_cigma_so_CXXFLAGS += -I$(top_srcdir)/src
+
+_cigma_so_LDADD =
+_cigma_so_LDADD += $(top_srcdir)/src/libcigma.a
+
+_cigma_so_SOURCES = \
+	pycigma.cpp
+
+
+#EOF

Added: cs/cigma/trunk/pysrc/README
===================================================================
--- cs/cigma/trunk/pysrc/README	                        (rev 0)
+++ cs/cigma/trunk/pysrc/README	2008-09-24 11:10:53 UTC (rev 12960)
@@ -0,0 +1,8 @@
+This directory contains the C++ bindings to Python
+
+To facilitate the build procedure, we make use of distutils to
+compile the Boost.Python module.
+
+
+    http://pydoc.org/2.5.1/distutils.extension.html
+

Added: cs/cigma/trunk/pysrc/pycigma.cpp
===================================================================
--- cs/cigma/trunk/pysrc/pycigma.cpp	                        (rev 0)
+++ cs/cigma/trunk/pysrc/pycigma.cpp	2008-09-24 11:10:53 UTC (rev 12960)
@@ -0,0 +1,17 @@
+#include "DataPath.h"
+#include <boost/python.hpp>
+using namespace boost::python;
+
+BOOST_PYTHON_MODULE(_cigma)
+{
+    class_<DataPath>("DataPath", no_init)
+        .def(init<std::string>())
+        .def("exists", &DataPath::exists)
+        .def("empty",  &DataPath::empty)
+        .def("extension", &DataPath::extension)
+        .def("filename", &DataPath::filename)
+        .def("location", &DataPath::location)
+        .def("set_filename", &DataPath::set_filename)
+        .def("set_location", &DataPath::set_location)
+        ;
+}

Added: cs/cigma/trunk/pysrc/pyhello.cpp
===================================================================
--- cs/cigma/trunk/pysrc/pyhello.cpp	                        (rev 0)
+++ cs/cigma/trunk/pysrc/pyhello.cpp	2008-09-24 11:10:53 UTC (rev 12960)
@@ -0,0 +1,19 @@
+#include <string>
+#include <boost/python.hpp>
+
+struct World
+{
+    void set(std::string msg) { this->msg = msg; }
+    std::string greet() { return msg; }
+    std::string msg;
+};
+
+using namespace boost::python;
+
+BOOST_PYTHON_MODULE(hello)
+{
+    class_<World>("World")
+        .def("greet", &World::greet)
+        .def("set", &World::set)
+    ;
+}

Added: cs/cigma/trunk/pysrc/setup.py
===================================================================
--- cs/cigma/trunk/pysrc/setup.py	                        (rev 0)
+++ cs/cigma/trunk/pysrc/setup.py	2008-09-24 11:10:53 UTC (rev 12960)
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+
+from distutils.core import setup, Extension
+
+import os
+
+defines = [('PYTHON_MODULE', 1)]
+
+#libs = os.environ["PYLIBS"].split()
+libs = ['boost_filesystem', 'boost_python']
+
+setup(name          = "_cigma",
+      version       = "1.0",
+      description   = "CIG Model Analysis Framework",
+      author        = "Luis Armendariz",
+      author_email  = "luis at geodynamics.org",
+      url           = "http://www.geodynamics.org/",
+      ext_modules   = [
+        Extension("_cigma", ['pysrc/pycigma.cpp'],
+            define_macros=defines,
+            libraries=libs,
+            extra_objects=['libcigma.a'])
+        ]
+)

Added: cs/cigma/trunk/pysrc/tests/test_cigma.py
===================================================================
--- cs/cigma/trunk/pysrc/tests/test_cigma.py	                        (rev 0)
+++ cs/cigma/trunk/pysrc/tests/test_cigma.py	2008-09-24 11:10:53 UTC (rev 12960)
@@ -0,0 +1,2 @@
+#!/usr/bin/env python
+import _cigma

Added: cs/cigma/trunk/pysrc/tests/test_hello.py
===================================================================
--- cs/cigma/trunk/pysrc/tests/test_hello.py	                        (rev 0)
+++ cs/cigma/trunk/pysrc/tests/test_hello.py	2008-09-24 11:10:53 UTC (rev 12960)
@@ -0,0 +1,6 @@
+#!/usr/bin/env python
+import hello
+planet = hello.World()
+planet.set('howdy')
+print planet.greet()
+



More information about the cig-commits mailing list