From 9efaf954c71118d41ba9bf43ed371bbe83093564 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 16 Aug 2013 23:34:24 +0200 Subject: [PATCH] Add support for std::map<> comparator template argument for C#. Allow exporting maps using non-default comparison function. Closes #77 --- CHANGES.current | 3 +++ Lib/csharp/std_map.i | 36 ++++++++++++++++++------------------ 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/CHANGES.current b/CHANGES.current index 07a57c42a..dfbe651f0 100644 --- a/CHANGES.current +++ b/CHANGES.current @@ -5,6 +5,9 @@ See the RELEASENOTES file for a summary of changes in each release. 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 [Python] %implicitconv is improved for overloaded functions. Like in C++, the methods with the actual types are considered before trying implicit conversions. Example: diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 6a7da16b6..acd190689 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -1,7 +1,7 @@ /* ----------------------------------------------------------------------------- * 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<>. * @@ -26,10 +26,10 @@ %} /* 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(cscode) std::map %{ +%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 %{ public $typemap(cstype, T) this[$typemap(cstype, K) key] { get { @@ -221,14 +221,14 @@ typedef T mapped_type; map(); - map(const map< K, T > &other); + map(const map< K, T, C > &other); size_type size() const; bool empty() const; %rename(Clear) clear; void clear(); %extend { 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()) return iter->second; else @@ -240,19 +240,19 @@ } 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(); } 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()) 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); + std::map< K, T, C >::iterator iter = $self->find(key); if (iter != $self->end()) { $self->erase(iter); 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# - %apply void *VOID_INT_PTR { std::map< K, T >::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 *create_iterator_begin } + %apply void *VOID_INT_PTR { std::map< K, T, C >::iterator *swigiterator } - std::map< K, T >::iterator *create_iterator_begin() { - return new std::map< K, T >::iterator($self->begin()); + std::map< K, T, C >::iterator *create_iterator_begin() { + return new std::map< K, T, C >::iterator($self->begin()); } - const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) { - std::map< K, T >::iterator iter = *swigiterator; + const key_type& get_next_key(std::map< K, T, C >::iterator *swigiterator) { + std::map< K, T, C >::iterator iter = *swigiterator; (*swigiterator)++; return (*iter).first; } - void destroy_iterator(std::map< K, T >::iterator *swigiterator) { + void destroy_iterator(std::map< K, T, C >::iterator *swigiterator) { delete swigiterator; } } @@ -291,8 +291,8 @@ // Default implementation namespace std { - template class map { - SWIG_STD_MAP_INTERNAL(K, T) + template > class map { + SWIG_STD_MAP_INTERNAL(K, T, C) }; }