#include #include #include #include #include #include #include #include // ------------------------------------------------------------------------- typedef std::map< std::string, std::string > TPair; typedef std::map< std::string, TPair > TInfo; // ------------------------------------------------------------------------- bool is_valid_class( const std::string& str ) { return( str.find( "cpPlugins_Id_Macro" ) != std::string::npos ); } // ------------------------------------------------------------------------- void process_header( TInfo& info, const std::string& file_name ) { // Load file into a buffer std::ifstream file_stream( file_name.c_str( ) ); if( !file_stream ) return; std::string buf; file_stream.seekg( 0, std::ios::end ); buf.reserve( ( unsigned int )( file_stream.tellg( ) ) ); file_stream.seekg( 0, std::ios::beg ); buf.assign( ( std::istreambuf_iterator< char >( file_stream ) ), std::istreambuf_iterator< char >( ) ); file_stream.close( ); // Replace separators with spaces std::replace( buf.begin( ), buf.end( ), ',', ' ' ); std::replace( buf.begin( ), buf.end( ), ';', ' ' ); std::replace( buf.begin( ), buf.end( ), ':', ' ' ); std::replace( buf.begin( ), buf.end( ), '(', ' ' ); std::replace( buf.begin( ), buf.end( ), ')', ' ' ); std::replace( buf.begin( ), buf.end( ), '{', ' ' ); std::replace( buf.begin( ), buf.end( ), '}', ' ' ); // Tokenize buffer std::istringstream tokenizer( buf ); std::vector< std::string > tokens; std::copy( std::istream_iterator< std::string >( tokenizer ), std::istream_iterator< std::string >( ), std::back_inserter( tokens ) ); // Find pivot auto p = std::find_if( tokens.begin( ), tokens.end( ), is_valid_class ); if( p != tokens.end( ) ) { // Find class name and category auto cls_it = p; cls_it++; auto cat_it = cls_it; cat_it++; // Find namespace typedef std::reverse_iterator< std::vector< std::string >::iterator > _RIt; _RIt r_end( tokens.begin( ) ); _RIt r_begin( cls_it ); auto ns_it = std::find( r_begin, r_end, "namespace" ); ns_it--; // Update info info[ *cat_it ][ *cls_it ] = *ns_it; } // fi } // ------------------------------------------------------------------------- int main( int argc, char* argv[] ) { if( argc < 3 ) { std::cerr << "Usage: " << argv[ 0 ] << " output_file header_file_0.h header_file_0.h ..." << std::endl; return( 1 ); } // fi // Parse all header files TInfo info; for( int i = 2; i < argc; ++i ) process_header( info, argv[ i ] ); if( info.size( ) == 0 ) { std::cerr << "ERROR: No valid input headers." << std::endl; return( 1 ); } // fi // Write data std::ofstream out_stream( argv[ 1 ] ); // Write include section for( int i = 2; i < argc; ++i ) out_stream << "#include \"" << argv[ i ] << "\"" <second.begin( ); jIt != iIt->second.end( ); ++jIt ) out_stream << " classes += std::string( \"" << iIt->first << ":" << jIt->first << ";\" );" << std::endl; out_stream << " return( classes.c_str( ) );" << std::endl << "}" << std::endl << std::endl; // Write creators for( auto iIt = info.begin( ); iIt != info.end( ); ++iIt ) { for( auto jIt = iIt->second.begin( ); jIt != iIt->second.end( ); ++jIt ) { out_stream << "extern \"C\" " << export_prefix << " void* " << iIt->first << "_" << jIt->first << "( )" << std::endl << "{" << std::endl << " static " << jIt->second << "::" << jIt->first << "::Pointer f;" << std::endl << " f = " << jIt->second << "::" << jIt->first << "::New( );" << std::endl << " return( &f );" << std::endl; out_stream << "}" << std::endl << std::endl; } // rof } // rof out_stream.close( ); return( 0 ); } // eof - $RCSfile$