Tommi,

sometimes it is useful to access JSON or XML fields
without a dedicated serialization structure.
SerializationInfo is convenient for that, but I don't see a way
to use it outside of serialization:
when I use cxxtools::xml::XmlDeserializer::si or
cxxtools::xml::XmlDeserializer::current the application crashes.

I have found a workaround using C++ lambdas:

struct FunctionOverSerializationInfo {
  std::function<void (const cxxtools::SerializationInfo&)> _fun;
  FunctionOverSerializationInfo (std::function<void (const
cxxtools::SerializationInfo&)> fun): _fun (fun) {}
};
void operator>>= (const cxxtools::SerializationInfo& si,
FunctionOverSerializationInfo fosi) {
  fosi._fun (si);
}

  std::ifstream is ("file");
  cxxtools::xml::XmlDeserializer ds (is);
  FunctionOverSerializationInfo dsFun (
    [&](const cxxtools::SerializationInfo& si) {
      // Use `si` there.
    }
  );
  ds.toObject (is, dsFun);

But is there a more direct way of using SerializationInfo
outside of object deserialization?


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general

Reply via email to