[C++-sig] Exposing Abstract Classes and factories

Rod Cloutier rodlist at hotmail.com
Tue Apr 18 05:29:55 CEST 2006


Hi,

I am trying to use pyplusplus to expose python binding to a library. The library currently uses a lot of abstract classes and generate concrete object through factories. I am currently unable to use, in python, any of the object created through the factories. Is it possible to expose abstract classes in python and call concrete object, not exposed in python, through the interface ?

Here is a concise example of the problem:

Many thanks for your help


Rod


==================== Hello.h  =============================

#include <memory>

class Abstract
{
public:
 virtual void run() const = 0;
};

std::auto_ptr<Abstract> create();


==================== Hello.cpp  =============================

#include <iostream>
#include "hello.h"

class Concrete : public Abstract
{
 virtual void run( ) const
 {
  std::cout << "Concrete ran!";
 }
};

std::auto_ptr<Abstract> create()
{
 return std::auto_ptr<Abstract>( new Concrete() );
}


==================== PyPlusPlus Code  =============================

from pyplusplus import module_builder
from pyplusplus import code_creators


mb = module_builder.module_builder_t( [r"hello.h"]
                                      , gccxml_path=r"C:/GCC_XML/bin" 
                                      , working_directory=r"."
                                      , include_paths=['.']
                                      , define_symbols=[] )

mb.build_code_creator( module_name='pyplusplusTest' )
mb.write_module( './bindings.cpp' )


==================== Python Test Code =============================

import pyplusplusTest

instance = pyplusplusTest.create()
instance.run()


--------------------- Error obtained -----------------------
Traceback (most recent call last):
  File "D:\dev\cplusplus\pyplusplusTest\Debug\test.py", line 5, in ?
    instance.run()
Boost.Python.ArgumentError: Python argument types in
    Abstract.run(Abstract)
did not match C++ signature:
    run(struct Abstract_wrapper {lvalue})
    run(struct Abstract_wrapper {lvalue})
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060417/2eb810cb/attachment.htm>


More information about the Cplusplus-sig mailing list