/* * Copyright (c) 2015 Cryptonomex, Inc., and contributors. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * 1. Any modified source or binaries are used only with the BitShares network. * * 2. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * * 3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ #include #include #include #include #include #include #include #include #include #include #include using namespace graphene::chain; namespace graphene { namespace member_enumerator { struct class_processor { explicit class_processor( std::map< std::string, std::vector< std::string > >& r ) : result(r) {} template< typename T > void process_class( const T* dummy ); template< typename... T > void process_class( const static_variant< T... >* dummy ); template< typename T > void process_class( const std::vector< T >* dummy ); template< typename K, typename V > void process_class( const std::map< K, V >* dummy ); template< typename T > void process_class( const fc::flat_set< T >* dummy ); template< typename K, typename V > void process_class( const fc::flat_map< K, V >* dummy ); template< typename T > void process_class( const fc::optional< T >* dummy ); template< typename T > static void process_class( std::map< std::string, std::vector< std::string > >& result ); std::map< std::string, std::vector< std::string > >& result; }; template< typename T > struct member_visitor { member_visitor( class_processor* p ) : proc(p) {} template void operator()( const char* name )const { members.emplace_back( name ); proc->process_class( (const Member*) nullptr ); } class_processor* proc; mutable std::vector< std::string > members; }; struct static_variant_visitor { explicit static_variant_visitor( class_processor* p ) : proc(p) {} typedef void result_type; template void operator()( const T& element )const { proc->process_class( (const T*) nullptr ); } class_processor* proc; }; template< typename... T > void class_processor::process_class( const static_variant< T... >* dummy ) { static_variant dummy2; static_variant_visitor vtor( this ); for( int w=0; w struct if_enum { template< typename T > static void process_class( class_processor* proc, const T* dummy ) { std::string tname = fc::get_typename::name(); if( proc->result.find( tname ) != proc->result.end() ) return; ilog( "processing class ${c}", ("c", tname) ); // need this to keep from recursing on same class proc->result.emplace( tname, std::vector< std::string >() ); member_visitor vtor( proc ); fc::reflector::visit( vtor ); ilog( "members of class ${c} are ${m}", ("c", tname)("m", vtor.members) ); proc->result[tname] = vtor.members; } }; template<> struct if_enum { template< typename T > static void process_class( class_processor* proc, const T* dummy ) { std::string tname = fc::get_typename::name(); std::cerr << "skipping reflected enum " << tname << std::endl; } }; template struct if_reflected { template< typename T > static void process_class( class_processor* proc, const T* dummy ) { std::string tname = fc::get_typename::name(); std::cerr << "skipping non-reflected class " << tname << std::endl; } }; template<> struct if_reflected { template< typename T > static void process_class( class_processor* proc, const T* dummy ) { if_enum< std::is_enum::value >::process_class(proc, dummy); } }; template< typename T > void class_processor::process_class( const T* dummy ) { if_reflected< typename fc::reflector::is_defined >::process_class( this, dummy ); } template< typename T > void class_processor::process_class( const std::vector< T >* dummy ) { process_class( (T*) nullptr ); } template< typename K, typename V > void class_processor::process_class( const std::map< K, V >* dummy ) { process_class( (K*) nullptr ); process_class( (V*) nullptr ); } template< typename T > void class_processor::process_class( const fc::flat_set< T >* dummy ) { process_class( (T*) nullptr ); } template< typename K, typename V > void class_processor::process_class( const fc::flat_map< K, V >* dummy ) { process_class( (K*) nullptr ); process_class( (V*) nullptr ); } template< typename T > void class_processor::process_class( const fc::optional< T >* dummy ) { process_class( (T*) nullptr ); } template< typename T > void class_processor::process_class( std::map< std::string, std::vector< std::string > >& result ) { class_processor proc(result); proc.process_class( (T*) nullptr ); } } } int main( int argc, char** argv ) { try { std::map< std::string, std::vector< std::string > > result; graphene::member_enumerator::class_processor::process_class(result); fc::mutable_variant_object mvo; for( const auto& e : result ) { variant v; to_variant( e.second, v , 1); mvo.set( e.first, v ); } std::cout << fc::json::to_string( mvo ) << std::endl; } catch ( const fc::exception& e ) { edump((e.to_detail_string())); } return 0; }