1 #ifndef BOOST_ARCHIVE_DETAIL_HELPER_COLLECTION_HPP
2 #define BOOST_ARCHIVE_DETAIL_HELPER_COLLECTION_HPP
4 // MS compatible compilers support #pragma once
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
10 // helper_collection.hpp: archive support for run-time helpers
12 // (C) Copyright 2002-2008 Robert Ramey and Joaquin M Lopez Munoz
13 // Use, modification and distribution is subject to the Boost Software
14 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // See http://www.boost.org for updates, documentation, and revision history.
19 #include <cstddef> // NULL
25 #include <boost/config.hpp>
27 #include <boost/smart_ptr/shared_ptr.hpp>
28 #include <boost/smart_ptr/make_shared.hpp>
35 class helper_collection
37 helper_collection(const helper_collection&); // non-copyable
38 helper_collection& operator = (const helper_collection&); // non-copyable
40 // note: we dont' actually "share" the function object pointer
41 // we only use shared_ptr to make sure that it get's deleted
45 boost::shared_ptr<void>
48 boost::shared_ptr<void> make_helper_ptr(){
49 // use boost::shared_ptr rather than std::shared_ptr to maintain
50 // c++03 compatibility
51 return boost::make_shared<T>();
54 typedef std::vector<helper_value_type> collection;
55 collection m_collection;
58 BOOST_DELETED_FUNCTION(predicate & operator=(const predicate & rhs))
60 const void * const m_ti;
61 bool operator()(helper_value_type const &rhs) const {
62 return m_ti == rhs.first;
64 predicate(const void * ti) :
70 ~helper_collection(){}
72 template<typename Helper>
73 Helper& find_helper(void * const id = 0) {
74 collection::const_iterator it =
82 if(it == m_collection.end()){
83 m_collection.push_back(
84 std::make_pair(id, make_helper_ptr<Helper>())
86 rval = m_collection.back().second.get();
89 rval = it->second.get();
91 return *static_cast<Helper *>(rval);
96 } // namespace serialization
99 #endif // BOOST_ARCHIVE_DETAIL_HELPER_COLLECTION_HPP