[857] | 1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
|
---|
| 2 | // archive_pointer_oserializer.ipp:
|
---|
| 3 |
|
---|
| 4 | // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
|
---|
| 5 | // Use, modification and distribution is subject to the Boost Software
|
---|
| 6 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
---|
| 7 | // http://www.boost.org/LICENSE_1_0.txt)
|
---|
| 8 |
|
---|
| 9 | // See http://www.boost.org for updates, documentation, and revision history.
|
---|
| 10 |
|
---|
| 11 | #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression
|
---|
| 12 |
|
---|
| 13 | #include <boost/archive/detail/archive_pointer_oserializer.hpp>
|
---|
| 14 | #include <boost/archive/detail/basic_serializer_map.hpp>
|
---|
| 15 |
|
---|
| 16 | namespace boost {
|
---|
| 17 | namespace archive {
|
---|
| 18 | namespace detail {
|
---|
| 19 |
|
---|
| 20 | template<class Archive>
|
---|
| 21 | basic_serializer_map *
|
---|
| 22 | oserializer_map(){
|
---|
| 23 | static bool deleted = false;
|
---|
| 24 | static basic_serializer_map map(deleted);
|
---|
| 25 | return deleted ? NULL : & map;
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | template<class Archive>
|
---|
| 29 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
|
---|
| 30 | archive_pointer_oserializer<Archive>::archive_pointer_oserializer(
|
---|
| 31 | const boost::serialization::extended_type_info & eti
|
---|
| 32 | ) :
|
---|
| 33 | basic_pointer_oserializer(eti)
|
---|
| 34 | {
|
---|
| 35 | basic_serializer_map *mp = oserializer_map<Archive>();
|
---|
| 36 | assert(NULL != mp);
|
---|
| 37 | mp->insert(this);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | template<class Archive>
|
---|
| 41 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(const basic_pointer_oserializer *)
|
---|
| 42 | archive_pointer_oserializer<Archive>::find(
|
---|
| 43 | const boost::serialization::extended_type_info & eti
|
---|
| 44 | ){
|
---|
| 45 | basic_serializer_map *mp = oserializer_map<Archive>();
|
---|
| 46 | assert(NULL != mp);
|
---|
| 47 | return static_cast<const basic_pointer_oserializer *>(mp->tfind(eti));
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | template<class Archive>
|
---|
| 51 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY())
|
---|
| 52 | archive_pointer_oserializer<Archive>::~archive_pointer_oserializer(){
|
---|
| 53 | // note: we need to check that the map still exists as we can't depend
|
---|
| 54 | // on static variables being constructed in a specific sequence
|
---|
| 55 | basic_serializer_map *mp = oserializer_map<Archive>();
|
---|
| 56 | if(NULL == mp)
|
---|
| 57 | return;
|
---|
| 58 | mp->erase(this);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | } // namespace detail
|
---|
| 62 | } // namespace archive
|
---|
| 63 | } // namespace boost
|
---|