diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/csharp/std_array.i | 71 | ||||
-rw-r--r-- | Lib/csharp/std_map.i | 3 | ||||
-rw-r--r-- | Lib/csharp/std_set.i | 2 | ||||
-rw-r--r-- | Lib/csharp/std_vector.i | 14 | ||||
-rw-r--r-- | Lib/java/director.swg | 44 | ||||
-rw-r--r-- | Lib/swiglabels.swg | 6 |
6 files changed, 89 insertions, 51 deletions
diff --git a/Lib/csharp/std_array.i b/Lib/csharp/std_array.i index 6e7fe9eb4..87b1b8956 100644 --- a/Lib/csharp/std_array.i +++ b/Lib/csharp/std_array.i @@ -6,37 +6,37 @@ * The C# wrapper is made to look and feel like a C# System.Collections.Generic.IReadOnlyList<> collection. * ----------------------------------------------------------------------------- */ -%{ -#include <algorithm> -#include <array> -#include <stdexcept> -%} - %include <std_common.i> -%define SWIG_STD_ARRAY_INTERNAL(T, N) -%typemap(csinterfaces) std::array< T, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>\n" +%define SWIG_STD_ARRAY_INTERNAL(CTYPE, N) +%typemap(csinterfaces) std::array< CTYPE, N > "global::System.IDisposable, global::System.Collections.IEnumerable\n , global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>\n" %proxycode %{ public $csclassname(global::System.Collections.ICollection c) : this() { if (c == null) throw new global::System.ArgumentNullException("c"); - int end = global::System.Math.Min(this.Count, c.Count); + int count = this.Count; int i = 0; - foreach ($typemap(cstype, T) elem in c) { - if (i >= end) + foreach ($typemap(cstype, CTYPE) element in c) { + if (i >= count) break; - this[i++] = elem; + this[i++] = element; } } - public int Count { + public bool IsFixedSize { get { - return (int)size(); + return true; } } - public $typemap(cstype, T) this[int index] { + public bool IsReadOnly { + get { + return false; + } + } + + public $typemap(cstype, CTYPE) this[int index] { get { return getitem(index); } @@ -51,17 +51,29 @@ } } - public void CopyTo($typemap(cstype, T)[] array) + public int Count { + get { + return (int)size(); + } + } + + public bool IsSynchronized { + get { + return false; + } + } + + public void CopyTo($typemap(cstype, CTYPE)[] array) { CopyTo(0, array, 0, this.Count); } - public void CopyTo($typemap(cstype, T)[] array, int arrayIndex) + public void CopyTo($typemap(cstype, CTYPE)[] array, int arrayIndex) { CopyTo(0, array, arrayIndex, this.Count); } - public void CopyTo(int index, $typemap(cstype, T)[] array, int arrayIndex, int count) + public void CopyTo(int index, $typemap(cstype, CTYPE)[] array, int arrayIndex, int count) { if (array == null) throw new global::System.ArgumentNullException("array"); @@ -79,7 +91,13 @@ array.SetValue(getitemcopy(index+i), arrayIndex+i); } - global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, T)>.GetEnumerator() { + public $typemap(cstype, CTYPE)[] ToArray() { + $typemap(cstype, CTYPE)[] array = new $typemap(cstype, CTYPE)[this.Count]; + this.CopyTo(array); + return array; + } + + global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> global::System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() { return new $csclassnameEnumerator(this); } @@ -97,7 +115,7 @@ /// collection but not when one of the elements of the collection is modified as it is a bit /// tricky to detect unmanaged code that modifies the collection under our feet. public sealed class $csclassnameEnumerator : global::System.Collections.IEnumerator - , global::System.Collections.Generic.IEnumerator<$typemap(cstype, T)> + , global::System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> { private $csclassname collectionRef; private int currentIndex; @@ -112,7 +130,7 @@ } // Type-safe iterator Current - public $typemap(cstype, T) Current { + public $typemap(cstype, CTYPE) Current { get { if (currentIndex == -1) throw new global::System.InvalidOperationException("Enumeration not started."); @@ -120,7 +138,7 @@ throw new global::System.InvalidOperationException("Enumeration finished."); if (currentObject == null) throw new global::System.InvalidOperationException("Collection modified."); - return ($typemap(cstype, T))currentObject; + return ($typemap(cstype, CTYPE))currentObject; } } @@ -161,7 +179,7 @@ public: typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef T value_type; + typedef CTYPE value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; @@ -180,7 +198,7 @@ void swap(array& other); %extend { - T getitemcopy(int index) throw (std::out_of_range) { + CTYPE getitemcopy(int index) throw (std::out_of_range) { if (index>=0 && index<(int)$self->size()) return (*$self)[index]; else @@ -213,6 +231,11 @@ } %enddef +%{ +#include <array> +#include <algorithm> +#include <stdexcept> +%} %csmethodmodifiers std::array::empty "private" %csmethodmodifiers std::array::getitemcopy "private" diff --git a/Lib/csharp/std_map.i b/Lib/csharp/std_map.i index 7a118569a..e7a910f65 100644 --- a/Lib/csharp/std_map.i +++ b/Lib/csharp/std_map.i @@ -269,12 +269,14 @@ } const key_type& get_next_key(std::map< K, T, C >::iterator *swigiterator) { + (void)$self; std::map< K, T, C >::iterator iter = *swigiterator; (*swigiterator)++; return (*iter).first; } void destroy_iterator(std::map< K, T, C >::iterator *swigiterator) { + (void)$self; delete swigiterator; } } @@ -309,4 +311,3 @@ namespace std { %define specialize_std_map_on_both(K,CHECK_K,CONVERT_K_FROM,CONVERT_K_TO, T,CHECK_T,CONVERT_T_FROM,CONVERT_T_TO) #warning "specialize_std_map_on_both ignored - macro is deprecated and no longer necessary" %enddef - diff --git a/Lib/csharp/std_set.i b/Lib/csharp/std_set.i index 012152260..ec8a3dc5e 100644 --- a/Lib/csharp/std_set.i +++ b/Lib/csharp/std_set.i @@ -297,12 +297,14 @@ class set { } const key_type& get_next(std::set<T>::iterator *swigiterator) { + (void)$self; std::set<T>::iterator iter = *swigiterator; (*swigiterator)++; return *iter; } void destroy_iterator(std::set<T>::iterator *swigiterator) { + (void)$self; delete swigiterator; } } diff --git a/Lib/csharp/std_vector.i b/Lib/csharp/std_vector.i index a2add584d..8438f6418 100644 --- a/Lib/csharp/std_vector.i +++ b/Lib/csharp/std_vector.i @@ -69,6 +69,12 @@ } } + public bool IsEmpty { + get { + return empty(); + } + } + public int Count { get { return (int)size(); @@ -203,19 +209,20 @@ typedef value_type& reference; typedef CONST_REFERENCE const_reference; + vector(); + vector(const vector &other); + %rename(Clear) clear; void clear(); %rename(Add) push_back; void push_back(CTYPE const& x); size_type size() const; + bool empty() const; size_type capacity() const; void reserve(size_type n); %newobject GetRange(int index, int count); %newobject Repeat(CTYPE const& value, int count); - vector(); - vector(const vector &other); - %extend { vector(int capacity) throw (std::out_of_range) { std::vector< CTYPE >* pv = 0; @@ -415,4 +422,3 @@ SWIG_STD_VECTOR_ENHANCED(float) SWIG_STD_VECTOR_ENHANCED(double) SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include <std_string.i> SWIG_STD_VECTOR_ENHANCED(std::wstring) // also requires a %include <std_wstring.i> - diff --git a/Lib/java/director.swg b/Lib/java/director.swg index 536513557..630a98f3b 100644 --- a/Lib/java/director.swg +++ b/Lib/java/director.swg @@ -60,11 +60,11 @@ namespace Swig { /* Java object wrapper */ class JObjectWrapper { public: - JObjectWrapper() : jthis_(NULL), weak_global_(true) { + JObjectWrapper() : jthis_(SWIG_NULLPTR), weak_global_(true) { } ~JObjectWrapper() { - jthis_ = NULL; + jthis_ = SWIG_NULLPTR; weak_global_ = true; } @@ -103,13 +103,13 @@ namespace Swig { #endif if (jthis_) { if (weak_global_) { - if (jenv->IsSameObject(jthis_, NULL) == JNI_FALSE) + if (jenv->IsSameObject(jthis_, SWIG_NULLPTR) == JNI_FALSE) jenv->DeleteWeakGlobalRef((jweak)jthis_); } else jenv->DeleteGlobalRef(jthis_); } - jthis_ = NULL; + jthis_ = SWIG_NULLPTR; weak_global_ = true; } @@ -193,7 +193,7 @@ namespace Swig { JNIEnv *jenv_; int env_status; public: - JNIEnvWrapper(const Director *director) : director_(director), jenv_(0), env_status(0) { + JNIEnvWrapper(const Director *director) : director_(director), jenv_(SWIG_NULLPTR), env_status(0) { #if defined(__ANDROID__) JNIEnv **jenv = &jenv_; #else @@ -202,8 +202,8 @@ namespace Swig { env_status = director_->swig_jvm_->GetEnv((void **)&jenv_, JNI_VERSION_1_2); JavaVMAttachArgs args; args.version = JNI_VERSION_1_2; - args.group = NULL; - args.name = NULL; + args.group = SWIG_NULLPTR; + args.name = SWIG_NULLPTR; #if defined(SWIG_JAVA_USE_THREAD_NAME) char thread_name[64]; // MAX_TASK_COMM_LEN=16 is hard-coded in the Linux kernel and MacOS has MAXTHREADNAMESIZE=64. if (Swig::GetThreadName(thread_name, sizeof(thread_name)) == 0) { @@ -267,7 +267,7 @@ namespace Swig { #if defined(DEBUG_DIRECTOR_OWNED) std::cout << "Swig::Director::disconnect_director_self(" << jobj << ")" << std::endl; #endif - if (jobj && jenv->IsSameObject(jobj, NULL) == JNI_FALSE) { + if (jobj && jenv->IsSameObject(jobj, SWIG_NULLPTR) == JNI_FALSE) { jmethodID disconn_meth = jenv->GetMethodID(jenv->GetObjectClass(jobj), disconn_method, "()V"); if (disconn_meth) { #if defined(DEBUG_DIRECTOR_OWNED) @@ -280,11 +280,11 @@ namespace Swig { jclass swig_new_global_ref(JNIEnv *jenv, const char *classname) { jclass clz = jenv->FindClass(classname); - return clz ? (jclass)jenv->NewGlobalRef(clz) : 0; + return clz ? (jclass)jenv->NewGlobalRef(clz) : SWIG_NULLPTR; } public: - Director(JNIEnv *jenv) : swig_jvm_((JavaVM *) NULL), swig_self_() { + Director(JNIEnv *jenv) : swig_jvm_((JavaVM *) SWIG_NULLPTR), swig_self_() { /* Acquire the Java VM pointer */ jenv->GetJavaVM(&swig_jvm_); } @@ -329,9 +329,9 @@ namespace Swig { // Simple holder for a Java string during exception handling, providing access to a c-style string class JavaString { public: - JavaString(JNIEnv *jenv, jstring jstr) : jenv_(jenv), jstr_(jstr), cstr_(0) { + JavaString(JNIEnv *jenv, jstring jstr) : jenv_(jenv), jstr_(jstr), cstr_(SWIG_NULLPTR) { if (jenv_ && jstr_) - cstr_ = (const char *) jenv_->GetStringUTFChars(jstr_, NULL); + cstr_ = (const char *) jenv_->GetStringUTFChars(jstr_, SWIG_NULLPTR); } ~JavaString() { @@ -372,7 +372,7 @@ namespace Swig { // Get exception message by calling Java method Throwable.getMessage() static jstring exceptionMessageFromThrowable(JNIEnv *jenv, jthrowable throwable) { - jstring jmsg = NULL; + jstring jmsg = SWIG_NULLPTR; if (jenv && throwable) { jenv->ExceptionClear(); // Cannot invoke methods with any pending exceptions jclass throwclz = jenv->GetObjectClass(throwable); @@ -382,7 +382,7 @@ namespace Swig { if (getMessageMethodID) jmsg = (jstring)jenv->CallObjectMethod(throwable, getMessageMethodID); } - if (jmsg == NULL && jenv->ExceptionCheck()) + if (jmsg == SWIG_NULLPTR && jenv->ExceptionCheck()) jenv->ExceptionClear(); } return jmsg; @@ -396,7 +396,7 @@ namespace Swig { public: // Construct exception from a Java throwable - DirectorException(JNIEnv *jenv, jthrowable throwable) : jenv_(jenv), throwable_(throwable), classname_(0), msg_(0) { + DirectorException(JNIEnv *jenv, jthrowable throwable) : jenv_(jenv), throwable_(throwable), classname_(SWIG_NULLPTR), msg_(SWIG_NULLPTR) { // Call Java method Object.getClass().getName() to obtain the throwable's class name (delimited by '/') if (jenv && throwable) { @@ -411,7 +411,7 @@ namespace Swig { // Copy strings, since there is no guarantee that jenv will be active when handled if (jstr_classname) { JavaString jsclassname(jenv, jstr_classname); - const char *classname = jsclassname.c_str(0); + const char *classname = jsclassname.c_str(SWIG_NULLPTR); if (classname) classname_ = copypath(classname); } @@ -421,11 +421,11 @@ namespace Swig { } JavaExceptionMessage exceptionmsg(jenv, throwable); - msg_ = copystr(exceptionmsg.message(0)); + msg_ = copystr(exceptionmsg.message(SWIG_NULLPTR)); } // More general constructor for handling as a java.lang.RuntimeException - DirectorException(const char *msg) : jenv_(0), throwable_(0), classname_(0), msg_(msg ? copystr(msg) : 0) { + DirectorException(const char *msg) : jenv_(SWIG_NULLPTR), throwable_(SWIG_NULLPTR), classname_(SWIG_NULLPTR), msg_(msg ? copystr(msg) : SWIG_NULLPTR) { } ~DirectorException() throw() { @@ -446,7 +446,7 @@ namespace Swig { jthrowable throwable = jenv->ExceptionOccurred(); if (throwable && jenv->IsSameObject(throwable, throwable_) == JNI_FALSE) { jenv->ExceptionClear(); - throwable = 0; + throwable = SWIG_NULLPTR; } if (!throwable) jenv->Throw(throwable_); @@ -454,8 +454,8 @@ namespace Swig { // Try and reconstruct original exception, but original stacktrace is not reconstructed jenv->ExceptionClear(); - jmethodID ctorMethodID = 0; - jclass throwableclass = 0; + jmethodID ctorMethodID = SWIG_NULLPTR; + jclass throwableclass = SWIG_NULLPTR; if (classname_) { throwableclass = jenv->FindClass(classname_); if (throwableclass) @@ -492,7 +492,7 @@ namespace Swig { } static char *copystr(const char *srcmsg) { - char *target = 0; + char *target = SWIG_NULLPTR; if (srcmsg) { size_t msglen = strlen(srcmsg) + 1; target = new char[msglen]; diff --git a/Lib/swiglabels.swg b/Lib/swiglabels.swg index b3855665e..0b9ad2383 100644 --- a/Lib/swiglabels.swg +++ b/Lib/swiglabels.swg @@ -121,3 +121,9 @@ #ifdef __INTEL_COMPILER # pragma warning disable 592 #endif + +#if __cplusplus >=201103L +# define SWIG_NULLPTR nullptr +#else +# define SWIG_NULLPTR NULL +#endif |