Adding the beginnings of an example for cross module inheritance. Not

building yet 'cause I don't  understand waf.  Why does every project I
look at use a different build system!
This commit is contained in:
Mike Owen committed 2012-12-10 23:26:25 -08:00
1 parent 2560c98f5e
commit 37dcfcb514
6 files changed
+126

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
from pybindgen import *
from ModuleGenerationFactory import *
# Module
mod = Module("A")
mod.add_include('"classes.hh"')
# Base
mod.begin_section("A_BaseBindings")
Base = mod.add_class("Base", allow_subclassing = True)
Base.add_constructor([])
Base.add_method("do_something", None, [], is_virtual=True)
mod.end_section("A_BaseBindings")
# Generate the code.
out = ModuleGenerationFactory("A.C", ["BaseBindings"])
mod.generate(out, "A")
out.close()
+20
View File
@@ -0,0 +1,20 @@
from pybindgen import *
from ModuleGenerationFactory import *
import Agen
# Module
mod = Module("B")
mod.add_include('"classes.hh"')
mod.add_include('"A.hh"')
# Derived
mod.begin_section("B_DerivedBindings")
Derived = mod.add_class("Derived", allow_subclassing = True, parent = Agen.Base)
Derived.add_constructor([])
Derived.add_method("do_something", None, [], is_virtual=True)
mod.end_section("B_DerivedBindings")
# Generate the code.
out = ModuleGenerationFactory("B.C", ["DerivedBindings"])
mod.generate(out, "B")
out.close()
@@ -0,0 +1,48 @@
import os
from pybindgen import *
#-------------------------------------------------------------------------------
# This is the implementation of the multi-section factory that allows us to
# write multiple source files for compiling.
#
# This is directly cribbed from Gustavo's example from the ns3 package at
# http://code.nsnam.org/ns-3-dev/file/e15adc7172f1/bindings/python/ns3modulegen.py
#-------------------------------------------------------------------------------
class ModuleGenerationFactory(module.MultiSectionFactory):
def __init__(self, main_file_name, modules):
print "main file name: ", main_file_name
print "modules: ", modules
self.basename, ext = os.path.splitext(main_file_name)
super(ModuleGenerationFactory, self).__init__()
self.main_file_name = main_file_name
self.main_sink = FileCodeSink(open(main_file_name, "wt"))
self.header_name = self.basename + ".hh"
header_file_name = os.path.join(os.path.dirname(self.main_file_name),
'.',
self.header_name)
self.header_sink = FileCodeSink(open(header_file_name, "wt"))
self.section_sinks = {'__main__': self.main_sink}
for module in modules:
section_name = '%s_%s' % (self.basename, module.replace('-', '_'))
file_name = os.path.join(os.path.dirname(self.main_file_name), "%s.C" % section_name)
sink = FileCodeSink(open(file_name, "wt"))
self.section_sinks[section_name] = sink
def get_section_code_sink(self, section_name):
return self.section_sinks[section_name]
def get_main_code_sink(self):
return self.main_sink
def get_common_header_code_sink(self):
return self.header_sink
def get_common_header_include(self):
return '"%s"' % self.header_name
def close(self):
self.header_sink.file.close()
self.main_sink.file.close()
for sink in self.section_sinks.itervalues():
sink.file.close()
@@ -0,0 +1,20 @@
#ifndef __PYBINDGEN_CROSS_MODULE_EXAMPLE_CLASSES_HH__
#define __PYBINDGEN_CROSS_MODULE_EXAMPLE_CLASSES_HH__
#include <iostream>
class Base {
public:
Base() { std::cerr << "Base::Base()" << std::endl; }
virtual ~Base() { std::cerr << "Base::~Base()" << std::endl; }
virtual void do_something() const { std::cerr << "Base::do_something()" << std::endl; }
};
class Derived: public Base {
public:
Derived(): Base() { std::cerr << "Derived::Derived()" << std::endl; }
virtual ~Derived() { std::cerr << "Derived::~Derived()" << std::endl; }
virtual void do_something() const { std::cerr << "Derived::do_something()" << std::endl; }
};
#endif
+19
View File
@@ -0,0 +1,19 @@
## -*- python -*-
def build(bld):
gen = bld.new_task_gen(
features='command',
source='Agen.py',
target='A.C',
command='${PYTHON} ${SRC[0]} > ${TGT[0]}')
if bld.env['CXX']:
obj = bld.new_task_gen(features=['cxx', 'cxxshlib', 'pyext'])
obj.source = [
'A.C',
]
obj.target = 'A'
obj.install_path = None # do not install
obj.includes = '.'
+1
View File
@@ -9,6 +9,7 @@ def build(bld):
bld.add_subdirs('buffer')
if bld.env['ENABLE_BOOST_SHARED_PTR']:
bld.add_subdirs('boost_shared_ptr')
bld.add_subdirs('cross_module_inheritance')
def configure(conf):
pass