sudham / ticpp

Automatically exported from code.google.com/p/ticpp
0 stars 0 forks source link

Parsing an XML file using ticpp (tinyxml++) using streaming operators #69

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I'd like to utilize the streaming operator to parse an XML file with ticpp 
(tinyxml ++ ). I've not been able to find any examples on this. The ticpp 
documentation says only a little bit about streaming support.

I'd like to initialize streaming in with the following:

ifstream in;
in.open( m_sConfigFile, std::ios::in );

if( in.good() )
    in >> *this;
I'm not sure how to write the stream in function:

std::istream & operator >> ( std::istream & in, EffectMgr & r )
{   
    return in;
}
My XML file looks like this:

<? xml version="1.0" ?>

<EffectsMgr>
    <Effect name="textured-phong" >
        <Shader name="textured-phong.vert" type="Vertex" />
        <Shader name="textured-phong.frag" type="Fragment" />
        <VertexClass name="CustomVertex" />
        <Attribute name="VertexPosition" size="3" offset="0" />
        <Attribute name="VertexNormal" size="3" offset="3" />
        <Attribute name="VertexTexCoord" size="3" offset="6" />
    </Effect>
</EffectsMgr>
Are there any examples out there I should check out?

Original issue reported on code.google.com by johnny.m...@gmail.com on 19 Feb 2012 at 12:36

GoogleCodeExporter commented 9 years ago
I've updated my question, as I've found how to stream in from disk.

I'd like to utilize the streaming operator to parse an XML file with ticpp 
(tinyxml ++ ).  I've not been able to find any examples on this. 

I'd like to initialize streaming in with the following:

    ifstream in;
    in.open( m_sConfigFile, std::ios::in );

    if( in.good() )
        in >> *this;

Here's my solution for the stream in function:

    std::istream & operator >> ( std::istream & in, EffectMgr & r )
    {
        ticpp::Document doc;

        in >> doc;  

        ticpp::Iterator<ticpp::Element> EffectItr;      

        for( EffectItr = EffectItr.begin(doc.FirstChildElement()); EffectItr != EffectItr.end(); EffectItr ++ )
        {       
            // Generate Effect objects
        }

        return in;
    }

My question is how can I write the stream out function?

    std::ostream & operator << ( std::ostream & out, const EffectMgr & r )
    {
        // ????
        return out;
    }

My XML file looks like this:

    <? xml version="1.0" ?>

    <EffectsMgr>
        <Effect name="textured-phong" >
            <Shader name="textured-phong.vert" type="Vertex" />
            <Shader name="textured-phong.frag" type="Fragment" />
            <VertexClass name="CustomVertex" />
            <Attribute name="VertexPosition" size="3" offset="0" />
            <Attribute name="VertexNormal" size="3" offset="3" />
            <Attribute name="VertexTexCoord" size="3" offset="6" />
        </Effect>
        <Effect>
            ...
        </Effect>
    </EffectsMgr>

Original comment by johnny.m...@gmail.com on 20 Feb 2012 at 12:06