XML pointer question


A quick question- going through the tutorials for getStateInformation() and setStateInformation() I create two scoped pointers of XML element type. My understanding is that the choice to use pointers here is because we are looking to access and change this data in real time- am I correct in saying this?


It’s mainly just that it’s idiomatic to use XmlElement* rather than by value in many case. The getStateInformation() function could easily avoid using a pointer here:

void getStateInformation (MemoryBlock& destData) override
    XmlElement xml ("ParamTutorial");
    xml.setAttribute ("gain", (double) *gain);
    copyXmlToBinary (xml, destData);

But setStateInformation() relies on getXmlFromBinary() returning nullptr if it fails to parse the data as valid XML.

void setStateInformation (const void* data, int sizeInBytes) override
    ScopedPointer<XmlElement> xmlState (getXmlFromBinary (data, sizeInBytes));
    if (xmlState != nullptr)
        if (xmlState->hasTagName ("ParamTutorial"))
            *gain = xmlState->getDoubleAttribute ("gain", 1.0);

You also access child XML elements as XmlElement* hence it becoming idiomatic, but not a requirement, in other cases.