Initial commit

This commit is contained in:
Bassem Girgis
2018-12-20 17:34:07 -06:00
parent 7a2d899662
commit 81b4b9e273
34743 changed files with 5940233 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
TOP = ../..
SWIGEXE = $(TOP)/../swig
SWIG_LIB_DIR = $(TOP)/../$(TOP_BUILDDIR_TO_TOP_SRCDIR)Lib
CXXSRCS =
TARGET = example
INTERFACE = example.i
LIBS = -lm
SWIGOPT =
check: build
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' python_run
build:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' python_cpp
static:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' CXXSRCS='$(CXXSRCS)' \
SWIG_LIB_DIR='$(SWIG_LIB_DIR)' SWIGEXE='$(SWIGEXE)' \
SWIGOPT='$(SWIGOPT)' TARGET='mypython' INTERFACE='$(INTERFACE)' python_cpp_static
clean:
$(MAKE) -f $(TOP)/Makefile SRCDIR='$(SRCDIR)' TARGET='$(TARGET)' python_clean

View File

@@ -0,0 +1,17 @@
/* File : example.h */
#include <map>
#include <string>
template<class Key, class Value>
std::map<Key,Value> half_map(const std::map<Key,Value>& v) {
typedef typename std::map<Key,Value>::const_iterator iter;
std::map<Key,Value> w;
for (iter i = v.begin(); i != v.end(); ++i) {
w[i->first] = (i->second)/2;
}
return w;
}

View File

@@ -0,0 +1,27 @@
/* File : example.i */
%module example
%{
#include "example.h"
%}
%include std_string.i
%include std_pair.i
%include std_map.i
/* instantiate the required template specializations */
namespace std {
/* remember to instantiate the key,value pair! */
%template(DoubleMap) map<std::string,double>;
%template() map<std::string,int>;
}
/* Let's just grab the original header file here */
%include "example.h"
%template(halfd) half_map<std::string,double>;
%template(halfi) half_map<std::string,int>;
%template() std::pair<swig::SwigPtr_PyObject, swig::SwigPtr_PyObject>;
%template(pymap) std::map<swig::SwigPtr_PyObject, swig::SwigPtr_PyObject>;

View File

@@ -0,0 +1,79 @@
# file: runme.py
import example
pmap = example.pymap()
pmap["hi"] = 1
pmap["hello"] = 2
dmap = {}
dmap["hello"] = 1.0
dmap["hi"] = 2.0
print dmap.items()
print dmap.keys()
print dmap.values()
print dmap
hmap = example.halfd(dmap)
dmap = hmap
print dmap
for i in dmap.iterkeys():
print "key", i
for i in dmap.itervalues():
print "val", i
for k, v in dmap.iteritems():
print "item", k, v
dmap = example.DoubleMap()
dmap["hello"] = 1.0
dmap["hi"] = 2.0
for i in dmap.iterkeys():
print "key", i
for i in dmap.itervalues():
print "val", i
for k, v in dmap.iteritems():
print "item", k, v
print dmap.items()
print dmap.keys()
print dmap.values()
hmap = example.halfd(dmap)
print hmap.keys()
print hmap.values()
dmap = {}
dmap["hello"] = 2
dmap["hi"] = 4
hmap = example.halfi(dmap)
print hmap
print hmap.keys()
print hmap.values()
dmap = hmap
for i in dmap.iterkeys():
print "key", i
for i in dmap.itervalues():
print "val", i
for i in dmap.iteritems():
print "item", i
for k, v in dmap.iteritems():
print "item", k, v
print dmap