开发者

how do i create a map and iterate between exp_tag and lhs to print them in sorted order?

extern int JAX_EXP_DEBUG_print_all_exps_in_session ( )
{
    tag_t part_tag = NULL_TAG;

    for ( PART_cycle_parts_in_world ( &part_tag ); part_tag; PART_cycle_parts_in_world ( &part_tag ) )
    {
        EXP_generic_p_t exp = NULL;

        for ( exp = EXP_generic_cycle_all_exps ( part_tag, exp ); exp; exp = EXP_generic_cycle_all_exps ( part_tag, exp ) )
        {

   //typedef map< tag_t, const char * > Exp_Map;
   Exp_Map new_map;
   tag_t exp_tag = OM_ask_object_tag ( exp );

   const char *lhs                = exp->GetLHSInLocale ( );
   logical     is_kf_exp          = exp->is_exp_kf ( );
   logical     is_system_exp      = exp->is_a_system_exp ( );
   logical     is_geometry_exp    = exp->is_geom_exp ( );
   logical     is_measure_exp     = EXP_kf_is_measure_exp ( exp );
   logical     is_visible_exp     = exp->is_exp_visible ( );
   logical     is_locked_exp      = exp->is_locked ( );
   logical     is_edit_locked_exp = exp->is_edit_locked ( );
   logical     is_user_locked_exp = exp->is_user_locked ( );
   const char *data_type          = exp->ask_data_type ( );
   const char *unit_name          = EXP_kf_ask_unit_name_of_exp ( exp );
   const char *rhs       = exp->GetRHSInLocale ( );

   new_map.insert( std::pair< tag_t, const char * >( exp_tag, lhs ) );

            for ( Exp_Map::iterator iter = new_map.begin(); iter != new_map.end(); ++iter )
            {
                JAM_test_print_tag_start ( iter->first, iter->second, 0 );
            }

            JAM_test_print_method_start  ( "IsKfEXP" );
            JAM_test_print_param_logical ( is_kf_exp, "is_kf_exp", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end    ( "IsKfExp" );

            JAM_test_print_method_start  ( "IsSystem开发者_开发百科Exp" );
            JAM_test_print_param_logical ( is_system_exp, "is_system_exp", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end    ( "IsSystemExp" );

            JAM_test_print_method_start  ( "IsGeometryExp" );
            JAM_test_print_param_logical ( is_geometry_exp, "is_geometry_exp", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end    ( "IsGeometryExp" );

            JAM_test_print_method_start  ( "IsMeasureExp" );
            JAM_test_print_param_logical ( is_measure_exp, "is_measure_exp", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end    ( "IsMeasureExp" );

            JAM_test_print_method_start  ( "IsVisibleExp" );
            JAM_test_print_param_logical ( is_visible_exp, "is_visible_exp", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end    ( "IsVisibleExp" );

            JAM_test_print_method_start  ( "IsLockedExp" );
            JAM_test_print_param_logical ( is_locked_exp, "is_locked_exp", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end    ( "IsLockedExp" );

            JAM_test_print_method_start  ( "IsEditLockedExp" );
            JAM_test_print_param_logical ( is_edit_locked_exp, "is_edit_locked_exp", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end    ( "IsEditLockedExp" );

            JAM_test_print_method_start  ( "IsUserLockedExp" );
            JAM_test_print_param_logical ( is_user_locked_exp, "is_user_locked_exp", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end    ( "IsUserLockedExp" );

            JAM_test_print_method_start ( "GetDataType" );
            JAM_test_print_param_string ( data_type, "data_type", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end   ( "GetDataType" );

            JAM_test_print_method_start ( "GetUnitName" );
            JAM_test_print_param_string ( unit_name, "unit_name", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end   ( "GetUnitName" );

            JAM_test_print_method_start ( "GetRightHandSide" );
            JAM_test_print_param_string ( rhs, "right_hand_side", JAM_PRINT_TYPE_RETURN_VAL );
            JAM_test_print_method_end   ( "GetRightHandSide" );

            /*  <JBT> 21-Apr-2009 PR#6140162
                Use double format for number values.
            */
            if ( STR_compare_i ( data_type, EXP_NUMBER_TYPE ) == 0 )
            {
                double value = ( ( EXP_expression_p_t ) exp )->GetDoubleValue ( );
                JAM_test_print_method_start ( "GetDoubleValue" );
                JAM_test_print_param_double ( value, "double_value", JAM_PRINT_TYPE_RETURN_VAL );
                JAM_test_print_method_end   ( "GetDoubleValue" );
            }
            else if ( STR_compare_i ( data_type, EXP_POINT_TYPE ) == 0 )
            {
                PNT3_t value = ( ( ExpKf::ExpPoint * ) exp )->GetPointValue ( );

                JAM_test_print_struct_start ( "GetPointValue", JAM_PRINT_TYPE_RETURN_VAL );
                JAM_test_print_param_double ( PNT3_X ( &value ), "point_value_x", JAM_PRINT_TYPE_STRUCT_ELEM );
                JAM_test_print_param_double ( PNT3_Y ( &value ), "point_value_y", JAM_PRINT_TYPE_STRUCT_ELEM );
                JAM_test_print_param_double ( PNT3_Z ( &value ), "point_value_z", JAM_PRINT_TYPE_STRUCT_ELEM );
                JAM_test_print_struct_end   ( "GetPointValue", JAM_PRINT_TYPE_RETURN_VAL );
            }
            else if ( STR_compare_i ( data_type, EXP_VECTOR_TYPE ) == 0 )
            {
                VEC3_t value = ( ( ExpKf::ExpVector * ) exp )->GetVectorValue ( );

                JAM_test_print_struct_start ( "GetVectorValue", JAM_PRINT_TYPE_RETURN_VAL );
                JAM_test_print_param_double ( VEC3_X ( &value ), "vector_value_x", JAM_PRINT_TYPE_STRUCT_ELEM );
                JAM_test_print_param_double ( VEC3_Y ( &value ), "vector_value_y", JAM_PRINT_TYPE_STRUCT_ELEM );
                JAM_test_print_param_double ( VEC3_Z ( &value ), "vector_value_z", JAM_PRINT_TYPE_STRUCT_ELEM );
                JAM_test_print_struct_end   ( "GetVectorValue", JAM_PRINT_TYPE_RETURN_VAL );
            }
            else
            {
                TEXT_p_t    text  = exp->ask_value_as_text ( );
                const char *value = TEXT_to_utf8 ( text );

                JAM_test_print_method_start ( "GetValueAsText" );
                JAM_test_print_param_string ( value, "value_as_text", JAM_PRINT_TYPE_RETURN_VAL );
                JAM_test_print_method_end   ( "GetValueAsText" );

                TEXT_free ( text );
            }

            JAM_test_print_tag_end   ( );
        }
    }

    return 0;
}


You need to define your map outside of the loop in line 5 and move your printing loop (the one with JAM_test_print_tag_start) outside of that outmost loop right before the return.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜