Re: [pygccxml-development] Tag for Methods to bind ?
Brought to you by:
mbaas,
roman_yakovenko
|
From: Ben S. <bsc...@lu...> - 2008-07-07 18:46:53
|
I just found the code.
--------------------------------------------
#ifndef PREPROCESS
// This forces the class to have a virtual table so definition
system works correctly
#define META_CLASS(...) virtual void __META_CLASS_FUNCTION__(void)
{};
#define META_FIELD(...)
// #define META_METHOD(...)
#define META_ENUM(...)
#define META_INFO(key, value)
#define META_PROPERTY(...)
#else
// Define the macros as nothing
#define META_CLASS(x) __attribute__((gccxml("META_CLASS", #x))) \
virtual void __META_CLASS_FUNCTION__(void);
// These multiple definitions of helper are intended to allow each
META_INFO
// line appear as a unique declaration to the compiler
#define META_FIELD(x) META_FIELD_HELPER(__LINE__, x)
#define META_FIELD_HELPER(line, x) META_FIELD_HELPER2(line, x)
#define META_FIELD_HELPER2(line, x) \
__attribute__((gccxml("META_FIELD", #x))) \
void __META_FIELD_FUNCTION__ ## line () {};
#define META_METHOD(x) __attribute__((gccxml("META_METHOD", #x)))
#define META_ENUM(x) META_ENUM_HELPER(__LINE__, x)
#define META_ENUM_HELPER(line, x) META_ENUM_HELPER2(line, x)
#define META_ENUM_HELPER2(line, x) \
__attribute__((gccxml("META_ENUM", #x))) \
void __META_ENUM_FUNCTION__ ## line () {};
#define META_INFO(key, value) META_INFO_HELPER(__LINE__, key, value)
#define META_INFO_HELPER(line, key, value) META_INFO_HELPER2(line,
key, value)
#define META_INFO_HELPER2(line, key, value) \
__attribute__((gccxml("META_INFO", key, value))) \
void __META_INFO_FUNCTION__ ## line () {};
#define META_PROPERTY(x) META_PROPERTY_HELPER(__LINE__, x)
#define META_PROPERTY_HELPER(line, x) META_PROPERTY_HELPER2(line, x)
#define META_PROPERTY_HELPER2(line, x) \
__attribute__((gccxml("META_PROPERTY", #x))) \
void __META_PROPERTY_FUNCTION__ ## line () {};
#endif
----------------------------------------------
class Foo
{
META_CLASS(CLASS INFO HERE);
META_INFO("Class Type", "This is info separated by spaces");
META_INFO("MY_COMPANY_SPECIFIC_INFO_NOTICE", "Some info
here..");
META_INFO("DOC", "Class Documentation here..");
// These are Qt style property declarations.
META_PROPERTY(int Foo);
META_PROPERTY(string Name READONLY DOC "This is the name
property of this");
// These fields is not exported
void* nulptr;
int baz;
// These fields are exported
META_FIELD(NODEF NOREFLECT VALUE="1,1,1") Vec3 foo;
META_FIELD(NODEF DOC "This is the bar,:. field") int bar;
// Exported
META_METHOD(NODEF NOOID DOC "gfg") int doIt() const { return
4*3+12; }
// Not exported
int fooIt() { }
// We can even export enums!! Yeah!
META_ENUM(NOOID) enum colors { red, blue, green } ;
}
-----------------------------------------------------
I was really, really happy with this approach but it couldn't happen
(yet!) for various reasons. :(
Cheers
Ben
> -----Original Message-----
> From: Roman Yakovenko [mailto:rom...@gm...]
> Sent: Monday, July 07, 2008 11:23 AM
> To: Ben Schleimer
> Cc: Damien Fagnou; pyg...@li...
> Subject: Re: [pygccxml-development] Tag for Methods to bind ?
>
> On Mon, Jul 7, 2008 at 9:14 PM, Ben Schleimer
> <bsc...@lu...> wrote:
> > I had this same idea. Instead of putting the annotations inside the
> > comments, I made Qt style macros which I prepended to my
> > function/enum/field declarations.
> >
> > Something like
> > META_CLASS() class A {
> > META_METHOD() APtr create();
> >
> > // No annotations before this one so it isn't exposed
> > float * getInternals();
> >
> > ....
> > }
> >
> > The macros turn into __attribute((gccxml("META_XXX")));
> > when a preprocessor flag is defined and turns into nothing
> otherwise.
> > The cool thing is that you can have additional annotations work by
> > using macro inlining... I can't find the code anymore but
> it did work...
>
> You are right, this is another valid option.
> Every declarations contains "attributes" property wchih gives
> you access to them (
> http://language-binding.net/pyplusplus/documentation/apidocs/p
> ygccxml.declarations.declaration.declaration_t-class.html#attributes
> )
>
> This approach has speed advantage and it is less error prone.
>
> --
> Roman Yakovenko
> C++ Python language binding
> http://www.language-binding.net/
>
>
|