Boost logo

Boost Users :

Subject: [Boost-users] Seeking to particular array element while deserializing
From: rajiv82 (rajiv82_at_[hidden])
Date: 2011-04-11 15:22:46


I have a structure like:

struct Header
{
    vector foo;
    vector bar;
};

I have created an array of above structure:

Header *ptr = new Header[1000];

Now doing serialization/deserialization works fine with binary_oarchive.

But, in some situation, I want to just deserialize particular element of
array(say element at index 80).
Is it possible using binary archive ?

I have a work around of writing each element one by one & while
de-serialization, ignore irrelevant data(in our case index 0-79) & then use
proper data. But it is not optimum solution.

I even tried xml archive with name as index & value as binary object by
using make_binary_object. Doing something like:

for(int i = 0 ; i<1000; i++)
{
    stringstream ss ; ss << i;
  ar << make_nvp(ss.str().c_str(), make_binary_object(&ptr[i], 1)) ;
}

And deserializing 80th index object like:
ar >> make_nvp("80", make_binary_object(&ptr[80], 1)) ;

Program compiles fine, but result is inconsistent.

Please suggest is there any better way to read(deserialize) just one element
of an array.

--
View this message in context: http://boost.2283326.n4.nabble.com/Seeking-to-particular-array-element-while-deserializing-tp3442887p3442887.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net