[C++-sig] using the same module in different files

Roman Yakovenko roman.yakovenko at gmail.com
Tue Apr 11 07:48:06 CEST 2006


On 4/11/06, Ralf W. Grosse-Kunstleve <rwgk at yahoo.com> wrote:
> --- Abhi <abhi at qualcomm.com> wrote:
>
> > I have 2 files
> > - A.h which I want to wrap in a file boost_A.cpp
> > - and B.h which I want to wrap in a file boost_B.cpp
> >
> > >>> File A.h
> >
> > class A
> > {
> >   public:
> >     void fooA();
> > };
> >
> > >>> File B.h
> >
> > class B
> > {
> >   public:
> >     void fooB();
> > };
> >
> >
> > File boost_A.cpp wraps class A, while file boost_B.cpp wraps class B.
> >
> > I want both these files to expose methods in the same module, ie, I want to
> > "semantically" use BOOST_PYTHON_MODULE(common) for both these files, so
> > that all the methods exposed from boost_A.cpp and boost_B.cpp get imported
> > by doing
> >
> > >> import common
> > >> a = common.A()
> > >> b = common.B()
> >
> >
> > Is this possible?
>
> IIUC, yes. Create a file boost_common.cpp, e.g.:
>
> void wrap_A();
> void wrap_B();
>
> BOOST_PYTHON_MODULE(common)
> {
>   wrap_A();
>   wrap_B();
> }
>
>
> boost_A.cpp would look like this:
>
> void
> wrap_A()
> {
>   class_<A>("A")
>   // ...
>   ;
> }
>
> And boost_B.cpp the same with A replaced by B. Compile the three files
> (boost_common.cpp, boost_A.cpp, boost_B.cpp) separately, but link like this:

An other approach it to create common package in pure Python that will hide
implementation/building blocks.

> HTH,
>         Ralf


--
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list