|
|
|
1 |
|
// map stl/clr header |
2 |
|
#ifndef _CLI_MAP_ |
3 |
|
#define _CLI_MAP_ |
4 |
|
#include <cliext/xtree> |
5 |
|
#include <cliext/utility> |
6 |
|
|
7 |
|
namespace cliext { |
8 |
|
namespace impl { |
9 |
|
// |
10 |
|
// TEMPLATE CLASS map_traits |
11 |
|
// |
12 |
|
template<typename _Key_t, // key type |
13 |
|
typename _Mapped_t, // mapped type |
14 |
|
bool _Mflag, // true if multiple equivalent keys are permitted |
15 |
|
bool _Is_ref_key, // true if key field is allocated |
16 |
|
bool _Is_ref_mapped> // true if mapped field is allocated |
17 |
|
ref class map_traits |
18 |
|
{ // traits required to make tree behave like a map |
19 |
|
public: |
20 |
|
typedef map_traits<_Key_t, _Mapped_t, _Mflag, |
21 |
|
_Is_ref_key, _Is_ref_mapped> _Mytype_t; |
22 |
|
|
23 |
|
typedef _Key_t key_type; |
24 |
|
typedef _Mapped_t mapped_type; |
25 |
|
typedef _STLCLR GenericPair<_Key_t, _Mapped_t>^ value_type; |
26 |
|
typedef _STLCLR BinaryDelegate<key_type, key_type, bool> |
27 |
|
key_compare; |
28 |
|
typedef _STLCLR BinaryDelegate<value_type, value_type, bool> |
29 |
|
value_compare; |
30 |
|
|
31 |
|
typedef _Key_t generic_key; |
32 |
|
typedef _Mapped_t generic_mapped; |
33 |
|
|
34 |
|
map_traits() |
35 |
|
: comp(gcnew key_compare(&_Key_compare)), |
36 |
|
_Multi(_Mflag) |
37 |
|
{ // construct with default comparator |
38 |
|
} |
39 |
|
|
40 |
|
map_traits(key_compare^ _Pred) |
41 |
|
: comp(_Pred), |
42 |
|
_Multi(_Mflag) |
43 |
|
{ // construct with specified comparator |
44 |
|
} |
45 |
|
|
46 |
|
key_compare^ key_comp() |
47 |
|
{ // return object for comparing keys |
48 |
|
return (comp); |
49 |
|
} |
50 |
|
|
51 |
|
value_compare^ value_comp() |
52 |
|
{ // return object for comparing values |
53 |
|
return (gcnew value_compare(this, &_Mytype_t::_Value_compare)); |
2175 |
|
} |
2176 |
|
|
2177 |
|
multimap(_Myenum_it^ _Right) |
2178 |
|
: _Mybase_t() |
2179 |
|
{ // construct map from enumeration, default comparator |
2180 |
|
for each (value_type _Val in _Right) |
2181 |
|
insert(_Val); |
2182 |
|
} |
2183 |
|
|
2184 |
|
multimap(_Myenum_it^ _Right, |
2185 |
|
key_compare^ _Pred) |
2186 |
|
: _Mybase_t(_Pred) |
2187 |
|
{ // construct map from enumeration, comparator |
2188 |
|
for each (value_type _Val in _Right) |
2189 |
|
insert(_Val); |
2190 |
|
} |
2191 |
|
|
2192 |
|
// mutators |
2193 |
|
void swap(multimap% _Right) |
2194 |
|
{ // exchange contents with _Right |
2195 |
|
_Mybase_t::swap(_Right); |
2196 |
|
} |
2197 |
|
|
2198 |
|
// interfaces |
2199 |
|
public: |
2200 |
|
virtual System::Object^ Clone() override |
2201 |
|
{ // clone the vector |
2202 |
|
return (gcnew _Mytype_t(*this)); |
2203 |
|
} |
2204 |
|
}; |
2205 |
|
|
2206 |
|
// |
2207 |
|
// TEMPLATE FUNCTION swap |
2208 |
|
// |
2209 |
|
template<typename _Key_t, |
2210 |
|
typename _Mapped_t> inline |
2211 |
|
void swap(multimap<_Key_t, _Mapped_t>% _Left, |
2212 |
|
multimap<_Key_t, _Mapped_t>% _Right) |
2213 |
|
{ // swap two multimaps |
2214 |
|
_Left.swap(_Right); |
2215 |
|
} |
2216 |
|
} // namespace cliext |
2217 |
|
#endif // _CLI_MAP_ |
2218 |
|
|
2219 |
|
/* |
2220 |
|
* Copyright (c) 2004-2007 by Dinkumware, Ltd. ALL RIGHTS RESERVED. |
2221 |
|
* Consult your license regarding permissions and restrictions. |
2222 |
|
V5.03:0009 */ |
2223 |
|
|
|
|
|