[Boost Users] Serialization: problems when splitting serialize into load / save
Hello out there !
I have an urgent problem concerning boost::serialize.
I have split the serialize operation into save / load as described
in the tutorial:
===================================================
template<class Archive>
void save( Archive &ar, unsigned int version) {
m_offlineMode = true;
// we cannot load more when offline --> always cachedAll
bool oldCachedAll = m_CachedAll;
m_CachedAll = true;
ar & m_CachedAll;
ar & m_offlineMode;
// do not serialize the lock -- use the default constructor.
// we assume that no iterators that lock the cache do exist
when serializing.
// ar & m_Lock;
ar & m_LookupId;
ar & m_LookupName;
ar & m_SequenceNumber;
//reset old state for the case we want to continue working
m_CachedAll = oldCachedAll;
m_offlineMode = false;
}
template<class Archive>
void load( Archive &ar, unsigned int version) {
ar & m_CachedAll;
ar & m_offlineMode;
// do not serialize the lock -- use the default constructor.
// we assume that no iterators that lock the cache do exist
when serializing.
// ar & m_Lock;
ar & m_LookupId;
ar & m_LookupName;
ar & m_SequenceNumber;
//reset old state for the case we want to continue working
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
===============================================================
The class I serialize is part of a deep class hierarchy that I want to
serialize as a whole.
With the standard serialize() it seems to work, but now the compiler
complains ( when I
want to perform the actual serialization):
error C2662: 'void
jedox::palo::AbstractCache
Hello Oliver,
Your save method has to be const.
Regards
Oliver
________________________________
Von: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] Im Auftrag von Oliver Kania
Gesendet: Donnerstag, 8. November 2007 15:16
An: boost-users
Betreff: [Boost-users] [Boost Users] Serialization: problems when
splittingserialize into load / save
Hello out there !
I have an urgent problem concerning boost::serialize.
I have split the serialize operation into save / load as described
in the tutorial:
===================================================
template<class Archive>
void save( Archive &ar, unsigned int version) {
m_offlineMode = true;
// we cannot load more when offline --> always cachedAll
bool oldCachedAll = m_CachedAll;
m_CachedAll = true;
ar & m_CachedAll;
ar & m_offlineMode;
// do not serialize the lock -- use the default constructor.
// we assume that no iterators that lock the cache do exist
when serializing.
// ar & m_Lock;
ar & m_LookupId;
ar & m_LookupName;
ar & m_SequenceNumber;
//reset old state for the case we want to continue working
m_CachedAll = oldCachedAll;
m_offlineMode = false;
}
template<class Archive>
void load( Archive &ar, unsigned int version) {
ar & m_CachedAll;
ar & m_offlineMode;
// do not serialize the lock -- use the default constructor.
// we assume that no iterators that lock the cache do exist
when serializing.
// ar & m_Lock;
ar & m_LookupId;
ar & m_LookupName;
ar & m_SequenceNumber;
//reset old state for the case we want to continue working
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
===============================================================
The class I serialize is part of a deep class hierarchy that I want to
serialize as a whole.
With the standard serialize() it seems to work, but now the compiler complains
( when I
want to perform the actual serialization):
error C2662: 'void
jedox::palo::AbstractCache
Hello and thx
I guess that means I cannot change class state in my save method.
That is what I need ! Is there any way around it ?
regards, Oliver
On Nov 8, 2007 3:47 PM, Oliver Mutz
Hello Oliver,
Your save method has to be const.
Regards
Oliver
________________________________
Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] Im Auftrag von Oliver Kania Gesendet: Donnerstag, 8. November 2007 15:16 An: boost-users Betreff: [Boost-users] [Boost Users] Serialization: problems when splittingserialize into load / save
Hello out there ! I have an urgent problem concerning boost::serialize. I have split the serialize operation into save / load as described in the tutorial: =================================================== template<class Archive> void save( Archive &ar, unsigned int version) { m_offlineMode = true; // we cannot load more when offline --> always cachedAll bool oldCachedAll = m_CachedAll; m_CachedAll = true; ar & m_CachedAll; ar & m_offlineMode; // do not serialize the lock -- use the default constructor. // we assume that no iterators that lock the cache do exist when serializing. // ar & m_Lock; ar & m_LookupId; ar & m_LookupName; ar & m_SequenceNumber; //reset old state for the case we want to continue working m_CachedAll = oldCachedAll; m_offlineMode = false; }
template<class Archive> void load( Archive &ar, unsigned int version) {
ar & m_CachedAll; ar & m_offlineMode; // do not serialize the lock -- use the default constructor. // we assume that no iterators that lock the cache do exist when serializing. // ar & m_Lock; ar & m_LookupId; ar & m_LookupName; ar & m_SequenceNumber; //reset old state for the case we want to continue working } BOOST_SERIALIZATION_SPLIT_MEMBER() ===============================================================
The class I serialize is part of a deep class hierarchy that I want to serialize as a whole. With the standard serialize() it seems to work, but now the compiler complains ( when I want to perform the actual serialization):
error C2662: 'void jedox::palo::AbstractCache
::save<Archive>(Archive &,unsigned int)' : cannot convert 'this' pointer from 'const jedox::palo::AbstractCache ' to 'jedox::palo::AbstractCache &' AbstractCache is the class containing the above load / save operations
kind regards, Oliver
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hi Oliver, There is always the mutable keyword. Being able to use it would probably depend on how many members in your class need to be changed when you save. For example, it would seem awkward to have to mark every member as mutable. -Dave On Thu, 2007-11-08 at 16:02 +0100, Oliver Kania wrote:
Hello and thx I guess that means I cannot change class state in my save method. That is what I need ! Is there any way around it ?
regards, Oliver
On Nov 8, 2007 3:47 PM, Oliver Mutz < omutz@isdcad.de> wrote: Hello Oliver,
Your save method has to be const.
Regards
Oliver
________________________________
Von: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] Im Auftrag von Oliver Kania Gesendet: Donnerstag, 8. November 2007 15:16 An: boost-users Betreff: [Boost-users] [Boost Users] Serialization: problems when splittingserialize into load / save
Hello out there ! I have an urgent problem concerning boost::serialize. I have split the serialize operation into save / load as described in the tutorial: =================================================== template<class Archive> void save( Archive &ar, unsigned int version) { m_offlineMode = true; // we cannot load more when offline --> always cachedAll bool oldCachedAll = m_CachedAll; m_CachedAll = true; ar & m_CachedAll; ar & m_offlineMode; // do not serialize the lock -- use the default constructor. // we assume that no iterators that lock the cache do exist when serializing. // ar & m_Lock; ar & m_LookupId; ar & m_LookupName; ar & m_SequenceNumber; //reset old state for the case we want to continue working m_CachedAll = oldCachedAll; m_offlineMode = false; }
template<class Archive> void load( Archive &ar, unsigned int version) {
ar & m_CachedAll; ar & m_offlineMode; // do not serialize the lock -- use the default constructor. // we assume that no iterators that lock the cache do exist when serializing. // ar & m_Lock; ar & m_LookupId; ar & m_LookupName; ar & m_SequenceNumber; //reset old state for the case we want to continue working } BOOST_SERIALIZATION_SPLIT_MEMBER() ===============================================================
The class I serialize is part of a deep class hierarchy that I want to serialize as a whole. With the standard serialize() it seems to work, but now the compiler complains ( when I want to perform the actual serialization):
error C2662: 'void jedox::palo::AbstractCache
::save<Archive>(Archive &,unsigned int)' : cannot convert 'this' pointer from 'const jedox::palo::AbstractCache ' to 'jedox::palo::AbstractCache &' AbstractCache is the class containing the above load / save operations
kind regards, Oliver
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
The following would work. However as you already know, the state of the
class when loaded is not going to be the same as the state of the clas when
it was saved. This suggests that one might want to step back and
consider what he really wants to do.
template<class Archive>
// do not serialize the lock -- use the default constructor.
// we assume that no iterators that lock the cache do exist
when serializing.
// ar & m_Lock;
ar & m_LookupId;
ar & m_LookupName;
ar & m_SequenceNumber;
}
template<class Archive>
void load( Archive &ar, unsigned int version) {
m_CachedAll = true;
m_offlineMode = true;
// do not serialize the lock -- use the default constructor.
// we assume that no iterators that lock the cache do exist
when serializing.
// ar & m_Lock;
ar & m_LookupId;
ar & m_LookupName;
ar & m_SequenceNumber;
//reset old state for the case we want to continue working
"Oliver Kania"
Oliver Kania wrote:
Hello and thx I guess that means I cannot change class state in my save method. That is what I need ! Is there any way around it ?
... Please don't top post!
=================================================== template<class Archive>
void save( Archive &ar, unsigned int version) const { replace these:
m_offlineMode = true; // we cannot load more when offline --> always cachedAll bool oldCachedAll = m_CachedAll; m_CachedAll = true; ar & m_CachedAll; ar & m_offlineMode;
with: ar << true; ar << true;
// do not serialize the lock -- use the default constructor. // we assume that no iterators that lock the cache do exist when serializing. // ar & m_Lock; ar & m_LookupId; ar & m_LookupName; ar & m_SequenceNumber; //reset old state for the case we want to continue working
remove these:
m_CachedAll = oldCachedAll; m_offlineMode = false; }
then there's no need for mutable nor const_cast. Jeff Flinn
Oliver Kania wrote:
Hello out there ! I have an urgent problem concerning boost::serialize. I have split the serialize operation into save / load as described in the tutorial: =================================================== template<class Archive> void save( Archive &ar, unsigned int version) {
...
error C2662: 'void jedox::palo::AbstractCache
::save<Archive>(Archive &,unsigned int)' : cannot convert 'this' pointer from 'const jedox::palo::AbstractCache ' to 'jedox::palo::AbstractCache &'
'const' in the error message is saying that save should be a const member function with the signature: template<class Archive> void save( Archive &ar, unsigned int version) const { Jeff Flinn
participants (6)
-
David Daeschler
-
Jeff Flinn
-
Nat Goodspeed
-
Oliver Kania
-
Oliver Mutz
-
Robert Ramey