Jump to content
  • Advertisement
Sign in to follow this  
david6327

Boost Serialization Compile Error

This topic is 3876 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I'm sort of new to the Boost Serialization Class and also to C++ itself and I ask for some help from some of the professionals on gamedev. I've already tried to search this information up on yahoo and google but none of them seemed to help. Please help me! Basically, I made my own class named Algorithm. Part of it looks like this
void Algorithms::SaveBinary(std::string filePath, std::map<std::string,std::string> *mapData){
		for ( loop = mapData->begin(); loop != mapData->end(); loop++ ){
			(*mapData)[loop->first]=XOR_String(loop->second,'a') ;
		}

		std::ofstream ofs( filePath.c_str() );
		{
			boost::archive::text_oarchive oa(ofs);
			oa << *mapData;
		}

		for ( loop = mapData->begin(); loop != mapData->end(); loop++ ){
			(*mapData)[loop->first]=XOR_String(loop->second,'a') ;
		}
}




the line that says oa << *mapData; is cause of error. This is what the error code looks like:
Quote:
/usr/local/include/boost/archive/detail/oserializer.hpp: In function `void boost::archive::save(Archive&, T&) [with Archive = boost::archive::text_oarchive, T = std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >]': /usr/local/include/boost/archive/basic_text_oarchive.hpp:78: instantiated from `void boost::archive::basic_text_oarchive<Archive>::save_override(T&, int) [with T = std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >, Archive = boost::archive::text_oarchive]' /usr/local/include/boost/archive/detail/interface_oarchive.hpp:78: instantiated from `Archive& boost::archive::detail::interface_oarchive<Archive>::operator<<(T&) [with T = std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >, Archive = boost::archive::text_oarchive]' Algorithms.cpp:143: instantiated from here /usr/local/include/boost/archive/detail/oserializer.hpp:567: error: incomplete type `boost::STATIC_ASSERTION_FAILURE< false>' used in nested name specifier /usr/local/include/boost/archive/detail/oserializer.hpp:567: error: size of array has non-integral type `<type error>' *** Error code 1
[Edited by - david6327 on February 7, 2008 9:41:58 AM]

Share this post


Link to post
Share on other sites
Advertisement
Note:
Now, this code used to be compiled under these circumstances
FreeBSD 5.4
GCC 3.4.2
Boost v1.32

However, this code can't be compiled under these circumstances
I'm running on FreeBSD 5.5
GCC 3.4.2
Boost v1.33.1

Any Suggestions would be appreciated!!

Share this post


Link to post
Share on other sites
oh boy.... then does that mean that I need to change all "std::map<std::string,std::string> *mapData" 's into a const?

This project that I'm doing is over 1Mb just on the source code. It's practically impossible to fix all of them.

Is there possibly a quick fix?

Share this post


Link to post
Share on other sites
As I noted in that other thread I linked to, I haven't gotten boost::serialization to work with anything but extremely trivial examples. However, based on the "rationale" document I linked to, I think using a const_cast is an acceptable way around this issue. If you want help from people who know a lot more about boost than me, look at the boost-users mailing list. There is a lot of discussion about boost::serialization there and the library author, Robert Ramey, gets involved in lots of those discussions.

Share this post


Link to post
Share on other sites
Urm, I've read the documentation of the const_cast function, but it's way too difficult. I tried these but they still fail to compile:


oa << const_cast< std::map<std::string,std::string>& >(mapData);
oa << const_cast< std::map<std::string,std::string>* >(mapData);
oa << const_cast< std::map<std::string,std::string> >(&mapData);
oa << const_cast< std::map<std::string,std::string> >(*mapData);



They all don't work!
I'm sooo confused...

Share this post


Link to post
Share on other sites
const_cast *removes* the const-ness from a variable, it does not *add* it like you need to do.

Just change your function to take a const map * instead of a map * (you should have been doing this anyways, since it's a save function).


void Algorithms::SaveBinary(const std::string &filePath, const std::map<std::string,std::string> *mapData){
for ( loop = mapData->begin(); loop != mapData->end(); loop++ ){
(*mapData)[loop->first]=XOR_String(loop->second,'a') ;
}

std::ofstream ofs( filePath.c_str() );
{
boost::archive::text_oarchive oa(ofs);
oa << *mapData;
}

for ( loop = mapData->begin(); loop != mapData->end(); loop++ ){
(*mapData)[loop->first]=XOR_String(loop->second,'a') ;
}
}


Share this post


Link to post
Share on other sites
Saving data to disk logically does not (should not) change the data. Boost serialization routines require you to make the guarantee that you won't do any such thing. This guarantee is absent from your function as it stands.

Const correctness.

Share this post


Link to post
Share on other sites
Thanks for the replies. Now, I've taken mfawcett's recommendation and changed the source code to that. Does this require me to change everything else accordingly? Because the source file is huge, over 1Mb.... (it's a program that I used to work on just for fun but just recently decided to engage in it again) I'm really not confident if I can do this...

Just as a note, I used to know the differences between pointers, references, and constants a few years back, but it's been years since I've last programmed and forgot a lot of information and need some brushing up.

Thanks a million! Oh, and the const correctness link is great! but I'm having a difficult time applying that to my currently situation. And I understand that this is related to const correctness as well. I know I should read through the const correctness manual, but a little bit more of a hint will make my day! Boy, my brain's feeling a bit dusty.

Share this post


Link to post
Share on other sites
And another thing:
let's say I did change it to this:

void Algorithms::SaveBinary(const std::string &filePath, const std::map<std::string,std::string> *mapData){


but still, as you can see here, mapData is being modified...

for ( loop = mapData->begin(); loop != mapData->end(); loop++ ){
(*mapData)[loop->first]=XOR_String(loop->second,'a') ;
}


Now, according to the const correctness that I have just read, since my *mapData is a pointer, I can still modify mapData just not *mapData. If this is true, then I guess I should be able to compile. Changing all the functions accordingly will take me hours....

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!