How to read int64 from XML?

I am saving custom session data in XML chunks, but am wondering how best to write/read int64 attribute values using the XmlElement functions. When I write them as attributes, I have to put them into a String (with String(value)) in order to avoid an “ambiguous function” error. But how can I safely read them back? There is a getIntAttribute() function, but that returns just an int. I need an int64, which (if I understand correctly) can be larger than a simple int. Or is that also safe for reading int64, now that we’re only supporting 64-bit platforms? (I know I get warnings about size mismatches if I simply assign an int64 value to an int variable.) Or, do I have to read it as a string and convert it afterwards?

Looks like I tackled this some time ago, and forgot:

String samplePosStr = pMarkerXml->getStringAttribute( "SamplePos" );
samplePos = samplePosStr.getLargeIntValue();

Would be helpful to have this as a member of the XmlElement, though.


If you parsed the juce::XmlElement to a juce::ValueTree you could simply cast the property to an int64:

auto tree = juce::ValueTree::fromXml (pMarkerXml);
auto samplePos = static_cast<juce::int64> (tree["SamplePos"]);

My way looks just as easy, and with less overhead. I would just like to not have to do that just because it’s a large int value.