serialize - std::stack
I have a structure as:
stateStack a;
typedef std::stack < state*, std_deque
On Thu, 01 Dec 2005 17:38:45 -0200, sui tam
I have a structure as: stateStack a; typedef std::stack < state*, std_deque
> stateStack How can I serialize this structure? I cannot find any std::stack in the serialization header file.
I don't think it's psossible, because std::stack doesn't expose enough information. Either use deque/vector directly or inherit from std::stack to get access to the inner deque. Regards, Bruno
On Thu, 01 Dec 2005 18:16:21 -0200, Bruno Martínez wrote:
I don't think it's psossible, because std::stack doesn't expose enough information. Either use deque/vector directly or inherit from std::stack to get access to the inner deque.
Regards, Bruno
Inheriting from the std::stack is horrible idea. It is not portable. Not to mention that stack lacks a virtual destructor. Nathan Moore
On Fri, 02 Dec 2005 16:09:53 -0200, Nathan E. Moore
On Thu, 01 Dec 2005 18:16:21 -0200, Bruno Martínez wrote:
I don't think it's psossible, because std::stack doesn't expose enough information. Either use deque/vector directly or inherit from std::stack to get access to the inner deque.
Inheriting from the std::stack is horrible idea. It is not portable. Not to mention that stack lacks a virtual destructor.
You are right about the destructor. One has to be carefull. I think it's portable. The standard requieres the container to be protected for a reason. Bruno
"Nathan E. Moore"
On Thu, 01 Dec 2005 18:16:21 -0200, Bruno Martínez wrote:
I don't think it's psossible, because std::stack doesn't expose enough information. Either use deque/vector directly or inherit from std::stack to get access to the inner deque.
Regards, Bruno
Inheriting from the std::stack is horrible idea. It is not portable.
?? How so?
Not to mention that stack lacks a virtual destructor.
So use private inheritance if you're worried. -- Dave Abrahams Boost Consulting www.boost-consulting.com
Mostly because I had forgotten that stack provides a protected member to access the base structure directly. I was assuming that you would have to resort to tricks like '#define private public'. The only real problem is I shot off my mouth before I had checked. However my point about the lack of a virtual destructor is still valid, certainly not a deal breaker though. Nathan Moore
"sui tam"
Hi,
On 12/1/05, Robert Ramey
[snip]
There isn't, You'll have to make yourself. When you do upload it to the vault
Is this a reasonable implementation? I didnt knew how the better way to call the serialization of something inside the serialization code, so I called the serialize free function to serialize the stack internal container. Hope it works for types other than the STL containers.
Robert Ramey
-- Felipe Magno de Almeida Developer from synergy and Computer Science student from State University of Campinas(UNICAMP). Unicamp: http://www.ic.unicamp.br Synergy: http://www.synergy.com.br "There is no dark side of the moon really. Matter of fact it's all dark."
Looks like it might work. Make a test and upload the whole thing to the vault Robert Ramey Felipe Magno de Almeida wrote:
Hi,
On 12/1/05, Robert Ramey
wrote: [snip]
There isn't, You'll have to make yourself. When you do upload it to the vault
Is this a reasonable implementation? I didnt knew how the better way to call the serialization of something inside the serialization code, so I called the serialize free function to serialize the stack internal container. Hope it works for types other than the STL containers.
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 12/6/05, Robert Ramey
Looks like it might work. Make a test and upload the whole thing to the vault
Could you point me to some information on how to make a test?
Robert Ramey
Thanks, -- Felipe Magno de Almeida Developer from synergy and Computer Science student from State University of Campinas(UNICAMP). Unicamp: http://www.ic.unicamp.br Synergy: http://www.synergy.com.br "There is no dark side of the moon really. Matter of fact it's all dark."
Look at the libs/serialization/test directory - you'll find lots of tests there. Robert Ramey Felipe Magno de Almeida wrote:
On 12/6/05, Robert Ramey
wrote: Looks like it might work. Make a test and upload the whole thing to the vault
Could you point me to some information on how to make a test?
Robert Ramey
Thanks,
Shouldn't the get_aux::get method be explicitally inlined? This should make the M$ pragma unnecessary. Felipe Magno de Almeida wrote:
Hi,
On 12/1/05, Robert Ramey
wrote: [snip]
There isn't, You'll have to make yourself. When you do upload it to the vault
Is this a reasonable implementation? I didnt knew how the better way to call the serialization of something inside the serialization code, so I called the serialize free function to serialize the stack internal container. Hope it works for types other than the STL containers.
Robert Ramey
-- Felipe Magno de Almeida Developer from synergy and Computer Science student from State University of Campinas(UNICAMP). Unicamp: http://www.ic.unicamp.br Synergy: http://www.synergy.com.br "There is no dark side of the moon really. Matter of fact it's all dark."
------------------------------------------------------------------------
#ifndef BOOST_SERIALIZATION_STACK_HPP #define BOOST_SERIALIZATION_STACK_HPP
// MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // stack.hpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <deque>
#include
#include
#include #include <stack>
// function specializations must be defined in the appropriate // namespace - boost::serialization #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) #define STD _STLP_STD #else #define STD std #endif
namespace boost { namespace serialization { namespace stack_detail {
// needed to have access to the c protected member template
struct get_aux : STD::stack { static C& get(STD::stack& s) { return s.c; } }; // for template argument detection template
C& get(STD::stack& s) { return get_aux::get(s); } }
// serialize the internal's stack container template
inline void serialize( Archive & ar, STD::stack &t, const unsigned int file_version ){ serialize(ar, stack_detail::get(t), file_version); } } // namespace serialization } // namespace boost
#include
BOOST_SERIALIZATION_COLLECTION_TRAITS(STD::stack)
#undef STD
#endif // BOOST_SERIALIZATION_DEQUE_HPP
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Shouldn't the get_aux::get method be explicitally inlined? This should make the M$ pragma unecessary. Felipe Magno de Almeida wrote:
Hi,
On 12/1/05, Robert Ramey
wrote: [snip]
There isn't, You'll have to make yourself. When you do upload it to the vault
Is this a reasonable implementation? I didnt knew how the better way to call the serialization of something inside the serialization code, so I called the serialize free function to serialize the stack internal container. Hope it works for types other than the STL containers.
Robert Ramey
-- Felipe Magno de Almeida Developer from synergy and Computer Science student from State University of Campinas(UNICAMP). Unicamp: http://www.ic.unicamp.br Synergy: http://www.synergy.com.br "There is no dark side of the moon really. Matter of fact it's all dark."
------------------------------------------------------------------------
#ifndef BOOST_SERIALIZATION_STACK_HPP #define BOOST_SERIALIZATION_STACK_HPP
// MS compatible compilers support #pragma once #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma once #endif
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // stack.hpp
// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . // Use, modification and distribution is subject to the Boost Software // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
#include <deque>
#include
#include
#include #include <stack>
// function specializations must be defined in the appropriate // namespace - boost::serialization #if defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION) #define STD _STLP_STD #else #define STD std #endif
namespace boost { namespace serialization { namespace stack_detail {
// needed to have access to the c protected member template
struct get_aux : STD::stack { static C& get(STD::stack& s) { return s.c; } }; // for template argument detection template
C& get(STD::stack& s) { return get_aux::get(s); } }
// serialize the internal's stack container template
inline void serialize( Archive & ar, STD::stack &t, const unsigned int file_version ){ serialize(ar, stack_detail::get(t), file_version); } } // namespace serialization } // namespace boost
#include
BOOST_SERIALIZATION_COLLECTION_TRAITS(STD::stack)
#undef STD
#endif // BOOST_SERIALIZATION_DEQUE_HPP
------------------------------------------------------------------------
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On 12/6/05, Jeffrey Holle
Shouldn't the get_aux::get method be explicitally inlined? This should make the M$ pragma unecessary.
Probably, inlining is good, but I dont understand how it would make the MS pragma unnecessary. The #pragma once (is this you're talking about?) works like the macro guards of the header. The difference is that it makes it faster for the preprocessor, since it doesnt need to reopen the file to see that nothing will be added to the preprocessed file. Or are you saying that the header guards arent needed too? Thanks, -- Felipe Magno de Almeida Developer from synergy and Computer Science student from State University of Campinas(UNICAMP). Unicamp: http://www.ic.unicamp.br Synergy: http://www.synergy.com.br "There is no dark side of the moon really. Matter of fact it's all dark."
Sorry, I had to look at it. And being a booster - I couldn't leave well enough alone. So I made your version a little shorter - maybe too short for certain compilers. Robert Ramey Felipe Magno de Almeida wrote:
Hi,
On 12/1/05, Robert Ramey
wrote: [snip]
There isn't, You'll have to make yourself. When you do upload it to the vault
Is this a reasonable implementation? I didnt knew how the better way to call the serialization of something inside the serialization code, so I called the serialize free function to serialize the stack internal container. Hope it works for types other than the STL containers.
Robert Ramey
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
begin 666 stack.hpp
M(VEF;F1E9B @0D]/4U1?4T5224%,25I!5$E/3E]35$%#2U](4% -"B-D969I
M;F4@0D]/4U1?4T5224%,25I!5$E/3E]35$%#2U](4% -"@T*+R\@35,@8V]M
M<&%T:6)L92!C;VUP:6QE
participants (7)
-
Bruno Martínez
-
David Abrahams
-
Felipe Magno de Almeida
-
Jeffrey Holle
-
Nathan E. Moore
-
Robert Ramey
-
sui tam