ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
[C++-sig] Re: playing with pygame
by Brett Calcott other posts by this author
Jun 6 2003 7:18AM messages near this date
[C++-sig] Re: playing with pygame | [C++-sig] Re: playing with pygame
> 
>  lvalue_from_pytype is a simple template; take a look.  You could write
>  an extract function which does the same thing, but which uses your
>  non-constant PyTypeObject* expression in place of the template
>  parameter, and register that just the way the lvalue_from_pytype
>  constructor does.
> 

Uh yeah. That wasn't so hard.

A bit of messing around with your template got me this:

template <class Extractor> 
struct lvalue_from_nonconst_pytype
{
    lvalue_from_nonconst_pytype(PyTypeObject *type)
    {
        // assume this is called only once
        m_type = type;
        converter::registry::insert(
            &extract, detail::extractor_type_id(&Extractor::execute));
    }
 private:
    static PyTypeObject *m_type;

    static void* extract(PyObject* op)
    {
        return PyObject_TypeCheck(op, m_type)
            ? const_cast<void*> (
                static_cast<void const volatile*> (

detail::normalize<Extractor> (&Extractor::execute).execute(op)))
            : 0
            ;
    }
};

template <class Extractor>  PyTypeObject *
    lvalue_from_nonconst_pytype<Extractor> ::m_type = 0;


BOOST_PYTHON_MODULE(test)
{
    import_pygame_rect();
    lvalue_from_nonconst_pytype<extract_identity<PyRectObject>  >
        need_this_or_msvc_barfs(&PyRect_Type);

    ...etc...

}


Finding out what the msvc problem was took more time than changing the
template...

I am having great fun :)
Thanks again,

Brett




_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
Brett Calcott
David Abrahams
Brett Calcott
Brett Calcott
David Abrahams
David Abrahams

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved