Am 17.05.2012 01:30, schrieb ArtemGr:
> 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?
>
There is a deserialization operator for SerializationInfo for that. So 
you can write:

     cxxtools::xml::XmlDeserializer d(std::cin);
     cxxtools::SerializationInfo si;
     d.deserialize(si);

The you have the data from the read xml file in the si object.

Tommi

------------------------------------------------------------------------------
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