MACE  1.0.0
 All Classes Namespaces Files Functions Variables Enumerations Defines
libs/rpc/include/mace/rpc/describe.hpp
00001 #ifndef _MACE_RPC_DESCRIBE_HPP_
00002 #define _MACE_RPC_DESCRIBE_HPP_
00003 #include <mace/reflect/reflect.hpp>
00004 #include <vector>
00005 
00006 namespace mace { 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 MACE_REFLECT( mace::rpc::description::field, (name)(type) )
00041 MACE_REFLECT( mace::rpc::description, (fields) )
00042 
00043 #endif