| 1 | /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 |
|---|
| 2 | // pointer_iserializer.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 <cassert> |
|---|
| 12 | |
|---|
| 13 | #include <boost/config.hpp> // msvc 6.0 needs this for warning suppression |
|---|
| 14 | |
|---|
| 15 | #include <boost/archive/detail/basic_serializer_map.hpp> |
|---|
| 16 | #include <boost/archive/detail/archive_pointer_iserializer.hpp> |
|---|
| 17 | |
|---|
| 18 | namespace boost { |
|---|
| 19 | namespace archive { |
|---|
| 20 | namespace detail { |
|---|
| 21 | |
|---|
| 22 | template<class Archive> |
|---|
| 23 | basic_serializer_map * |
|---|
| 24 | iserializer_map(){ |
|---|
| 25 | static bool deleted = false; |
|---|
| 26 | static basic_serializer_map map(deleted); |
|---|
| 27 | return deleted ? NULL : & map; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | template<class Archive> |
|---|
| 31 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
|---|
| 32 | archive_pointer_iserializer<Archive>::archive_pointer_iserializer( |
|---|
| 33 | const boost::serialization::extended_type_info & eti |
|---|
| 34 | ) : |
|---|
| 35 | basic_pointer_iserializer(eti) |
|---|
| 36 | { |
|---|
| 37 | basic_serializer_map *mp = iserializer_map<Archive>(); |
|---|
| 38 | assert(NULL != mp); |
|---|
| 39 | mp->insert(this); |
|---|
| 40 | } |
|---|
| 41 | |
|---|
| 42 | template<class Archive> |
|---|
| 43 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(const basic_pointer_iserializer *) |
|---|
| 44 | archive_pointer_iserializer<Archive>::find( |
|---|
| 45 | const boost::serialization::extended_type_info & eti |
|---|
| 46 | ){ |
|---|
| 47 | basic_serializer_map *mp = iserializer_map<Archive>(); |
|---|
| 48 | assert(NULL != mp); |
|---|
| 49 | return static_cast<const basic_pointer_iserializer *>(mp->tfind(eti)); |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | template<class Archive> |
|---|
| 53 | BOOST_ARCHIVE_OR_WARCHIVE_DECL(BOOST_PP_EMPTY()) |
|---|
| 54 | archive_pointer_iserializer<Archive>::~archive_pointer_iserializer(){ |
|---|
| 55 | // note: we need to check that the map still exists as we can't depend |
|---|
| 56 | // on static variables being constructed in a specific sequence |
|---|
| 57 | basic_serializer_map *mp = iserializer_map<Archive>(); |
|---|
| 58 | if(NULL == mp) |
|---|
| 59 | return; |
|---|
| 60 | mp->erase(this); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | } // namespace detail |
|---|
| 64 | } // namespace archive |
|---|
| 65 | } // namespace boost |
|---|