]>
Commit | Line | Data |
---|---|---|
1 | // | |
2 | // Boost.Pointer Container | |
3 | // | |
4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and | |
5 | // distribution is subject to the Boost Software License, Version | |
6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | // | |
9 | // For more information, see http://www.boost.org/libs/ptr_container/ | |
10 | // | |
11 | ||
12 | #ifndef BOOST_PTR_CONTAINER_PTR_MAP_HPP | |
13 | #define BOOST_PTR_CONTAINER_PTR_MAP_HPP | |
14 | ||
15 | #if defined(_MSC_VER) && (_MSC_VER >= 1200) | |
16 | # pragma once | |
17 | #endif | |
18 | ||
19 | #include <map> | |
20 | #include <boost/ptr_container/ptr_map_adapter.hpp> | |
21 | ||
22 | namespace boost | |
23 | { | |
24 | ||
25 | template | |
26 | < | |
27 | class Key, | |
28 | class T, | |
29 | class Compare = std::less<Key>, | |
30 | class CloneAllocator = heap_clone_allocator, | |
31 | class Allocator = std::allocator< std::pair<const Key,void*> > | |
32 | > | |
33 | class ptr_map : | |
34 | public ptr_map_adapter<T,std::map<Key,void*, | |
35 | Compare,Allocator>,CloneAllocator> | |
36 | { | |
37 | typedef ptr_map_adapter<T,std::map<Key,void*, | |
38 | Compare,Allocator>,CloneAllocator> | |
39 | base_type; | |
40 | ||
41 | typedef ptr_map<Key,T,Compare,CloneAllocator,Allocator> this_type; | |
42 | ||
43 | public: | |
44 | ptr_map() | |
45 | { } | |
46 | ||
47 | explicit ptr_map( const Compare& comp, | |
48 | const Allocator& a = Allocator() ) | |
49 | : base_type( comp, a ) { } | |
50 | ||
51 | template< class InputIterator > | |
52 | ptr_map( InputIterator first, InputIterator last ) | |
53 | : base_type( first, last ) | |
54 | { } | |
55 | ||
56 | template< class InputIterator > | |
57 | ptr_map( InputIterator first, InputIterator last, | |
58 | const Compare& comp, | |
59 | const Allocator& a = Allocator() ) | |
60 | : base_type( first, last, comp, a ) | |
61 | { } | |
62 | ||
63 | BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_map, base_type, | |
64 | this_type ) | |
65 | ||
66 | template< class U > | |
67 | ptr_map( const ptr_map<Key,U>& r ) : base_type( r ) | |
68 | { } | |
69 | ||
70 | ptr_map& operator=( ptr_map r ) | |
71 | { | |
72 | this->swap( r ); | |
73 | return *this; | |
74 | } | |
75 | }; | |
76 | ||
77 | ||
78 | ||
79 | template | |
80 | < | |
81 | class Key, | |
82 | class T, | |
83 | class Compare = std::less<Key>, | |
84 | class CloneAllocator = heap_clone_allocator, | |
85 | class Allocator = std::allocator< std::pair<const Key,void*> > | |
86 | > | |
87 | class ptr_multimap : | |
88 | public ptr_multimap_adapter<T,std::multimap<Key,void*, | |
89 | Compare,Allocator>,CloneAllocator> | |
90 | { | |
91 | typedef ptr_multimap_adapter<T,std::multimap<Key,void*, | |
92 | Compare,Allocator>,CloneAllocator> | |
93 | base_type; | |
94 | ||
95 | typedef ptr_multimap<Key,T,Compare,CloneAllocator,Allocator> this_type; | |
96 | ||
97 | public: | |
98 | ptr_multimap() | |
99 | { } | |
100 | ||
101 | explicit ptr_multimap( const Compare& comp, | |
102 | const Allocator& a = Allocator() ) | |
103 | : base_type( comp, a ) { } | |
104 | ||
105 | template< class InputIterator > | |
106 | ptr_multimap( InputIterator first, InputIterator last ) | |
107 | : base_type( first, last ) | |
108 | { } | |
109 | ||
110 | template< class InputIterator > | |
111 | ptr_multimap( InputIterator first, InputIterator last, | |
112 | const Compare& comp, | |
113 | const Allocator& a = Allocator() ) | |
114 | : base_type( first, last, comp, a ) | |
115 | { } | |
116 | ||
117 | BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_multimap, | |
118 | base_type, | |
119 | this_type ) | |
120 | ||
121 | template< class U > | |
122 | ptr_multimap( const ptr_multimap<Key,U>& r ) : base_type( r ) | |
123 | { } | |
124 | ||
125 | ptr_multimap& operator=( ptr_multimap r ) | |
126 | { | |
127 | this->swap( r ); | |
128 | return *this; | |
129 | } | |
130 | }; | |
131 | ||
132 | ////////////////////////////////////////////////////////////////////////////// | |
133 | // clonability | |
134 | ||
135 | template< class K, class T, class C, class CA, class A > | |
136 | inline ptr_map<K,T,C,CA,A>* new_clone( const ptr_map<K,T,C,CA,A>& r ) | |
137 | { | |
138 | return r.clone().release(); | |
139 | } | |
140 | ||
141 | template< class K, class T, class C, class CA, class A > | |
142 | inline ptr_multimap<K,T,C,CA,A>* new_clone( const ptr_multimap<K,T,C,CA,A>& r ) | |
143 | { | |
144 | return r.clone().release(); | |
145 | } | |
146 | ||
147 | ///////////////////////////////////////////////////////////////////////// | |
148 | // swap | |
149 | ||
150 | template< typename K, typename T, typename C, typename CA, typename A > | |
151 | inline void swap( ptr_map<K,T,C,CA,A>& l, ptr_map<K,T,C,CA,A>& r ) | |
152 | { | |
153 | l.swap(r); | |
154 | } | |
155 | ||
156 | template< typename K, typename T, typename C, typename CA, typename A > | |
157 | inline void swap( ptr_multimap<K,T,C,CA,A>& l, ptr_multimap<K,T,C,CA,A>& r ) | |
158 | { | |
159 | l.swap(r); | |
160 | } | |
161 | ||
162 | ||
163 | } | |
164 | ||
165 | #endif |