Merged with recent changes from trunk.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2008-maciekd@11187 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
da5ade3143
commit
8c74fa0f46
703 changed files with 21126 additions and 9266 deletions
83
Lib/csharp/std_vector.i
Executable file → Normal file
83
Lib/csharp/std_vector.i
Executable file → Normal file
|
|
@ -6,15 +6,22 @@
|
|||
*
|
||||
* SWIG typemaps for std::vector
|
||||
* C# implementation
|
||||
* The C# wrapper is made to look and feel like a typesafe C# System.Collections.ArrayList
|
||||
* All the methods in IList are defined, but we don't derive from IList as this is a typesafe collection.
|
||||
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
|
||||
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.List<> collection.
|
||||
* For .NET 1 compatibility, define SWIG_DOTNET_1 when compiling the C# code; then the C# wrapper is
|
||||
* made to look and feel like a typesafe C# System.Collections.ArrayList. All the methods in IList
|
||||
* are defined, but we don't derive from IList as this is a typesafe collection and the C++ operator==
|
||||
* must always be defined for the collection type (which it isn't).
|
||||
*
|
||||
* Very often the C# generated code will not compile as the C++ template type is not the same as the C#
|
||||
* proxy type, so use the SWIG_STD_VECTOR_SPECIALIZE or SWIG_STD_VECTOR_SPECIALIZE_MINIMUM macro, eg
|
||||
*
|
||||
* SWIG_STD_VECTOR_SPECIALIZE_MINIMUM(Klass, SomeNamespace::Klass)
|
||||
* %template(VectKlass) std::vector<SomeNamespace::Klass>;
|
||||
*
|
||||
* Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
|
||||
* C++ std::vector wrappers.
|
||||
*
|
||||
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
// Warning: Use the typemaps here in the expectation that the macros they are in will change name.
|
||||
|
|
@ -24,8 +31,8 @@
|
|||
|
||||
// MACRO for use within the std::vector class body
|
||||
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
|
||||
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
|
||||
%typemap(csinterfaces) std::vector<CTYPE > "IDisposable, System.Collections.IEnumerable";
|
||||
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CONST_REFERENCE_TYPE, CSTYPE, CTYPE...)
|
||||
%typemap(csinterfaces) std::vector<CTYPE > "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IEnumerable<CSTYPE>\n#endif\n";
|
||||
%typemap(cscode) std::vector<CTYPE > %{
|
||||
public $csclassname(System.Collections.ICollection c) : this() {
|
||||
if (c == null)
|
||||
|
|
@ -79,15 +86,30 @@
|
|||
}
|
||||
}
|
||||
|
||||
public void CopyTo(System.Array array) {
|
||||
#if SWIG_DOTNET_1
|
||||
public void CopyTo(System.Array array)
|
||||
#else
|
||||
public void CopyTo(CSTYPE[] array)
|
||||
#endif
|
||||
{
|
||||
CopyTo(0, array, 0, this.Count);
|
||||
}
|
||||
|
||||
public void CopyTo(System.Array array, int arrayIndex) {
|
||||
#if SWIG_DOTNET_1
|
||||
public void CopyTo(System.Array array, int arrayIndex)
|
||||
#else
|
||||
public void CopyTo(CSTYPE[] array, int arrayIndex)
|
||||
#endif
|
||||
{
|
||||
CopyTo(0, array, arrayIndex, this.Count);
|
||||
}
|
||||
|
||||
public void CopyTo(int index, System.Array array, int arrayIndex, int count) {
|
||||
#if SWIG_DOTNET_1
|
||||
public void CopyTo(int index, System.Array array, int arrayIndex, int count)
|
||||
#else
|
||||
public void CopyTo(int index, CSTYPE[] array, int arrayIndex, int count)
|
||||
#endif
|
||||
{
|
||||
if (array == null)
|
||||
throw new ArgumentNullException("array");
|
||||
if (index < 0)
|
||||
|
|
@ -97,14 +119,19 @@
|
|||
if (count < 0)
|
||||
throw new ArgumentOutOfRangeException("count", "Value is less than zero");
|
||||
if (array.Rank > 1)
|
||||
throw new ArgumentException("Multi dimensional array.");
|
||||
throw new ArgumentException("Multi dimensional array.", "array");
|
||||
if (index+count > this.Count || arrayIndex+count > array.Length)
|
||||
throw new ArgumentException("Number of elements to copy is too large.");
|
||||
for (int i=0; i<count; i++)
|
||||
array.SetValue(getitemcopy(index+i), arrayIndex+i);
|
||||
}
|
||||
|
||||
// Type-safe version of IEnumerable.GetEnumerator
|
||||
#if !SWIG_DOTNET_1
|
||||
System.Collections.Generic.IEnumerator<CSTYPE> System.Collections.Generic.IEnumerable<CSTYPE>.GetEnumerator() {
|
||||
return new $csclassnameEnumerator(this);
|
||||
}
|
||||
#endif
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
|
||||
return new $csclassnameEnumerator(this);
|
||||
}
|
||||
|
|
@ -118,7 +145,11 @@
|
|||
/// whenever the collection is modified. This has been done for changes in the size of the
|
||||
/// 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 : System.Collections.IEnumerator {
|
||||
public sealed class $csclassnameEnumerator : System.Collections.IEnumerator
|
||||
#if !SWIG_DOTNET_1
|
||||
, System.Collections.Generic.IEnumerator<CSTYPE>
|
||||
#endif
|
||||
{
|
||||
private $csclassname collectionRef;
|
||||
private int currentIndex;
|
||||
private object currentObject;
|
||||
|
|
@ -170,13 +201,20 @@
|
|||
throw new InvalidOperationException("Collection modified.");
|
||||
}
|
||||
}
|
||||
|
||||
#if !SWIG_DOTNET_1
|
||||
public void Dispose() {
|
||||
currentIndex = -1;
|
||||
currentObject = null;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
%}
|
||||
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef CTYPE value_type;
|
||||
typedef const value_type& const_reference;
|
||||
typedef CONST_REFERENCE_TYPE const_reference;
|
||||
%rename(Clear) clear;
|
||||
void clear();
|
||||
%rename(Add) push_back;
|
||||
|
|
@ -286,8 +324,14 @@
|
|||
}
|
||||
%enddef
|
||||
|
||||
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
|
||||
SWIG_STD_VECTOR_MINIMUM_INTERNAL(const value_type&, CSTYPE, CTYPE)
|
||||
%enddef
|
||||
|
||||
|
||||
// Extra methods added to the collection class if operator== is defined for the class being wrapped
|
||||
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
|
||||
// The class will then implement IList<>, which adds extra functionality
|
||||
%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CSTYPE, CTYPE...)
|
||||
%extend {
|
||||
bool Contains(const value_type& value) {
|
||||
|
|
@ -307,10 +351,13 @@
|
|||
index = (int)(self->rend() - 1 - rit);
|
||||
return index;
|
||||
}
|
||||
void Remove(const value_type& value) {
|
||||
bool Remove(const value_type& value) {
|
||||
std::vector<CTYPE >::iterator it = std::find(self->begin(), self->end(), value);
|
||||
if (it != self->end())
|
||||
if (it != self->end()) {
|
||||
self->erase(it);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
|
@ -334,7 +381,6 @@ namespace std {
|
|||
}
|
||||
%enddef
|
||||
|
||||
|
||||
%{
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
|
@ -361,11 +407,15 @@ namespace std {
|
|||
template<class T> class vector<const T*> {
|
||||
SWIG_STD_VECTOR_MINIMUM(T, const T*)
|
||||
};
|
||||
// bool is a bit different in the C++ standard
|
||||
template<> class vector<bool> {
|
||||
SWIG_STD_VECTOR_MINIMUM_INTERNAL(bool, bool, bool)
|
||||
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool, bool)
|
||||
};
|
||||
}
|
||||
|
||||
// template specializations for std::vector
|
||||
// these provide extra collections methods as operator== is defined
|
||||
SWIG_STD_VECTOR_SPECIALIZE(bool, bool)
|
||||
SWIG_STD_VECTOR_SPECIALIZE(char, char)
|
||||
SWIG_STD_VECTOR_SPECIALIZE(sbyte, signed char)
|
||||
SWIG_STD_VECTOR_SPECIALIZE(byte, unsigned char)
|
||||
|
|
@ -381,4 +431,3 @@ SWIG_STD_VECTOR_SPECIALIZE(float, float)
|
|||
SWIG_STD_VECTOR_SPECIALIZE(double, double)
|
||||
SWIG_STD_VECTOR_SPECIALIZE(string, std::string) // also requires a %include <std_string.i>
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue