Bytemaster's Boost Libraries
|
00001 #ifndef _BOOST_RPC_DESCRIBE_HPP_ 00002 #define _BOOST_RPC_DESCRIBE_HPP_ 00003 #include <boost/reflect/reflect.hpp> 00004 #include <vector> 00005 00006 namespace boost { namespace rpc { 00007 00008 struct description { 00009 struct field { 00010 field( const std::string& n, const std::string& t ) 00011 :name(n),type(t){} 00012 std::string name; 00013 std::string type; 00014 }; 00015 std::vector< field > fields; 00016 }; 00017 00018 namespace detail { 00019 struct describe_visitor { 00020 describe_visitor( description& d ):desc(d){} 00021 00022 template<typename T, typename Class, T(Class::*p)> 00023 void operator()(const char* name )const { 00024 std::cerr<<" " << name << std::endl; 00025 desc.fields.push_back( description::field( name, boost::reflect::get_typename<T>() ) ); 00026 } 00027 description& desc; 00028 }; 00029 } 00030 00031 template<typename T> 00032 description describe_type() { 00033 description d; 00034 boost::reflect::reflector<T>::visit( detail::describe_visitor(d) ); 00035 return d; 00036 } 00037 00038 } } 00039 00040 BOOST_REFLECT( boost::rpc::description::field, (name)(type) ) 00041 BOOST_REFLECT( boost::rpc::description, (fields) ) 00042 00043 #endif