Note that there are some explanatory texts on larger screens.

plurals
  1. POBoost binary serialization with a map and doubles crashes on serialize in
    primarykey
    data
    text
    <p>This is a sample that represents my problem. The map will serialize perfectly fine unless finalTime is greater than 25. With boost unit testing I was given a std::exception input stream error. Also, this code works fine using polymorphic_text_archives. The error occurs while reading in the map.</p> <pre><code>#include &lt;fstream&gt; #include &lt;iostream&gt; #define BOOST_ALL_DYN_LINK #define BOOST_PARAMETER_MAX_ARITY 8 #include &lt;boost/serialization/export.hpp&gt; #include &lt;boost/archive/polymorphic_iarchive.hpp&gt; #include &lt;boost/archive/polymorphic_oarchive.hpp&gt; #include &lt;boost/archive/polymorphic_binary_iarchive.hpp&gt; #include &lt;boost/archive/polymorphic_binary_oarchive.hpp&gt; #include &lt;boost/static_assert.hpp&gt; #include &lt;boost/serialization/map.hpp&gt; using namespace boost; class DoubleTest { public: DoubleTest(double d) { this-&gt;Double = d; } DoubleTest() { this-&gt;Double = 0; } void serialize(boost::archive::polymorphic_iarchive &amp; ar, const unsigned int) { ar &amp; this-&gt;Double; } void serialize(boost::archive::polymorphic_oarchive &amp; ar, const unsigned int) { ar &amp; this-&gt;Double; } double Double; }; int main(int argc, char** argv) { const std::string fileName = "test.out"; std::map&lt;float, DoubleTest*&gt; mymap; const int initialValue = 0; const int initialTime = 0; // A "finalTime" of 25 works. "26" does not. const int finalTime = 26; int value = 10; // Put values into the map. for(int time = initialTime; time &lt; finalTime; time += 1) { value++; mymap[time] = new DoubleTest(value); } // Write a binary archive out. std::ofstream ofs(fileName.c_str()); boost::archive::polymorphic_binary_oarchive oa(ofs); oa &lt;&lt; mymap; ofs.flush(); ofs.close(); // Create a new map to read the binary archive into. std::map&lt;float, DoubleTest*&gt; mymap2; // Read in the new binary archive. std::ifstream ifs(fileName.c_str()); boost::archive::polymorphic_binary_iarchive ia(ifs); ia &gt;&gt; mymap2; ifs.close(); // Loop through the values to make sure they are correct. std::map&lt;float, DoubleTest*&gt;::iterator it; for(it = mymap2.begin(); it != mymap2.end(); ++it) { std::cout &lt;&lt; "Key: " &lt;&lt; it-&gt;first &lt;&lt; " "; std::cout &lt;&lt; "Value: " &lt;&lt; it-&gt;second-&gt;Double &lt;&lt; '\n'; } int pause; std::cin &gt;&gt; pause; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload