[C++-sig] Re: Auto-Generation and BPL v2

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Fri Nov 8 19:29:15 CET 2002


--- Brad King <brad.king at kitware.com> wrote:
> I've been developing a tool called "CABLE" (Cable Automates Bindings for
> Language Extension). Take a look at http://public.kitware.com/Cable for
> more information.  It already has a Tcl wrapper implementation that
> handles most of these problems.  I plan to add a wrapper generator to the
> project that generates Boost.Python v2 input files.

Taking a second look... Cool, no third syntax to learn! Even the "configuration
files" are pure C++!
To me this is a very important point. Currently this information is burried
 a bit in the "Running" page (I didn't get there when I first looked). It could
be helpful to have a dedicated "Configuration" section and to highlight the "no
third syntax" point near the beginning of the front page.

Your use of typedef's forces you to require implicit template instantiations.
How about something like this:

    namespace wrappers
    {
      // instead of typedef ::Bar<int> Bar_int;
      struct Bar_int : Bar<int> {};
    }

Am I right to assume that this will instantiate Bar<int>?

> It must be called as "f<int>()", and I'm not sure how we should go about
> specifying a name for this from a configuration point of view.  It gets
> even more complicated when some of the arguments are deduced, but not all:
> 
> template <typename A, typename B> void f(B) {}
> 
> This can be called as "f<int>(3.4)" or "f<int, double>(3.4)".  If we have
> a set of calls:
> 
>   f<int>(char());
>   f<int>(float());
> 
> should they all be called "f_int" and become overloads in python?  How
> does the user specify this in the config file?  Any suggestions are
> welcome.

Could something like this work?

    namespace cable {
      template <typename T> void wrap(T) {}
    }
    
    namespace wrappers
    {
      // to specify that they should all be called "f_int"
      void f_int()
      {
        cable::wrap(f<int, char>);
        cable::wrap(f<int, float>);
      }

      // or alternatively
      void f_int_double()
      {
        cable::wrap(f<int, double>);
      }
    }

One of the great features of Boost.Python is that you can .def Python methods
that have no equivalent in C++, most importantly the methods to support
pickling (__getinitarge__, __getstate__, __setstate__) but also methods such as
__repr__ or __str__. Suggestion:

    namespace wrappers
    {
      struct Bar_int : Bar<int>
      {
        typedef Bar<int> w_t;
        
        // "uu" == "underscore underscore"
        static
        uu_repr(w_t const& self) { /* code here */ }

        static
        any_additional_ordinary_method(w_t const& self) { /* code here */ }
      };
    }

Ralf


__________________________________________________
Do you Yahoo!?
HotJobs - Search new jobs daily now
http://hotjobs.yahoo.com/




More information about the Cplusplus-sig mailing list