Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/archive/detail/helper_collection.hpp @ 102:f46d142149f5
Whoops, finish that update
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:13:41 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
101:c530137014c0 | 102:f46d142149f5 |
---|---|
1 #ifndef BOOST_ARCHIVE_DETAIL_HELPER_COLLECTION_HPP | |
2 #define BOOST_ARCHIVE_DETAIL_HELPER_COLLECTION_HPP | |
3 | |
4 // MS compatible compilers support #pragma once | |
5 #if defined(_MSC_VER) && (_MSC_VER >= 1020) | |
6 # pragma once | |
7 #endif | |
8 | |
9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 | |
10 // helper_collection.hpp: archive support for run-time helpers | |
11 | |
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) | |
16 | |
17 // See http://www.boost.org for updates, documentation, and revision history. | |
18 | |
19 #include <cstddef> // NULL | |
20 #include <vector> | |
21 #include <utility> | |
22 #include <memory> | |
23 #include <algorithm> | |
24 | |
25 #include <boost/config.hpp> | |
26 | |
27 #include <boost/smart_ptr/shared_ptr.hpp> | |
28 #include <boost/smart_ptr/make_shared.hpp> | |
29 | |
30 namespace boost { | |
31 | |
32 namespace archive { | |
33 namespace detail { | |
34 | |
35 class helper_collection | |
36 { | |
37 helper_collection(const helper_collection&); // non-copyable | |
38 helper_collection& operator = (const helper_collection&); // non-copyable | |
39 | |
40 // note: we dont' actually "share" the function object pointer | |
41 // we only use shared_ptr to make sure that it get's deleted | |
42 | |
43 typedef std::pair< | |
44 const void *, | |
45 boost::shared_ptr<void> | |
46 > helper_value_type; | |
47 template<class T> | |
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>(); | |
52 } | |
53 | |
54 typedef std::vector<helper_value_type> collection; | |
55 collection m_collection; | |
56 | |
57 struct predicate { | |
58 const void * const m_ti; | |
59 bool operator()(helper_value_type const &rhs) const { | |
60 return m_ti == rhs.first; | |
61 } | |
62 predicate & operator=(const void * ti); // to suppress warning | |
63 predicate(const void * ti) : | |
64 m_ti(ti) | |
65 {} | |
66 }; | |
67 protected: | |
68 helper_collection(){} | |
69 ~helper_collection(){} | |
70 public: | |
71 template<typename Helper> | |
72 Helper& get_helper(void * const id = 0) { | |
73 collection::const_iterator it = | |
74 std::find_if( | |
75 m_collection.begin(), | |
76 m_collection.end(), | |
77 predicate(id) | |
78 ); | |
79 | |
80 void * rval = 0; | |
81 if(it == m_collection.end()){ | |
82 m_collection.push_back( | |
83 std::make_pair(id, make_helper_ptr<Helper>()) | |
84 ); | |
85 rval = m_collection.back().second.get(); | |
86 } | |
87 else{ | |
88 rval = it->second.get(); | |
89 } | |
90 return *static_cast<Helper *>(rval); | |
91 } | |
92 }; | |
93 | |
94 } // namespace detail | |
95 } // namespace serialization | |
96 } // namespace boost | |
97 | |
98 #endif // BOOST_ARCHIVE_DETAIL_HELPER_COLLECTION_HPP |