Add support for std::map<> comparator template argument for C#.
Allow exporting maps using non-default comparison function. Closes #77
This commit is contained in:
parent
6efe3d61f2
commit
9efaf954c7
2 changed files with 21 additions and 18 deletions
|
|
@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release.
|
||||||
Version 2.0.11 (in progress)
|
Version 2.0.11 (in progress)
|
||||||
============================
|
============================
|
||||||
|
|
||||||
|
2013-08-29: wsfulton
|
||||||
|
[C#] Pull Git patch #77: Allow exporting std::map using non-default comparison function.
|
||||||
|
|
||||||
2013-08-28: wsfulton
|
2013-08-28: wsfulton
|
||||||
[Python] %implicitconv is improved for overloaded functions. Like in C++, the methods
|
[Python] %implicitconv is improved for overloaded functions. Like in C++, the methods
|
||||||
with the actual types are considered before trying implicit conversions. Example:
|
with the actual types are considered before trying implicit conversions. Example:
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
/* -----------------------------------------------------------------------------
|
/* -----------------------------------------------------------------------------
|
||||||
* std_map.i
|
* std_map.i
|
||||||
*
|
*
|
||||||
* SWIG typemaps for std::map< K, T >
|
* SWIG typemaps for std::map< K, T, C >
|
||||||
*
|
*
|
||||||
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IDictionary<>.
|
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IDictionary<>.
|
||||||
*
|
*
|
||||||
|
|
@ -26,10 +26,10 @@
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/* K is the C++ key type, T is the C++ value type */
|
/* K is the C++ key type, T is the C++ value type */
|
||||||
%define SWIG_STD_MAP_INTERNAL(K, T)
|
%define SWIG_STD_MAP_INTERNAL(K, T, C)
|
||||||
|
|
||||||
%typemap(csinterfaces) std::map< K, T > "IDisposable \n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n#endif\n";
|
%typemap(csinterfaces) std::map< K, T, C > "IDisposable \n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IDictionary<$typemap(cstype, K), $typemap(cstype, T)>\n#endif\n";
|
||||||
%typemap(cscode) std::map<K, T > %{
|
%typemap(cscode) std::map<K, T, C > %{
|
||||||
|
|
||||||
public $typemap(cstype, T) this[$typemap(cstype, K) key] {
|
public $typemap(cstype, T) this[$typemap(cstype, K) key] {
|
||||||
get {
|
get {
|
||||||
|
|
@ -221,14 +221,14 @@
|
||||||
typedef T mapped_type;
|
typedef T mapped_type;
|
||||||
|
|
||||||
map();
|
map();
|
||||||
map(const map< K, T > &other);
|
map(const map< K, T, C > &other);
|
||||||
size_type size() const;
|
size_type size() const;
|
||||||
bool empty() const;
|
bool empty() const;
|
||||||
%rename(Clear) clear;
|
%rename(Clear) clear;
|
||||||
void clear();
|
void clear();
|
||||||
%extend {
|
%extend {
|
||||||
const mapped_type& getitem(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);
|
std::map< K, T, C >::iterator iter = $self->find(key);
|
||||||
if (iter != $self->end())
|
if (iter != $self->end())
|
||||||
return iter->second;
|
return iter->second;
|
||||||
else
|
else
|
||||||
|
|
@ -240,19 +240,19 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContainsKey(const key_type& key) {
|
bool ContainsKey(const key_type& key) {
|
||||||
std::map< K, T >::iterator iter = $self->find(key);
|
std::map< K, T, C >::iterator iter = $self->find(key);
|
||||||
return iter != $self->end();
|
return iter != $self->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Add(const key_type& key, const mapped_type& val) throw (std::out_of_range) {
|
void Add(const key_type& key, const mapped_type& val) throw (std::out_of_range) {
|
||||||
std::map< K, T >::iterator iter = $self->find(key);
|
std::map< K, T, C >::iterator iter = $self->find(key);
|
||||||
if (iter != $self->end())
|
if (iter != $self->end())
|
||||||
throw std::out_of_range("key already exists");
|
throw std::out_of_range("key already exists");
|
||||||
$self->insert(std::pair< K, T >(key, val));
|
$self->insert(std::pair< K, T >(key, val));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Remove(const key_type& key) {
|
bool Remove(const key_type& key) {
|
||||||
std::map< K, T >::iterator iter = $self->find(key);
|
std::map< K, T, C >::iterator iter = $self->find(key);
|
||||||
if (iter != $self->end()) {
|
if (iter != $self->end()) {
|
||||||
$self->erase(iter);
|
$self->erase(iter);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -261,20 +261,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// create_iterator_begin(), get_next_key() and destroy_iterator work together to provide a collection of keys to C#
|
// create_iterator_begin(), get_next_key() and destroy_iterator work together to provide a collection of keys to C#
|
||||||
%apply void *VOID_INT_PTR { std::map< K, T >::iterator *create_iterator_begin }
|
%apply void *VOID_INT_PTR { std::map< K, T, C >::iterator *create_iterator_begin }
|
||||||
%apply void *VOID_INT_PTR { std::map< K, T >::iterator *swigiterator }
|
%apply void *VOID_INT_PTR { std::map< K, T, C >::iterator *swigiterator }
|
||||||
|
|
||||||
std::map< K, T >::iterator *create_iterator_begin() {
|
std::map< K, T, C >::iterator *create_iterator_begin() {
|
||||||
return new std::map< K, T >::iterator($self->begin());
|
return new std::map< K, T, C >::iterator($self->begin());
|
||||||
}
|
}
|
||||||
|
|
||||||
const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) {
|
const key_type& get_next_key(std::map< K, T, C >::iterator *swigiterator) {
|
||||||
std::map< K, T >::iterator iter = *swigiterator;
|
std::map< K, T, C >::iterator iter = *swigiterator;
|
||||||
(*swigiterator)++;
|
(*swigiterator)++;
|
||||||
return (*iter).first;
|
return (*iter).first;
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_iterator(std::map< K, T >::iterator *swigiterator) {
|
void destroy_iterator(std::map< K, T, C >::iterator *swigiterator) {
|
||||||
delete swigiterator;
|
delete swigiterator;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -291,8 +291,8 @@
|
||||||
|
|
||||||
// Default implementation
|
// Default implementation
|
||||||
namespace std {
|
namespace std {
|
||||||
template<class K, class T> class map {
|
template<class K, class T, class C = std::less<K> > class map {
|
||||||
SWIG_STD_MAP_INTERNAL(K, T)
|
SWIG_STD_MAP_INTERNAL(K, T, C)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue