diff --git a/examples/a/a_test.py b/examples/a/a_test.py index 379ba7b..dd76218 100644 --- a/examples/a/a_test.py +++ b/examples/a/a_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/a") +sys.path.insert(0, "../../build/examples/a") from a import * ADoA () diff --git a/examples/b/b_test.py b/examples/b/b_test.py index 2fdf2c2..b996e3a 100644 --- a/examples/b/b_test.py +++ b/examples/b/b_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/b") +sys.path.insert(0, "../../build/examples/b") from b import * b = B () diff --git a/examples/boost_shared_ptr/bsp.cc b/examples/boost_shared_ptr/bsp.cc new file mode 100644 index 0000000..648c6c2 --- /dev/null +++ b/examples/boost_shared_ptr/bsp.cc @@ -0,0 +1,16 @@ +#include "bsp.h" + +boost::shared_ptr g_foo; + +void function_that_takes_foo(boost::shared_ptr foo) +{ + g_foo = foo; +} + +boost::shared_ptr function_that_returns_foo() +{ + return g_foo; +} + + + diff --git a/examples/boost_shared_ptr/bsp.h b/examples/boost_shared_ptr/bsp.h new file mode 100644 index 0000000..625066d --- /dev/null +++ b/examples/boost_shared_ptr/bsp.h @@ -0,0 +1,29 @@ +// -*- Mode: C++; c-file-style: "stroustrup"; indent-tabs-mode:nil; -*- +#ifndef BSP_H_ +# define BSP_H_ + +#include +#include + + +class Foo +{ + std::string m_datum; +public: + + Foo () : m_datum ("") {} + + Foo (std::string const &datum) : m_datum (datum) {} + + const std::string get_datum () const { return m_datum; } + + void set_datum (std::string const &datum) { m_datum = datum; } + + virtual ~Foo() {} + +}; + +void function_that_takes_foo (boost::shared_ptr foo); +boost::shared_ptr function_that_returns_foo (); + +#endif /* !FOO_H_ */ diff --git a/examples/boost_shared_ptr/bsp_test.py b/examples/boost_shared_ptr/bsp_test.py new file mode 100644 index 0000000..0b45b77 --- /dev/null +++ b/examples/boost_shared_ptr/bsp_test.py @@ -0,0 +1,15 @@ +import sys +import os.path +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), + '..', '..', 'build', 'examples', 'boost_shared_ptr')) + +import bsp + + +f = bsp.Foo("hello123") +bsp.function_that_takes_foo(f) +f1 = bsp.function_that_returns_foo() +print f1.get_datum() +f.set_datum("xxxx") +print f1.get_datum() + diff --git a/examples/boost_shared_ptr/modulegen.py b/examples/boost_shared_ptr/modulegen.py new file mode 100755 index 0000000..a1fae86 --- /dev/null +++ b/examples/boost_shared_ptr/modulegen.py @@ -0,0 +1,47 @@ +#! /usr/bin/env python + +import sys, os +sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), + '..', '..')) + +#import pybindgen +#import pybindgen.utils +#from pybindgen.typehandlers import base as typehandlers +from pybindgen import Module, FileCodeSink, param, retval +#from pybindgen import CppMethod, CppConstructor, CppClass, Enum +#from pybindgen.function import CustomFunctionWrapper +#from pybindgen.cppmethod import CustomCppMethodWrapper +from pybindgen import cppclass + +#from pybindgen import param, retval + +import pybindgen.settings +pybindgen.settings.deprecated_virtuals = False + + +def my_module_gen(out_file): + + mod = Module('bsp') + + mod.add_include ('"bsp.h"') + + Foo = mod.add_class('Foo', memory_policy=cppclass.BoostSharedPtr('::Foo')) + + Foo.add_constructor([param('std::string', 'datum')]) + Foo.add_constructor([]) + Foo.add_method('get_datum', retval('const std::string'), []) + Foo.add_method('set_datum', None, [param('const std::string', 'datum')]) + + + mod.add_function('function_that_takes_foo', None, + [param('boost::shared_ptr', 'foo')]) + + mod.add_function('function_that_returns_foo', retval('boost::shared_ptr'), []) + + ## ---- finally, generate the whole thing ---- + mod.generate(FileCodeSink(out_file)) + + +if __name__ == '__main__': + my_module_gen(sys.stdout) + diff --git a/examples/boost_shared_ptr/wscript b/examples/boost_shared_ptr/wscript new file mode 100644 index 0000000..72fcd31 --- /dev/null +++ b/examples/boost_shared_ptr/wscript @@ -0,0 +1,20 @@ +## -*- python -*- + +def build(bld): + + gen = bld.new_task_gen( + features='command', + source='modulegen.py', + target='bspmodule.cc', + command='${PYTHON} ${SRC[0]} > ${TGT[0]}') + + if bld.env['CXX']: + obj = bld.new_task_gen(features=['cxx', 'cxxshlib', 'pyext']) + obj.source = [ + 'bsp.cc', + 'bspmodule.cc' + ] + obj.target = 'bsp' + obj.install_path = None # do not install + obj.includes = '.' + diff --git a/examples/buffer/c_test.py b/examples/buffer/c_test.py index 6ed7e06..22baffc 100644 --- a/examples/buffer/c_test.py +++ b/examples/buffer/c_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/buffer") +sys.path.insert(0, "../../build/examples/buffer") import c print c.GetBufferLen() diff --git a/examples/c/c_test.py b/examples/c/c_test.py index 1c70876..371b515 100644 --- a/examples/c/c_test.py +++ b/examples/c/c_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/c") +sys.path.insert(0, "../../build/examples/c") from c import * c = C (10) diff --git a/examples/callback/c_test.py b/examples/callback/c_test.py index 2dda1d3..f5d814b 100644 --- a/examples/callback/c_test.py +++ b/examples/callback/c_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/callback") +sys.path.insert(0, "../../build/examples/callback") import c def visitor(value): diff --git a/examples/d/d_test.py b/examples/d/d_test.py index c62f3fc..36715d3 100644 --- a/examples/d/d_test.py +++ b/examples/d/d_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/d") +sys.path.insert(0, "../../build/examples/d") from d import * diff --git a/examples/e/e_test.py b/examples/e/e_test.py index 8f95a2e..4683cd5 100644 --- a/examples/e/e_test.py +++ b/examples/e/e_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/e") +sys.path.insert(0, "../../build/examples/e") from e import * e = E () diff --git a/examples/g/g_test.py b/examples/g/g_test.py index b326868..b9fbdf3 100644 --- a/examples/g/g_test.py +++ b/examples/g/g_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/g") +sys.path.insert(0, "../../build/examples/g") from g import * from g.G import GDoB from g.G.GInner import GDoC diff --git a/examples/h/h_test.py b/examples/h/h_test.py index 01f4346..dabd592 100644 --- a/examples/h/h_test.py +++ b/examples/h/h_test.py @@ -1,5 +1,5 @@ import sys -sys.path.insert(0, "../../build/default/examples/h") +sys.path.insert(0, "../../build/examples/h") from h import * h = H() diff --git a/examples/wscript b/examples/wscript index 0116749..d10e90c 100644 --- a/examples/wscript +++ b/examples/wscript @@ -7,8 +7,8 @@ def build(bld): bld.add_subdirs('a b c d e f g h') bld.add_subdirs('callback') bld.add_subdirs('buffer') - #if bld.env['HAVE_BOOST']: - # bld.add_subdirs('shared_ptr') + if bld.env['ENABLE_BOOST_SHARED_PTR']: + bld.add_subdirs('boost_shared_ptr') def configure(conf): pass