
On Tue, Nov 4, 2008 at 9:47 PM, Jean-Louis Leroy <jl@yorel.be> wrote:
I have renamed my library 'introspection' (to avoid clashing with Jeremy's work) and committed it to the sandbox.
FYI there already is a library named introspection in the vault written by Joel Falcou.
Today I wet my feet with Boost.Mirror. Using the doc (and the source code ;-)) I was able to make the code at the bottom of this message work. After a couple of hours 1/ I was very impressed 2/ I had a headache 3/ I was convinced that building runtime reflection on top of your work will be easy and 4/ I had found a bug ;-)
1/ I hope the impression was positive ;), thanks 2/ Sorry about the headache ;) 3/ I hope I will be helpful 4/ Thanks for spotting it !
Sure, we must write the backend in such a way that it is useable stand-alone then write generators. My experience is that generators are fine as long as you have only one of them in a project but two won't coexist well, usually.
sounds reasonable.
I'm running out of time, I have to work on serious things, namely preparing my trip to ... Slovakia !
Well, hope we can manage meet.
Here's my Mirror hello-world, with the bug report:
Whee, this is the first program using mirror written by somebody else than myself, that I've seen so far :)
#include <iostream>
#include <boost/mirror/meta_class.hpp> #include <boost/mirror/meta_inheritance.hpp> #include <boost/mirror/algorithm/for_each.hpp>
using namespace std; using namespace boost; using namespace boost::mirror;
struct animal { int age; };
struct mammal : virtual animal { };
struct carnivore : virtual animal { };
struct dog : mammal, carnivore { };
namespace boost { namespace mirror {
BOOST_MIRROR_REG_TYPE_GLOBAL_SCOPE(animal) BOOST_MIRROR_REG_CLASS_ATTRIBS_BEGIN(animal) BOOST_MIRROR_REG_SIMPLE_CLASS_ATTRIB(_, int, age) BOOST_MIRROR_REG_CLASS_ATTRIBS_END
BOOST_MIRROR_REG_TYPE_GLOBAL_SCOPE(mammal) BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(mammal) BOOST_MIRROR_REG_VIRTUAL_BASE_CLASS(0, public, animal) BOOST_MIRROR_REG_BASE_CLASSES_END
// watch out: BOOST_MIRROR_REG_SINGLE_BASE_CLASS_VIRTUAL(mammal, public, animal) // doesn't work because it calls BOOST_MIRROR_REG_BASE_CLASS_VIRTUAL // instead of BOOST_MIRROR_REG_VIRTUAL_BASE_CLASS
Again, thanks for your bug report, I'm going to fix it ASAP.
BOOST_MIRROR_REG_TYPE_GLOBAL_SCOPE(carnivore) BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(carnivore) BOOST_MIRROR_REG_VIRTUAL_BASE_CLASS(0, public, animal) BOOST_MIRROR_REG_BASE_CLASSES_END
BOOST_MIRROR_REG_TYPE_GLOBAL_SCOPE(dog) BOOST_MIRROR_REG_BASE_CLASSES_BEGIN(dog) BOOST_MIRROR_REG_BASE_CLASS(0, public, mammal) BOOST_MIRROR_REG_BASE_CLASS(1, public, carnivore) BOOST_MIRROR_REG_BASE_CLASSES_END
} }
struct print_attribute { template<typename ATTRIBUTE> void operator()(ATTRIBUTE) { cout << ATTRIBUTE::get_name(mpl::false_(), std::char_traits<char>()) << endl; } };
struct print_base { template<typename CLASS> void display(CLASS, virtual_base_) { cout << "virtual " << CLASS::meta_base_class::get_name(mpl::false_(), std::char_traits<char>()) << endl; } template<typename CLASS> void display(CLASS, nonvirtual_base_) { cout << CLASS::meta_base_class::get_name(mpl::false_(), std::char_traits<char>()) << endl; } template<typename CLASS> void operator()(CLASS c) { display(c, CLASS::inheritance_specifier()); } };
int main() { mirror::for_each< meta_class<animal>::attributes >(print_attribute()); mirror::for_each< meta_class<mammal>::base_classes >(print_base()); mirror::for_each< meta_class<dog>::base_classes >(print_base()); return 0; }
Cordially, Jean-Louis _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Best, --matus