Add a boost::shared_ptr<> example
This commit is contained in:
1 parent
a17ce14a6e
commit
3b5e055dae
15 files changed
+138
-11
No files matched your search
@@ -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 ()
|
||||
|
||||
@@ -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 ()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "bsp.h"
|
||||
|
||||
boost::shared_ptr<Foo> g_foo;
|
||||
|
||||
void function_that_takes_foo(boost::shared_ptr<Foo> foo)
|
||||
{
|
||||
g_foo = foo;
|
||||
}
|
||||
|
||||
boost::shared_ptr<Foo> function_that_returns_foo()
|
||||
{
|
||||
return g_foo;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// -*- Mode: C++; c-file-style: "stroustrup"; indent-tabs-mode:nil; -*-
|
||||
#ifndef BSP_H_
|
||||
# define BSP_H_
|
||||
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
|
||||
|
||||
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> foo);
|
||||
boost::shared_ptr<Foo> function_that_returns_foo ();
|
||||
|
||||
#endif /* !FOO_H_ */
|
||||
@@ -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()
|
||||
|
||||
Executable
+47
@@ -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>', 'foo')])
|
||||
|
||||
mod.add_function('function_that_returns_foo', retval('boost::shared_ptr<Foo>'), [])
|
||||
|
||||
## ---- finally, generate the whole thing ----
|
||||
mod.generate(FileCodeSink(out_file))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
my_module_gen(sys.stdout)
|
||||
|
||||
@@ -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 = '.'
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import sys
|
||||
sys.path.insert(0, "../../build/default/examples/d")
|
||||
sys.path.insert(0, "../../build/examples/d")
|
||||
from d import *
|
||||
|
||||
|
||||
|
||||
@@ -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 ()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
+2
-2
@@ -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
|
||||
|
||||
Reference in new issue
Block a user