std::map C# improvements
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11236 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
3ffdfee64a
commit
25bcb4d5e6
3 changed files with 41 additions and 17 deletions
|
|
@ -1,10 +1,25 @@
|
|||
Version 1.3.40 (in progress)
|
||||
============================
|
||||
|
||||
2009-05-11: wsfulton
|
||||
2009-05-26: wsfulton
|
||||
[C#] Improved std::map wrappers based on patch from Yuval Baror. The C# proxy
|
||||
now implements System.Collections.Generic.IDictionary<>.
|
||||
|
||||
These std:map wrappers have a non-backwards compatible overhaul to make them
|
||||
like a .NET IDictionary. Some method names have changed as following:
|
||||
set -> setitem (use this[] property now)
|
||||
get -> getitem (use this[] property now)
|
||||
has_key -> ContainsKey
|
||||
del -> Remove
|
||||
clear -> Clear
|
||||
|
||||
The following macros used for std::map wrappers are deprecated and will no longer work:
|
||||
specialize_std_map_on_key
|
||||
specialize_std_map_on_value
|
||||
specialize_std_map_on_both
|
||||
|
||||
*** POTENTIAL INCOMPATIBILITY ***
|
||||
|
||||
2009-05-14: bhy
|
||||
[Python] Fix the wrong pointer value returned by SwigPyObject_repr().
|
||||
|
||||
|
|
|
|||
|
|
@ -226,14 +226,14 @@ public class li_std_map_runme {
|
|||
StructIntMap limap = new StructIntMap();
|
||||
Struct s7 = new Struct(7);
|
||||
Struct s8 = new Struct(8);
|
||||
limap.set(s7 , 8);
|
||||
if (limap.get(s7) != 8)
|
||||
limap.setitem(s7 , 8);
|
||||
if (limap.getitem(s7) != 8)
|
||||
throw new Exception("Assignment test on non-specialized map failed");
|
||||
|
||||
if (!limap.has_key(s7))
|
||||
if (!limap.ContainsKey(s7))
|
||||
throw new Exception("Key test (1) on non-specialized map failed");
|
||||
|
||||
if (limap.has_key(s8))
|
||||
if (limap.ContainsKey(s8))
|
||||
throw new Exception("Key test (2) on non-specialized map failed");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
%rename(Clear) clear;
|
||||
void clear();
|
||||
%extend {
|
||||
const mapped_type& get(const key_type& key) throw (std::out_of_range) {
|
||||
const mapped_type& getitem(const key_type& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator iter = $self->find(key);
|
||||
if (iter != $self->end())
|
||||
return iter->second;
|
||||
|
|
@ -61,22 +61,31 @@
|
|||
throw std::out_of_range("key not found");
|
||||
}
|
||||
|
||||
void set(const key_type& key, const mapped_type& x) {
|
||||
void setitem(const key_type& key, const mapped_type& x) {
|
||||
(*$self)[key] = x;
|
||||
}
|
||||
|
||||
void del(const key_type& key) throw (std::out_of_range) {
|
||||
std::map<K,T >::iterator iter = $self->find(key);
|
||||
if (iter != $self->end())
|
||||
$self->erase(iter);
|
||||
else
|
||||
throw std::out_of_range("key not found");
|
||||
}
|
||||
|
||||
bool has_key(const key_type& key) {
|
||||
std::map<K,T >::iterator iter = $self->find(key);
|
||||
bool ContainsKey(const key_type& key) {
|
||||
std::map<K, T >::iterator iter = $self->find(key);
|
||||
return iter != $self->end();
|
||||
}
|
||||
|
||||
void Add(const key_type& key, const mapped_type& val) throw (std::out_of_range) {
|
||||
std::map<K, T >::iterator iter = $self->find(key);
|
||||
if (iter != $self->end())
|
||||
throw std::out_of_range("key already exists");
|
||||
$self->insert(std::pair<K, T >(key, val));
|
||||
}
|
||||
|
||||
bool Remove(const key_type& key) {
|
||||
std::map<K, T >::iterator iter = $self->find(key);
|
||||
if (iter != $self->end()) {
|
||||
$self->erase(iter);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%enddef
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue