File indexing completed on 2025-01-18 09:28:27
0001 #ifndef BOOST_ARCHIVE_DETAIL_HELPER_COLLECTION_HPP
0002 #define BOOST_ARCHIVE_DETAIL_HELPER_COLLECTION_HPP
0003
0004
0005 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
0006 # pragma once
0007 #endif
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <cstddef> // NULL
0020 #include <vector>
0021 #include <utility>
0022 #include <memory>
0023 #include <algorithm>
0024
0025 #include <boost/config.hpp>
0026
0027 #include <boost/smart_ptr/shared_ptr.hpp>
0028 #include <boost/smart_ptr/make_shared.hpp>
0029
0030 namespace boost {
0031
0032 namespace archive {
0033 namespace detail {
0034
0035 class helper_collection
0036 {
0037 helper_collection(const helper_collection&);
0038 helper_collection& operator = (const helper_collection&);
0039
0040
0041
0042
0043 typedef std::pair<
0044 const void *,
0045 boost::shared_ptr<void>
0046 > helper_value_type;
0047 template<class T>
0048 boost::shared_ptr<void> make_helper_ptr(){
0049
0050
0051 return boost::make_shared<T>();
0052 }
0053
0054 typedef std::vector<helper_value_type> collection;
0055 collection m_collection;
0056
0057 struct predicate {
0058 BOOST_DEFAULTED_FUNCTION(predicate(const predicate& rhs), : m_ti(rhs.m_ti) {})
0059 BOOST_DELETED_FUNCTION(predicate & operator=(const predicate & rhs))
0060 public:
0061 const void * const m_ti;
0062 bool operator()(helper_value_type const &rhs){
0063 return m_ti == rhs.first;
0064 }
0065 predicate(const void * ti) :
0066 m_ti(ti)
0067 {}
0068 };
0069 protected:
0070 helper_collection(){}
0071 ~helper_collection(){}
0072 public:
0073 template<typename Helper>
0074 Helper& find_helper(void * const id = 0) {
0075 collection::const_iterator it =
0076 std::find_if(
0077 m_collection.begin(),
0078 m_collection.end(),
0079 predicate(id)
0080 );
0081
0082 void * rval = 0;
0083 if(it == m_collection.end()){
0084 m_collection.push_back(
0085 std::make_pair(id, make_helper_ptr<Helper>())
0086 );
0087 rval = m_collection.back().second.get();
0088 }
0089 else{
0090 rval = it->second.get();
0091 }
0092 return *static_cast<Helper *>(rval);
0093 }
0094 };
0095
0096 }
0097 }
0098 }
0099
0100 #endif