landmarkreader.cpp

来自「2009 ROBOCUP 仿真2DSERVER 源码」· C++ 代码 · 共 785 行 · 第 1/3 页

CPP
785
字号
            }            else if ( goal_mouth.side == LandmarkReader::SIDE_R )            {                rect.startx = rect.endx = rect_stack.top().endx;                side_found = true;                goal_mouth.side = LandmarkReader::SIDE_R;            }            else            {                // error                std::cerr << path << ": " << line                          << ": Cannot convert " << attr[i]                          << " attribute from " << attr[i+1] << std::endl;                return false;            }        }        else if ( std::string( attr[i] ) == LandmarkReader::STARTY_KW )        {            if ( rect_stack.size() == 0 )            {                if ( ! extract( attr[i], attr[i+1], rect.starty ) )                {                    return false;                }            }            else            {                if ( ! extract( attr[i], attr[i+1], rect.starty,                                rect_stack.top().starty, rect_stack.top().endy ) )                {                    return false;                }            }        }        else if ( std::string( attr[i] ) == LandmarkReader::ENDY_KW )        {            if ( rect_stack.size() == 0 )            {                if ( ! extract( attr[i], attr[i+1], rect.endy ) )                {                    return false;                }            }            else            {                if ( ! extract( attr[i], attr[i+1], rect.endy,                                rect_stack.top().starty, rect_stack.top().endy ) )                {                    return false;                }            }        }        else        {            // error            std::cerr << path << ": " << line                      << ": unknown attribute " << attr[i] << std::endl;            return false;        }    }    if ( ! side_found )    {        // error        std::cerr << path << ": " << line                  << ": goalMouth must specify a side\n" << std::endl;        return false;    }    rect_stack.push( rect );    if ( goal_mouth.side == LandmarkReader::SIDE_L )    {        goal_width_l = std::fabs( goal_mouth.starty - goal_mouth.endy );    }    else    {        goal_width_r = std::fabs( goal_mouth.starty - goal_mouth.endy );    }    return true;}boolLandmarkReader::processPitch( const char ** attr,                              bool main ){    LandmarkReader::rect_t rect = LandmarkReader::DEF_PITCH;    for ( int i = 0; attr[i]; i += 2 )    {        if ( std::string( attr[i] ) == LandmarkReader::STARTX_KW )        {            if ( rect_stack.size() == 0 )            {                if ( ! extract( attr[i], attr[i+1], rect.startx ) )                {                    return false;                }            }            else            {                if ( ! extract( attr[i], attr[i+1], rect.startx,                                rect_stack.top().startx, rect_stack.top().endx ) )                {                    return false;                }            }        }        else if ( std::string( attr[i] ) == LandmarkReader::STARTY_KW )        {            if ( rect_stack.size() == 0 )            {                if ( ! extract( attr[i], attr[i+1], rect.starty ) )                {                    return false;                }            }            else            {                if ( ! extract( attr[i], attr[i+1], rect.starty,                                rect_stack.top().starty, rect_stack.top().endy ) )                {                    return false;                }            }        }        else if ( std::string( attr[i] ) == LandmarkReader::ENDX_KW )        {            if ( rect_stack.size() == 0 )            {                if ( ! extract( attr[i], attr[i+1], rect.endx ) )                {                    return false;                }            }            else            {                if ( ! extract( attr[i], attr[i+1], rect.endx,                                rect_stack.top().startx, rect_stack.top().endx ) )                {                    return false;                }            }        }        else if ( std::string( attr[i] ) == LandmarkReader::ENDY_KW )        {            if ( rect_stack.size() == 0 )            {                if ( ! extract( attr[i], attr[i+1], rect.endy ) )                {                    return false;                }            }            else            {                if ( ! extract( attr[i], attr[i+1], rect.endy,                                rect_stack.top().starty, rect_stack.top().endy ) )                {                    return false;                }            }        }        else        {            // error            std::cerr << path << ": " << line                      << ": unknown attribute " << attr[i] << std::endl;            return false;        }    }    rect_stack.push(rect);    if ( main )    {        pitch = rect;    }    return true;}boolLandmarkReader::processFlag( const char **attr,                             bool goal ){    LandmarkReader::flag_t flag = LandmarkReader::DEF_FLAG;    if ( rect_stack.size() > 0 )    {        flag.x =( rect_stack.top().startx + rect_stack.top().endx ) * 0.5;        flag.y =( rect_stack.top().starty + rect_stack.top().endy ) * 0.5;    }    for(int i = 0; attr[i]; i += 2)    {        if ( std::string( attr[i] ) == LandmarkReader::X_KW )        {            if ( rect_stack.size() == 0 )            {                if ( ! extract( attr[i], attr[i+1], flag.x ) )                {                    return false;                }            }            else            {                if ( ! extract( attr[i], attr[i+1], flag.x,                                rect_stack.top().startx, rect_stack.top().endx ) )                {                    return false;                }            }        }        else if ( std::string( attr[i] ) == LandmarkReader::Y_KW )        {            if ( rect_stack.size() == 0 )            {                if ( ! extract( attr[i], attr[i+1], flag.y ) )                {                    return false;                }            }            else            {                if ( ! extract( attr[i], attr[i+1], flag.y,                                rect_stack.top().starty, rect_stack.top().endy ) )                {                    return false;                }            }        }        else if ( std::string( attr[i] ) == LandmarkReader::NAME_KW )        {            if ( ! extract( attr[i], attr[i+1], flag.name ) )            {                return false;            }        }        else if ( std::string( attr[i] ) == LandmarkReader::VER_KW )        {            if ( ! extract( attr[i], attr[i+1], flag.ver ) )            {                return false;            }        }        else        {            std::cerr << path << ": " << line                      << ": Unknown attribute " << attr[i] << std::endl;            return false;        }    }    addFlag( flag, goal );}#endif // HAVE_LIBEXPAT// Be very carefull when changing the default values.  If you// change from abs to percent or visa-versa, make sure you add// or remove the % sign in the print function and the loadDefaults.std::ostream &LandmarkReader::print( std::ostream & o ) const{    o << "<?xml version=\"1.0\"?>" << std::endl;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?