4

任何人都可以帮助我使用 boost 属性树迭代我拥有的 XML 文件中的变量吗?

<HLSL>
  <Constants>
    <Constant name ="myObject">
      <Variable name ="matWorld" class ="matrix" type="float" rows="4" cols="4"/>
      <Variable name ="vObjectPosition" class ="vector" type="float" rows="1" cols="3"/>
      <Variable name ="arrayIndex" class ="scalar" type="int" rows="0" cols="0"/>
    </Constant>
  </Constants>
</HLSL>

到目前为止,这是我的代码 [它不会超过 XML 中的第一个变量]

void CFxCompiler::LoadShader(const string& headerName, const string& asmName)
{
    using std::vector;

    // Create an empty property tree object
    iptree pt;

    // Load the XML file into the property tree. If reading fails
    // (cannot open file, parse error), an exception is thrown.
    read_xml(headerName, pt);

    iptree &itorLevel = pt.get_child("HLSL");
    iptree &constLevel = itorLevel.get_child("Constants");
    BOOST_FOREACH(iptree::value_type& constant, constLevel.get_child("Constant"))
    {   
        BOOST_FOREACH(iptree::value_type& constAttrib, constLevel.get_child("Constant.<xmlattr>"))
        {
            std::string bufferName = constAttrib.second.get<std::string>("");
            CConstantFormatPtr pConstFormat = make_shared<CConstantFormat>(bufferName, 0);

            // Populate the variables
            iptree &varLevel = constLevel.get_child("Constant.Variable");
            BOOST_FOREACH(iptree::value_type& variable, varLevel.get_child("") )
            {
                std::string attribute = variable.first;
                BOOST_FOREACH(iptree::value_type& variableAttrib, varLevel.get_child( attribute.c_str() ))
                {
                    //CConstantElementDesc desc = BuildConstantVariable(variableAttrib);
                    int pause = 1;
                }
            }

        }
     }
4

0 回答 0