Class-level instrospection

Daniel Walker a écrit :
Why don't we both package what we have, upload to vault, and then work out merging the two and adding the rest in another thread?
I've cleaned-up my files and 'boostified' them so to speak. I've uploaded a 'introspection.zip' on the vault so you can grab it and we can start discussing this in a proper topic ;) Basically i've uploaded the following : BOOST_HAVE_MEMBER_FUNCTION BOOST_HAVE_CONST_MEMBER_FUNCTION BOOST_HAVE_NON_CONST_MEMBER_FUNCTION BOOST_HAVE_MEMBER_DATA Basically, the usage is really simple. You want to check if classes provides a bool is_ok(long) method and you want to catch both const and non-const variations : BOOST_HAVE_MEMBER_FUNCTION(is_ok, bool(long) ) then the check itself is done via : has_member_function<T>::type For BOOST_HAVE_DATA_MEMBER, my method can only check for public members. So I added a macoer called BOOST_INSTROSPECTION_SUPPORT(C,V) that have to be used in user-defined class C that want to publish a member named V to our introspection mecanism. struct foo { private : int mValue; }; struct bar { BOOST_INTROSPECTION_SUPPORT(bar,mValue); private : int mValue; }; BOOST_HAVE_MEMBER_DATA(int, mValue) has_member_data_mValue<foo>::value is false has_member_data_mValue<bar>::value is true Other limitations is that currently you can't have various check for a method with a given name but different signature. I'm working on a fix using PP sequence and : BOOST_HAS_MEMBER_FUNCTION_OVERLOADS(func,(void())(void(int))(void(int,int))) In the same way, checking for suff like operator[] yields invalid class name has_member_function_operator[]. So I propose we hand-code the following : BOOST_HAS_SUBSCRIPT_OPERATOR( void(int) ) that builds a has_subscript_operator<T> class. Other similar operator should be handled the same way.

AMDG Joel Falcou wrote:
In the same way, checking for suff like operator[] yields invalid class name has_member_function_operator[]. So I propose we hand-code the following :
BOOST_HAS_SUBSCRIPT_OPERATOR( void(int) ) that builds a has_subscript_operator<T> class. Other similar operator should be handled the same way.
Can't you use a more general macro: BOOST_NAMED_HAS_MEMBER_FUNCTION(has_subscript_operator, operator[], void(int)) In Christ, Steven Watanabe

Joel Falcou wrote:
I've cleaned-up my files and 'boostified' them so to speak. I've uploaded a 'introspection.zip' on the vault so you can grab it and we can start discussing this in a proper topic ;)
What's the license on this? Someone in ##c++ on freenode has encountered a problem that basically needs this library to solve a problem, and was wondering what the license was so that he can use it in his project. Thanks! Sean

Sean Hunt a écrit :
What's the license on this?
Someone in ##c++ on freenode has encountered a problem that basically needs this library to solve a problem, and was wondering what the license was so that he can use it in his project.
Thanks!
Sean
Well, as I've bundled this up as a potential candidate for boost, consider it to use boost licensing ;) If needed I can drop by #c++ for additional help. -- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35

Hi, I was playing around with the introspection lib and it doesn't seem to work for public members that are not of POD type with Visual 7.1 Any idea how to work around that ? Thanks, Olivier. On Mon, Oct 20, 2008 at 8:29 AM, Joel Falcou <joel.falcou@u-psud.fr> wrote:
Sean Hunt a écrit :
What's the license on this?
Someone in ##c++ on freenode has encountered a problem that basically needs this library to solve a problem, and was wondering what the license was so that he can use it in his project.
Thanks!
Sean
Well, as I've bundled this up as a potential candidate for boost, consider it to use boost licensing ;) If needed I can drop by #c++ for additional help.
-- ___________________________________________ Joel Falcou - Assistant Professor PARALL Team - LRI - Universite Paris Sud XI Tel : (+33)1 69 15 66 35
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Olivier Grant a écrit :
Hi, I was playing around with the introspection lib and it doesn't seem to work for public members that are not of POD type with Visual 7.1
Any idea how to work around that ?
Thanks,
Olivier.
Thanks for reporting. THose were predictable so i'll take extra-care at solvign those. I don't have access to VC7.1, only to VC8. Does it fail to compile or does it returns incorrec results ? If the former, care to post error messages ? If the later, care to post a code I can compile on VC ? Thanks in advance

Hi, It compiles fine but the result is wrong if the member type is not POD. Forcing the resolution to use the "test( ... )" nested function yields the following compiler error : test.cpp(23) : error C2770: invalid explicit template argument(s) for 'has_type_to_test<T>::yes has_type_to_test<T>::test(has_type_to_test<T>::Helper<U,&U::value> *)' Here is the test code that I ran, simplifying your code to try and track down the pb: #include <iostream> /* * under VC7.1, if type_to_test is not a POD, the output * will be "false", else it will be "true". * * If the test( ... ) is commented out to force use of the * test( Helper<U, &U::value> * ) resolution, the VC7.1 will output * the following error message: * * test.cpp(23) : error C2770: invalid explicit template argument(s) for * 'has_type_to_test<T>::yes has_type_to_test<T>::test(has_type_to_test<T>::Helper<U,&U::value> *)' */ #if 0 // Changing this to 1 will yield a wrong output. class type_to_test { }; #else typedef int type_to_test; #endif /** * introspection */ template< typename T > struct has_type_to_test { private: typedef char no; typedef struct { no _[2]; } yes; template< typename U, type_to_test U::* > struct Helper; template< typename U > static yes test( Helper<U, &U::value> * ); template< typename U > static no test( ... ); public: static bool const result = (sizeof(yes) == sizeof(test<T>(0))); }; /** * dummy test structure. */ struct test_structure { type_to_test value; }; /** * main prog. */ int main( ) { std::cout << "has_type_to_test<test_structure>::result == " << std::boolalpha << has_type_to_test<test_structure>::result << "\n"; std::getchar(); return 0; } This codes compiles fine under gcc 4.x.x and yields the correct result as well. Don't hesitate if you have any other questions, Regards, Olivier. On Fri, Oct 24, 2008 at 6:06 PM, Joel Falcou <joel.falcou@u-psud.fr> wrote:
Olivier Grant a écrit :
Hi, I was playing around with the introspection lib and it doesn't seem to work for public members that are not of POD type with Visual 7.1
Any idea how to work around that ?
Thanks,
Olivier.
Thanks for reporting. THose were predictable so i'll take extra-care at solvign those. I don't have access to VC7.1, only to VC8. Does it fail to compile or does it returns incorrec results ? If the former, care to post error messages ? If the later, care to post a code I can compile on VC ?
Thanks in advance
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (4)
-
Joel Falcou
-
Olivier Grant
-
Sean Hunt
-
Steven Watanabe