[serialization] serializing an stl container.
Hey,
I've been banging my head against the wall for hours on this one.
I'd like to serialize stl containers to an archive. Starting simple: a
vector<int>
This is what I think I should do:
1) include the proper support header file for the to be serialized
container.
#include
what compiler are you running? which version of boost are you running? do the tests/examples run on your system? what do the warnings say? I would think what you've done below should work. Robert Ramey Lucas Meijer wrote:
Hey,
I've been banging my head against the wall for hours on this one. I'd like to serialize stl containers to an archive. Starting simple: a vector<int>
This is what I think I should do:
1) include the proper support header file for the to be serialized container.
#include
2) create an archive, can be any type:
std::stringstream ss; boost::archive::text_oarchive oa(ss);
3) operator<< my container into this archive:
const vector<int> myvec; oa << myvec;
The "oa << myvec" generates lots of warnings, and when running it anyway, it crashes in smart_cast.hpp
I've tried lots of containertypes, and creating them in other ways than shown above, using a binary_oarchive, but it doesn't seem to make a difference.
(int myint; oa << myint; works fine)
Does anybody see what I'm missing here?
Thanks, Lucas
Hey Robert, first off, thanks for the work on the serialization library, it looks really good so far. sorry for not including this info in my original post.
what compiler are you running?
Microsoft Visual Studio .NET 2003 boost succesfully built using boost.jam
which version of boost are you running?
1_33_0
do the tests/examples run on your system?
yes.
what do the warnings say?
warning C4541: 'dynamic_cast' used on polymorphic type 'boost::archive::detail::basic_oarchive' with /GR-; unpredictable behavior may result (see full warning below.) this is compiling the following code: std::stringstream ss; boost::archive::binary_oarchive oa(ss); //also tried with text_oarchive std::vector<int> myvec; myvec.push_back(12); const std::vector<int>& ref = myvec; //seem to require a reference. oa << ref;
I would think what you've done below should work.
thanks for the realitycheck,
Lucas
c:\Boost\include\boost-1_33\boost\smart_cast.hpp(76) : warning C4541:
'dynamic_cast' used on polymorphic type
'boost::archive::detail::basic_oarchive' with /GR-; unpredictable
behavior may result
c:\Boost\include\boost-1_33\boost\smart_cast.hpp(87) : see
reference to function template instantiation 'T
boost::smart_cast_impl::reference<T>::polymorphic::cross::cast<U>(U &)'
being compiled
with
[
T=boost::archive::binary_oarchive &,
U=boost::archive::detail::basic_oarchive
]
c:\Boost\include\boost-1_33\boost\smart_cast.hpp(135) : see
reference to function template instantiation 'T
boost::smart_cast_impl::reference<T>::polymorphic::cast<U>(U &)' being
compiled
with
[
T=boost::archive::binary_oarchive &,
U=boost::archive::detail::basic_oarchive
]
c:\Boost\include\boost-1_33\boost\smart_cast.hpp(293) : see
reference to function template instantiation 'T
boost::smart_cast_impl::reference<T>::cast<U>(U &)' being compiled
with
[
T=boost::archive::binary_oarchive &,
U=boost::archive::detail::basic_oarchive
]
c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(148) :
see reference to function template instantiation 'T
boost::smart_cast_reference
I presume you are using VC 7.1 IDE. Make sure that the project properties are set for C++ so that Enable Runtime Info is set to "Yes" Robert Ramey Lucas Meijer wrote:
Hey Robert,
first off, thanks for the work on the serialization library, it looks really good so far.
sorry for not including this info in my original post.
what compiler are you running?
Microsoft Visual Studio .NET 2003 boost succesfully built using boost.jam
which version of boost are you running?
1_33_0
do the tests/examples run on your system?
yes.
what do the warnings say?
warning C4541: 'dynamic_cast' used on polymorphic type 'boost::archive::detail::basic_oarchive' with /GR-; unpredictable behavior may result
(see full warning below.)
this is compiling the following code:
std::stringstream ss; boost::archive::binary_oarchive oa(ss); //also tried with text_oarchive std::vector<int> myvec; myvec.push_back(12); const std::vector<int>& ref = myvec; //seem to require a reference. oa << ref;
I would think what you've done below should work.
thanks for the realitycheck,
Lucas
c:\Boost\include\boost-1_33\boost\smart_cast.hpp(76) : warning C4541: 'dynamic_cast' used on polymorphic type 'boost::archive::detail::basic_oarchive' with /GR-; unpredictable behavior may result c:\Boost\include\boost-1_33\boost\smart_cast.hpp(87) : see reference to function template instantiation 'T boost::smart_cast_impl::reference<T>::polymorphic::cross::cast<U>(U &)' being compiled with [ T=boost::archive::binary_oarchive &, U=boost::archive::detail::basic_oarchive ] c:\Boost\include\boost-1_33\boost\smart_cast.hpp(135) : see reference to function template instantiation 'T boost::smart_cast_impl::reference<T>::polymorphic::cast<U>(U &)' being compiled with [ T=boost::archive::binary_oarchive &, U=boost::archive::detail::basic_oarchive ] c:\Boost\include\boost-1_33\boost\smart_cast.hpp(293) : see reference to function template instantiation 'T boost::smart_cast_impl::reference<T>::cast<U>(U &)' being compiled with [ T=boost::archive::binary_oarchive &, U=boost::archive::detail::basic_oarchive ]
c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(148) : see reference to function template instantiation 'T boost::smart_cast_reference
(U &)' being compiled with [ T=boost::archive::binary_oarchive &, Archive=boost::archive::binary_oarchive, U=boost::archive::detail::basic_oarchive ] c:\Boost\include\boost-1_33\boost\serialization\extended_type_info_typeid.hpp(69)
while compiling class-template member function 'void boost::archive::detail::oserializer
::save_object_data(boost::archive::detail::basic_oarchive &,const void *) const' with [ Archive=boost::archive::binary_oarchive, T=std::vector<int> ] c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(263) : see reference to class template instantiation 'boost::archive::detail::oserializer
' being compiled with [ Archive=boost::archive::binary_oarchive, T=std::vector<int> ] c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(262) : while compiling class-template member function 'void boost::archive::detail::save_non_pointer_type
::save_standard::invoke(Archive &,const std::vector<_Ty> &)' with [ Archive=boost::archive::binary_oarchive, T=std::vector<int>, _Ty=int ] c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(272) : see reference to class template instantiation 'boost::archive::detail::save_non_pointer_type
::save_standard' being compiled with [ Archive=boost::archive::binary_oarchive, T=std::vector<int> ] c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(270) : while compiling class-template member function 'void boost::archive::detail::save_non_pointer_type
::save_conditional::invoke(Archive &,const std::vector<_Ty> &)' with [ Archive=boost::archive::binary_oarchive, T=std::vector<int>, _Ty=int ] c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(321) : see reference to class template instantiation 'boost::archive::detail::save_non_pointer_type
::save_conditional' being compiled with [ Archive=boost::archive::binary_oarchive, T=std::vector<int> ] c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(309) : while compiling class-template member function 'void boost::archive::detail::save_non_pointer_type
::invoke(Archive &,const std::vector<_Ty> &)' with [ Archive=boost::archive::binary_oarchive, T=std::vector<int>, _Ty=int ] c:\Boost\include\boost-1_33\boost\archive\detail\oserializer.hpp(535) : see reference to class template instantiation 'boost::archive::detail::save_non_pointer_type
' being compiled with [ Archive=boost::archive::binary_oarchive, T=std::vector<int> ] c:\Boost\include\boost-1_33\boost\archive\basic_binary_oarchive.hpp(70)
see reference to function template instantiation 'void boost::archive::save
(Archive &,T &)' being compiled with [ Archive=boost::archive::binary_oarchive, T=const std::vector<int> ] c:\Boost\include\boost-1_33\boost\archive\binary_oarchive.hpp(47) : see reference to function template instantiation 'void boost::archive::basic_binary_oarchive<Archive>::save_override<T>(T &,int)' being compiled with [ Archive=boost::archive::binary_oarchive, T=const std::vector<int> ]
c:\Boost\include\boost-1_33\boost\archive\detail\interface_oarchive.hpp(85)
see reference to function template instantiation 'void boost::archive::binary_oarchive_impl<Archive>::save_override<T>(T &,int)' being compiled with [ Archive=boost::archive::binary_oarchive, T=const std::vector<int> ]
c:\PetProjects\XtraDevelopment\CastmemberPropertyXtra\source\casset.cpp(480)
see reference to function template instantiation 'Archive &boost::archive::detail::interface_oarchive<Archive>::operator <<
>(T &)' being compiled with [ Archive=boost::archive::binary_oarchive, _Ty=int, T=const std::vector<int> ] Linking...
Robert Ramey wrote:
I presume you are using VC 7.1 IDE. Make sure that the project properties are set for C++ so that Enable Runtime Info is set to "Yes"
!!! You're a star !!! Spent hours and hours trying to figure out what I was doing wrong. Is there a place for boost newbies like me that collects these sort of problems-likely-to-run-into? Thanks, Lucas
You might try the documentation at boost.org documentation serialization library reference implementation notes specific compiler issues VC 7.1 Robert Ramey Lucas Meijer wrote:
Robert Ramey wrote:
I presume you are using VC 7.1 IDE. Make sure that the project properties are set for C++ so that Enable Runtime Info is set to "Yes"
!!! You're a star !!!
Spent hours and hours trying to figure out what I was doing wrong. Is there a place for boost newbies like me that collects these sort of problems-likely-to-run-into?
Thanks,
Lucas
Robert Ramey wrote:
You might try the documentation at boost.org documentation serialization library reference implementation notes specific compiler issues VC 7.1
Hey Robert, Excuse me if I'm looking with my nose, but following this line I've only found the documentation that I've looked at before posting here: boost.org documentation serialization library reference the reference section has no implementation notes as far as I can see. I did find the page you're referring to just now, by googling for "implementation notes boost serialization", but it seems like it is not being linked to from anywhere? I couldn't find it, nor could google. link:http://www.boost.org/libs/serialization/doc/implementation.html returns no results. Bye, Lucas
Hmmm - something must be out of whack somewhere. I click on the link in your email - http://www.boost.org/libs/serialization/doc/implementation.html and it goes right where I expect it to. I don't know what else to say here. Robert Ramey Lucas Meijer wrote:
Robert Ramey wrote:
You might try the documentation at boost.org documentation serialization library reference implementation notes specific compiler issues VC 7.1
Hey Robert,
Excuse me if I'm looking with my nose, but following this line I've only found the documentation that I've looked at before posting here:
boost.org documentation serialization library reference
the reference section has no implementation notes as far as I can see.
I did find the page you're referring to just now, by googling for "implementation notes boost serialization", but it seems like it is not being linked to from anywhere? I couldn't find it, nor could google. link:http://www.boost.org/libs/serialization/doc/implementation.html returns no results.
Bye, Lucas
Robert Ramey wrote:
Hmmm - something must be out of whack somewhere. I click on the link in your email - http://www.boost.org/libs/serialization/doc/implementation.html and it goes right where I expect it to.
I don't know what else to say here.
Sorry if I've been unclear here. What I meant was that I couldn't find that document from any place inside the boost-serialize documentation. I only found it because you emailed me the name of the document. I googled that name, and google found the url for me. If I follow the documentation-path you sent me, I get stuck at "references". when I click the references link, I see no way to progress to the implementation notes. I've now found the implementation notes being linked to from the bottom of the release notes page though, so it turns out I could have found out myself. Maybe linking to the implementation notes somewhere more in sight would be a good idea, alltough I'm not sure how many people run into this. Very glad things work now :) Lucas
On my browser, the serialization documentation shows up with a navigation panel on the left which expands and contracts the sections. This panel uses javascript so I'm guessing you don't have javascript enabled on your browser. My intention has been that things should be navigable even without javascript being enabled. It looks like this intention hasn't been realized. I'll look into it. Robert Ramey Lucas Meijer wrote:
Robert Ramey wrote:
Hmmm - something must be out of whack somewhere. I click on the link in your email - http://www.boost.org/libs/serialization/doc/implementation.html and it goes right where I expect it to.
I don't know what else to say here.
Sorry if I've been unclear here. What I meant was that I couldn't find that document from any place inside the boost-serialize documentation. I only found it because you emailed me the name of the document. I googled that name, and google found the url for me.
If I follow the documentation-path you sent me, I get stuck at "references". when I click the references link, I see no way to progress to the implementation notes.
I've now found the implementation notes being linked to from the bottom of the release notes page though, so it turns out I could have found out myself.
Maybe linking to the implementation notes somewhere more in sight would be a good idea, alltough I'm not sure how many people run into this.
Very glad things work now :)
Lucas
participants (2)
-
Lucas Meijer
-
Robert Ramey