merge revisions 11243-11872 from trunk to gsoc2009-matevz

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/branches/gsoc2009-matevz@12162 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2010-07-20 21:58:41 +00:00
commit ab1cd03979
387 changed files with 12383 additions and 4412 deletions

View file

@ -19,7 +19,7 @@
%include <chicken/chickenkw.swg>
%include <csharp/csharpkw.swg>
%include <java/javakw.swg>
%include <php/php.swg>
%include <php/phpkw.swg>
%include <pike/pikekw.swg>
%include <python/pythonkw.swg>
%include <ocaml/ocamlkw.swg>

View file

@ -76,5 +76,6 @@ SWIGCDATA cdata_##NAME(TYPE *ptr, int nelements);
%cdata(void);
/* Memory move function */
/* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
void memmove(void *data, const char *s); */
void memmove(void *data, const void *indata, int inlen);

View file

@ -1,7 +1,9 @@
%include <shared_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
@ -10,6 +12,7 @@
//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
"(void)arg1; delete smartarg1;"
// Typemap customisations...
// plain value
%typemap(in, canthrow=1) CONST TYPE ($&1_type argp = 0) %{

View file

@ -1,25 +1,14 @@
/* -----------------------------------------------------------------------------
* std_map.i
*
* SWIG typemaps for std::map
* SWIG typemaps for std::map< K, T >
*
* The C# wrapper is made to look and feel like a C# System.Collections.Generic.IDictionary<>.
*
* Using this wrapper is fairly simple. For example, to create a map from integers to doubles use:
*
* %include <std_map.i>
* %template(Map_Int_Double) std::map<int, double>
*
* 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_MAP_SPECIALIZED or SWIG_STD_MAP_SPECIALIZED_SIMPLE macros. For example:
*
* SWIG_STD_MAP_SPECIALIZED(MyCppKeyClass, MyCppValueClass, MyCsKeyClass, MyCsValueClass)
* %template(Map_MyCppKeyClass_MyCppValueClass) std::map<MyCppKeyClass, MyCppValueClass >;
*
* Or if the C# class names are the same as the C++ class names, you can use:
*
* SWIG_STD_MAP_SPECIALIZED_SIMPLE(MyKeyClass, MyValueClass)
* %template(Map_MyCppKeyClass_MyCppValueClass) std::map<MyKeyClass, MyValueClass >;
* %template(MapIntDouble) std::map<int, double>
*
* Notes:
* 1) For .NET 1 compatibility, define SWIG_DOTNET_1 when compiling the C# code. In this case
@ -36,69 +25,13 @@
#include <stdexcept>
%}
// A minimal implementation to be used when no specialization exists.
%define SWIG_STD_MAP_MINIMAL_INTERNAL(K, T)
public:
map();
map(const map<K, T > &other);
/* K is the C++ key type, T is the C++ value type */
%define SWIG_STD_MAP_INTERNAL(K, T)
typedef K key_type;
typedef T mapped_type;
typedef size_t size_type;
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);
if (iter != $self->end())
return iter->second;
else
throw std::out_of_range("key not found");
}
void setitem(const key_type& key, const mapped_type& x) {
(*$self)[key] = x;
}
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
/* The specialized std::map implementation
* K is the C++ key type
* T is the C++ value type
* CSKEYTYPE is the C# key type
* CSVALUETYPE is the C# value type
*/
%define SWIG_STD_MAP_SPECIALIZED_INTERNAL(K, T, CSKEYTYPE, CSVALUETYPE)
// add typemaps here
%typemap(csinterfaces) std::map<K, T > "IDisposable \n#if !SWIG_DOTNET_1\n , System.Collections.Generic.IDictionary<CSKEYTYPE, CSVALUETYPE>\n#endif\n";
%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<K, T > %{
public CSVALUETYPE this[CSKEYTYPE key] {
public $typemap(cstype, T) this[$typemap(cstype, K) key] {
get {
return getitem(key);
}
@ -108,12 +41,12 @@
}
}
public bool TryGetValue(CSKEYTYPE key, out CSVALUETYPE value) {
public bool TryGetValue($typemap(cstype, K) key, out $typemap(cstype, T) value) {
if (this.ContainsKey(key)) {
value = this[key];
return true;
}
value = default(CSVALUETYPE);
value = default($typemap(cstype, T));
return false;
}
@ -131,9 +64,9 @@
#if !SWIG_DOTNET_1
public System.Collections.Generic.ICollection<CSKEYTYPE> Keys {
public System.Collections.Generic.ICollection<$typemap(cstype, K)> Keys {
get {
System.Collections.Generic.ICollection<CSKEYTYPE> keys = new System.Collections.Generic.List<CSKEYTYPE>();
System.Collections.Generic.ICollection<$typemap(cstype, K)> keys = new System.Collections.Generic.List<$typemap(cstype, K)>();
IntPtr iter = create_iterator_begin();
try {
while (true) {
@ -145,21 +78,21 @@
}
}
public System.Collections.Generic.ICollection<CSVALUETYPE> Values {
public System.Collections.Generic.ICollection<$typemap(cstype, T)> Values {
get {
System.Collections.Generic.ICollection<CSVALUETYPE> vals = new System.Collections.Generic.List<CSVALUETYPE>();
foreach (System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> pair in this) {
System.Collections.Generic.ICollection<$typemap(cstype, T)> vals = new System.Collections.Generic.List<$typemap(cstype, T)>();
foreach (System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> pair in this) {
vals.Add(pair.Value);
}
return vals;
}
}
public void Add(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> item) {
public void Add(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) {
Add(item.Key, item.Value);
}
public bool Remove(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> item) {
public bool Remove(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) {
if (Contains(item)) {
return Remove(item.Key);
} else {
@ -167,7 +100,7 @@
}
}
public bool Contains(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> item) {
public bool Contains(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> item) {
if (this[item.Key] == item.Value) {
return true;
} else {
@ -175,11 +108,11 @@
}
}
public void CopyTo(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>[] array) {
public void CopyTo(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array) {
CopyTo(array, 0);
}
public void CopyTo(System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>[] array, int arrayIndex) {
public void CopyTo(System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>[] array, int arrayIndex) {
if (array == null)
throw new ArgumentNullException("array");
if (arrayIndex < 0)
@ -189,14 +122,14 @@
if (arrayIndex+this.Count > array.Length)
throw new ArgumentException("Number of elements to copy is too large.");
System.Collections.Generic.IList<CSKEYTYPE> keyList = new System.Collections.Generic.List<CSKEYTYPE>(this.Keys);
System.Collections.Generic.IList<$typemap(cstype, K)> keyList = new System.Collections.Generic.List<$typemap(cstype, K)>(this.Keys);
for (int i = 0; i < keyList.Count; i++) {
CSKEYTYPE currentKey = keyList[i];
array.SetValue(new System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>(currentKey, this[currentKey]), arrayIndex+i);
$typemap(cstype, K) currentKey = keyList[i];
array.SetValue(new System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>(currentKey, this[currentKey]), arrayIndex+i);
}
}
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>>.GetEnumerator() {
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>> System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
@ -214,24 +147,24 @@
/// 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,
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>>
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>>
{
private $csclassname collectionRef;
private System.Collections.Generic.IList<CSKEYTYPE> keyCollection;
private System.Collections.Generic.IList<$typemap(cstype, K)> keyCollection;
private int currentIndex;
private object currentObject;
private int currentSize;
public $csclassnameEnumerator($csclassname collection) {
collectionRef = collection;
keyCollection = new System.Collections.Generic.List<CSKEYTYPE>(collection.Keys);
keyCollection = new System.Collections.Generic.List<$typemap(cstype, K)>(collection.Keys);
currentIndex = -1;
currentObject = null;
currentSize = collectionRef.Count;
}
// Type-safe iterator Current
public System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE> Current {
public System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)> Current {
get {
if (currentIndex == -1)
throw new InvalidOperationException("Enumeration not started.");
@ -239,7 +172,7 @@
throw new InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new InvalidOperationException("Collection modified.");
return (System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>)currentObject;
return (System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>)currentObject;
}
}
@ -255,8 +188,8 @@
bool moveOkay = (currentIndex+1 < size) && (size == currentSize);
if (moveOkay) {
currentIndex++;
CSKEYTYPE currentKey = keyCollection[currentIndex];
currentObject = new System.Collections.Generic.KeyValuePair<CSKEYTYPE, CSVALUETYPE>(currentKey, collectionRef[currentKey]);
$typemap(cstype, K) currentKey = keyCollection[currentIndex];
currentObject = new System.Collections.Generic.KeyValuePair<$typemap(cstype, K), $typemap(cstype, T)>(currentKey, collectionRef[currentKey]);
} else {
currentObject = null;
}
@ -282,7 +215,7 @@
public:
map();
map(const map<K, T > &other);
map(const map< K, T > &other);
typedef K key_type;
typedef T mapped_type;
@ -293,7 +226,7 @@
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 >::iterator iter = $self->find(key);
if (iter != $self->end())
return iter->second;
else
@ -305,19 +238,19 @@
}
bool ContainsKey(const key_type& key) {
std::map<K, T >::iterator iter = $self->find(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);
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));
$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 >::iterator iter = $self->find(key);
if (iter != $self->end()) {
$self->erase(iter);
return true;
@ -326,15 +259,15 @@
}
// create_iterator_begin() and get_next_key() work together to provide a collection of keys to C#
%apply void *VOID_INT_PTR { std::map<K, T >::iterator *std::map<K, T >::create_iterator_begin }
%apply void *VOID_INT_PTR { std::map<K, T >::iterator *swigiterator }
%apply void *VOID_INT_PTR { std::map< K, T >::iterator *create_iterator_begin }
%apply void *VOID_INT_PTR { std::map< K, T >::iterator *swigiterator }
std::map<K, T >::iterator *create_iterator_begin() {
return new std::map<K, T >::iterator($self->begin());
std::map< K, T >::iterator *create_iterator_begin() {
return new std::map< K, T >::iterator($self->begin());
}
const key_type& get_next_key(std::map<K, T >::iterator *swigiterator) throw (std::out_of_range) {
std::map<K, T >::iterator iter = *swigiterator;
const key_type& get_next_key(std::map< K, T >::iterator *swigiterator) throw (std::out_of_range) {
std::map< K, T >::iterator iter = *swigiterator;
if (iter == $self->end()) {
delete swigiterator;
throw std::out_of_range("no more map elements");
@ -345,275 +278,32 @@
}
%csmethodmodifiers std::map<K, T >::size "private"
%csmethodmodifiers std::map<K, T >::getitem "private"
%csmethodmodifiers std::map<K, T >::setitem "private"
%csmethodmodifiers std::map<K, T >::create_iterator_begin "private"
%csmethodmodifiers std::map<K, T >::get_next_key "private"
%enddef
// Main specialization macros
%define SWIG_STD_MAP_SPECIALIZED(K, T, CSKEY, CSVAL)
namespace std {
template<> class map<K, T > {
SWIG_STD_MAP_SPECIALIZED_INTERNAL(K, T, CSKEY, CSVAL)
};
}
%enddef
%define SWIG_STD_MAP_SPECIALIZED_SIMPLE(K, T)
SWIG_STD_MAP_SPECIALIZED(K, T, K, T)
%enddef
// Old macros (deprecated)
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
#warning specialize_std_map_on_key ignored - macro is deprecated, please use SWIG_STD_MAP_MINIMAL_INTERNAL in Lib/csharp/std_map.i
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
#warning specialize_std_map_on_value ignored - macro is deprecated, please use SWIG_STD_MAP_MINIMAL_INTERNAL in Lib/csharp/std_map.i
%enddef
%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, please use SWIG_STD_MAP_MINIMAL_INTERNAL in Lib/csharp/std_map.i
%enddef
%csmethodmodifiers std::map::size "private"
%csmethodmodifiers std::map::getitem "private"
%csmethodmodifiers std::map::setitem "private"
%csmethodmodifiers std::map::create_iterator_begin "private"
%csmethodmodifiers std::map::get_next_key "private"
// Default implementation
namespace std {
template<class K, class T> class map {
SWIG_STD_MAP_MINIMAL_INTERNAL(K, T)
SWIG_STD_MAP_INTERNAL(K, T)
};
}
// specializations for built-ins
SWIG_STD_MAP_SPECIALIZED(std::string, std::string, string, string)
SWIG_STD_MAP_SPECIALIZED(std::string, bool, string, bool)
SWIG_STD_MAP_SPECIALIZED(std::string, int, string, int)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned long long, string, ulong)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned long, string, uint)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned short, string, ushort)
SWIG_STD_MAP_SPECIALIZED(std::string, long long, string, long)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned int, string, uint)
SWIG_STD_MAP_SPECIALIZED(std::string, unsigned char, string, byte)
SWIG_STD_MAP_SPECIALIZED(std::string, signed char, string, sbyte)
SWIG_STD_MAP_SPECIALIZED(std::string, double, string, double)
SWIG_STD_MAP_SPECIALIZED(std::string, short, string, short)
SWIG_STD_MAP_SPECIALIZED(std::string, float, string, float)
SWIG_STD_MAP_SPECIALIZED(std::string, char, string, char)
SWIG_STD_MAP_SPECIALIZED(std::string, long, string, int)
SWIG_STD_MAP_SPECIALIZED(bool, std::string, bool, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, int)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned long long, bool, ulong)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned long, bool, uint)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned short, bool, ushort)
SWIG_STD_MAP_SPECIALIZED(bool, long long, bool, long)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned int, bool, uint)
SWIG_STD_MAP_SPECIALIZED(bool, unsigned char, bool, byte)
SWIG_STD_MAP_SPECIALIZED(bool, signed char, bool, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(bool, char)
SWIG_STD_MAP_SPECIALIZED(bool, long, bool, int)
SWIG_STD_MAP_SPECIALIZED(int, std::string, int, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, int)
SWIG_STD_MAP_SPECIALIZED(int, unsigned long long, int, ulong)
SWIG_STD_MAP_SPECIALIZED(int, unsigned long, int, uint)
SWIG_STD_MAP_SPECIALIZED(int, unsigned short, int, ushort)
SWIG_STD_MAP_SPECIALIZED(int, long long, int, long)
SWIG_STD_MAP_SPECIALIZED(int, unsigned int, int, uint)
SWIG_STD_MAP_SPECIALIZED(int, unsigned char, int, byte)
SWIG_STD_MAP_SPECIALIZED(int, signed char, int, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(int, char)
SWIG_STD_MAP_SPECIALIZED(int, long, int, int)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, std::string, ulong, string)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, bool, ulong, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, int, ulong, int)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned long long, ulong, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned long, ulong, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned short, ulong, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, long long, ulong, long)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned int, ulong, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, unsigned char, ulong, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, signed char, ulong, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, double, ulong, double)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, short, ulong, short)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, float, ulong, float)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, char, ulong, char)
SWIG_STD_MAP_SPECIALIZED(unsigned long long, long, ulong, int)
SWIG_STD_MAP_SPECIALIZED(unsigned long, std::string, uint, string)
SWIG_STD_MAP_SPECIALIZED(unsigned long, bool, uint, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned long, int, uint, int)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned long long, uint, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned long, uint, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned short, uint, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned long, long long, uint, long)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned int, uint, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned long, unsigned char, uint, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned long, signed char, uint, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned long, double, uint, double)
SWIG_STD_MAP_SPECIALIZED(unsigned long, short, uint, short)
SWIG_STD_MAP_SPECIALIZED(unsigned long, float, uint, float)
SWIG_STD_MAP_SPECIALIZED(unsigned long, char, uint, char)
SWIG_STD_MAP_SPECIALIZED(unsigned long, long, uint, int)
SWIG_STD_MAP_SPECIALIZED(unsigned short, std::string, ushort, string)
SWIG_STD_MAP_SPECIALIZED(unsigned short, bool, ushort, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned short, int, ushort, int)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned long long, ushort, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned long, ushort, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned short, ushort, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned short, long long, ushort, long)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned int, ushort, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned short, unsigned char, ushort, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned short, signed char, ushort, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned short, double, ushort, double)
SWIG_STD_MAP_SPECIALIZED(unsigned short, short, ushort, short)
SWIG_STD_MAP_SPECIALIZED(unsigned short, float, ushort, float)
SWIG_STD_MAP_SPECIALIZED(unsigned short, char, ushort, char)
SWIG_STD_MAP_SPECIALIZED(unsigned short, long, ushort, int)
SWIG_STD_MAP_SPECIALIZED(long long, std::string, long, string)
SWIG_STD_MAP_SPECIALIZED(long long, bool, long, bool)
SWIG_STD_MAP_SPECIALIZED(long long, int, long, int)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned long long, long, ulong)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned long, long, uint)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned short, long, ushort)
SWIG_STD_MAP_SPECIALIZED(long long, long long, long, long)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned int, long, uint)
SWIG_STD_MAP_SPECIALIZED(long long, unsigned char, long, byte)
SWIG_STD_MAP_SPECIALIZED(long long, signed char, long, sbyte)
SWIG_STD_MAP_SPECIALIZED(long long, double, long, double)
SWIG_STD_MAP_SPECIALIZED(long long, short, long, short)
SWIG_STD_MAP_SPECIALIZED(long long, float, long, float)
SWIG_STD_MAP_SPECIALIZED(long long, char, long, char)
SWIG_STD_MAP_SPECIALIZED(long long, long, long, int)
SWIG_STD_MAP_SPECIALIZED(unsigned int, std::string, uint, string)
SWIG_STD_MAP_SPECIALIZED(unsigned int, bool, uint, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned int, int, uint, int)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned long long, uint, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned long, uint, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned short, uint, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned int, long long, uint, long)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned int, uint, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned int, unsigned char, uint, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned int, signed char, uint, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned int, double, uint, double)
SWIG_STD_MAP_SPECIALIZED(unsigned int, short, uint, short)
SWIG_STD_MAP_SPECIALIZED(unsigned int, float, uint, float)
SWIG_STD_MAP_SPECIALIZED(unsigned int, char, uint, char)
SWIG_STD_MAP_SPECIALIZED(unsigned int, long, uint, int)
SWIG_STD_MAP_SPECIALIZED(unsigned char, std::string, byte, string)
SWIG_STD_MAP_SPECIALIZED(unsigned char, bool, byte, bool)
SWIG_STD_MAP_SPECIALIZED(unsigned char, int, byte, int)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned long long, byte, ulong)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned long, byte, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned short, byte, ushort)
SWIG_STD_MAP_SPECIALIZED(unsigned char, long long, byte, long)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned int, byte, uint)
SWIG_STD_MAP_SPECIALIZED(unsigned char, unsigned char, byte, byte)
SWIG_STD_MAP_SPECIALIZED(unsigned char, signed char, byte, sbyte)
SWIG_STD_MAP_SPECIALIZED(unsigned char, double, byte, double)
SWIG_STD_MAP_SPECIALIZED(unsigned char, short, byte, short)
SWIG_STD_MAP_SPECIALIZED(unsigned char, float, byte, float)
SWIG_STD_MAP_SPECIALIZED(unsigned char, char, byte, char)
SWIG_STD_MAP_SPECIALIZED(unsigned char, long, byte, int)
SWIG_STD_MAP_SPECIALIZED(signed char, std::string, sbyte, string)
SWIG_STD_MAP_SPECIALIZED(signed char, bool, sbyte, bool)
SWIG_STD_MAP_SPECIALIZED(signed char, int, sbyte, int)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned long long, sbyte, ulong)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned long, sbyte, uint)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned short, sbyte, ushort)
SWIG_STD_MAP_SPECIALIZED(signed char, long long, sbyte, long)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned int, sbyte, uint)
SWIG_STD_MAP_SPECIALIZED(signed char, unsigned char, sbyte, byte)
SWIG_STD_MAP_SPECIALIZED(signed char, signed char, sbyte, sbyte)
SWIG_STD_MAP_SPECIALIZED(signed char, double, sbyte, double)
SWIG_STD_MAP_SPECIALIZED(signed char, short, sbyte, short)
SWIG_STD_MAP_SPECIALIZED(signed char, float, sbyte, float)
SWIG_STD_MAP_SPECIALIZED(signed char, char, sbyte, char)
SWIG_STD_MAP_SPECIALIZED(signed char, long, sbyte, int)
SWIG_STD_MAP_SPECIALIZED(double, std::string, double, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, int)
SWIG_STD_MAP_SPECIALIZED(double, unsigned long long, double, ulong)
SWIG_STD_MAP_SPECIALIZED(double, unsigned long, double, uint)
SWIG_STD_MAP_SPECIALIZED(double, unsigned short, double, ushort)
SWIG_STD_MAP_SPECIALIZED(double, long long, double, long)
SWIG_STD_MAP_SPECIALIZED(double, unsigned int, double, uint)
SWIG_STD_MAP_SPECIALIZED(double, unsigned char, double, byte)
SWIG_STD_MAP_SPECIALIZED(double, signed char, double, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(double, char)
SWIG_STD_MAP_SPECIALIZED(double, long, double, int)
SWIG_STD_MAP_SPECIALIZED(short, std::string, short, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, int)
SWIG_STD_MAP_SPECIALIZED(short, unsigned long long, short, ulong)
SWIG_STD_MAP_SPECIALIZED(short, unsigned long, short, uint)
SWIG_STD_MAP_SPECIALIZED(short, unsigned short, short, ushort)
SWIG_STD_MAP_SPECIALIZED(short, long long, short, long)
SWIG_STD_MAP_SPECIALIZED(short, unsigned int, short, uint)
SWIG_STD_MAP_SPECIALIZED(short, unsigned char, short, byte)
SWIG_STD_MAP_SPECIALIZED(short, signed char, short, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(short, char)
SWIG_STD_MAP_SPECIALIZED(short, long, short, int)
SWIG_STD_MAP_SPECIALIZED(float, std::string, float, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, int)
SWIG_STD_MAP_SPECIALIZED(float, unsigned long long, float, ulong)
SWIG_STD_MAP_SPECIALIZED(float, unsigned long, float, uint)
SWIG_STD_MAP_SPECIALIZED(float, unsigned short, float, ushort)
SWIG_STD_MAP_SPECIALIZED(float, long long, float, long)
SWIG_STD_MAP_SPECIALIZED(float, unsigned int, float, uint)
SWIG_STD_MAP_SPECIALIZED(float, unsigned char, float, byte)
SWIG_STD_MAP_SPECIALIZED(float, signed char, float, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(float, char)
SWIG_STD_MAP_SPECIALIZED(float, long, float, int)
SWIG_STD_MAP_SPECIALIZED(char, std::string, char, string)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, bool)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, int)
SWIG_STD_MAP_SPECIALIZED(char, unsigned long long, char, ulong)
SWIG_STD_MAP_SPECIALIZED(char, unsigned long, char, uint)
SWIG_STD_MAP_SPECIALIZED(char, unsigned short, char, ushort)
SWIG_STD_MAP_SPECIALIZED(char, long long, char, long)
SWIG_STD_MAP_SPECIALIZED(char, unsigned int, char, uint)
SWIG_STD_MAP_SPECIALIZED(char, unsigned char, char, byte)
SWIG_STD_MAP_SPECIALIZED(char, signed char, char, sbyte)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, double)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, short)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, float)
SWIG_STD_MAP_SPECIALIZED_SIMPLE(char, char)
SWIG_STD_MAP_SPECIALIZED(char, long, char, int)
SWIG_STD_MAP_SPECIALIZED(long, std::string, int, string)
SWIG_STD_MAP_SPECIALIZED(long, bool, int, bool)
SWIG_STD_MAP_SPECIALIZED(long, int, int, int)
SWIG_STD_MAP_SPECIALIZED(long, unsigned long long, int, ulong)
SWIG_STD_MAP_SPECIALIZED(long, unsigned long, int, uint)
SWIG_STD_MAP_SPECIALIZED(long, unsigned short, int, ushort)
SWIG_STD_MAP_SPECIALIZED(long, long long, int, long)
SWIG_STD_MAP_SPECIALIZED(long, unsigned int, int, uint)
SWIG_STD_MAP_SPECIALIZED(long, unsigned char, int, byte)
SWIG_STD_MAP_SPECIALIZED(long, signed char, int, sbyte)
SWIG_STD_MAP_SPECIALIZED(long, double, int, double)
SWIG_STD_MAP_SPECIALIZED(long, short, int, short)
SWIG_STD_MAP_SPECIALIZED(long, float, int, float)
SWIG_STD_MAP_SPECIALIZED(long, char, int, char)
SWIG_STD_MAP_SPECIALIZED(long, long, int, int)
// add specializations here
// Legacy macros (deprecated)
%define specialize_std_map_on_key(K,CHECK,CONVERT_FROM,CONVERT_TO)
#warning specialize_std_map_on_key ignored - macro is deprecated and no longer necessary
%enddef
%define specialize_std_map_on_value(T,CHECK,CONVERT_FROM,CONVERT_TO)
#warning specialize_std_map_on_value ignored - macro is deprecated and no longer necessary
%enddef
%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

View file

@ -1,23 +1,20 @@
/* -----------------------------------------------------------------------------
* std_vector.i
*
* SWIG typemaps for std::vector
* SWIG typemaps for std::vector<T>
* C# implementation
* 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>;
* made to look and feel like a typesafe C# System.Collections.ArrayList.
*
* Note that IEnumerable<> is implemented in the proxy class which is useful for using LINQ with
* C++ std::vector wrappers. IEnumerable<> is replaced by IList<> wherever we are confident that the
* required C++ operator== is available for correct compilation.
* C++ std::vector wrappers. The IList<> interface is also implemented to provide enhanced functionality
* whenever we are confident that the required C++ operator== is available. This is the case for when
* T is a primitive type or a pointer. If T does define an operator==, then use the SWIG_STD_VECTOR_ENHANCED
* macro to obtain this enhanced functionality, for example:
*
* SWIG_STD_VECTOR_ENHANCED(SomeNamespace::Klass)
* %template(VectKlass) std::vector<SomeNamespace::Klass>;
*
* Warning: heavy macro usage in this file. Use swig -E to get a sane view on the real file contents!
* ----------------------------------------------------------------------------- */
@ -28,14 +25,13 @@
%include <std_common.i>
// 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_INTERNAL(CSINTERFACE, CONST_REFERENCE_TYPE, CSTYPE, CTYPE...)
%typemap(csinterfaces) std::vector<CTYPE > "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.CSINTERFACE<CSTYPE>\n#endif\n";
%define SWIG_STD_VECTOR_MINIMUM_INTERNAL(CSINTERFACE, CONST_REFERENCE_TYPE, CTYPE...)
%typemap(csinterfaces) std::vector<CTYPE > "IDisposable, System.Collections.IEnumerable\n#if !SWIG_DOTNET_1\n , System.Collections.Generic.CSINTERFACE<$typemap(cstype, CTYPE)>\n#endif\n";
%typemap(cscode) std::vector<CTYPE > %{
public $csclassname(System.Collections.ICollection c) : this() {
if (c == null)
throw new ArgumentNullException("c");
foreach (CSTYPE element in c) {
foreach ($typemap(cstype, CTYPE) element in c) {
this.Add(element);
}
}
@ -52,7 +48,7 @@
}
}
public CSTYPE this[int index] {
public $typemap(cstype, CTYPE) this[int index] {
get {
return getitem(index);
}
@ -87,7 +83,7 @@
#if SWIG_DOTNET_1
public void CopyTo(System.Array array)
#else
public void CopyTo(CSTYPE[] array)
public void CopyTo($typemap(cstype, CTYPE)[] array)
#endif
{
CopyTo(0, array, 0, this.Count);
@ -96,7 +92,7 @@
#if SWIG_DOTNET_1
public void CopyTo(System.Array array, int arrayIndex)
#else
public void CopyTo(CSTYPE[] array, int arrayIndex)
public void CopyTo($typemap(cstype, CTYPE)[] array, int arrayIndex)
#endif
{
CopyTo(0, array, arrayIndex, this.Count);
@ -105,7 +101,7 @@
#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)
public void CopyTo(int index, $typemap(cstype, CTYPE)[] array, int arrayIndex, int count)
#endif
{
if (array == null)
@ -125,7 +121,7 @@
}
#if !SWIG_DOTNET_1
System.Collections.Generic.IEnumerator<CSTYPE> System.Collections.Generic.IEnumerable<CSTYPE>.GetEnumerator() {
System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)> System.Collections.Generic.IEnumerable<$typemap(cstype, CTYPE)>.GetEnumerator() {
return new $csclassnameEnumerator(this);
}
#endif
@ -145,7 +141,7 @@
/// tricky to detect unmanaged code that modifies the collection under our feet.
public sealed class $csclassnameEnumerator : System.Collections.IEnumerator
#if !SWIG_DOTNET_1
, System.Collections.Generic.IEnumerator<CSTYPE>
, System.Collections.Generic.IEnumerator<$typemap(cstype, CTYPE)>
#endif
{
private $csclassname collectionRef;
@ -161,7 +157,7 @@
}
// Type-safe iterator Current
public CSTYPE Current {
public $typemap(cstype, CTYPE) Current {
get {
if (currentIndex == -1)
throw new InvalidOperationException("Enumeration not started.");
@ -169,7 +165,7 @@
throw new InvalidOperationException("Enumeration finished.");
if (currentObject == null)
throw new InvalidOperationException("Collection modified.");
return (CSTYPE)currentObject;
return ($typemap(cstype, CTYPE))currentObject;
}
}
@ -323,14 +319,13 @@
}
%enddef
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, const value_type&, CSTYPE, CTYPE)
%define SWIG_STD_VECTOR_MINIMUM(CTYPE...)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, const value_type&, 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...)
%define SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE...)
%extend {
bool Contains(const value_type& value) {
return std::find($self->begin(), $self->end(), value) != $self->end();
@ -360,23 +355,24 @@ SWIG_STD_VECTOR_MINIMUM_INTERNAL(IEnumerable, const value_type&, CSTYPE, CTYPE)
}
%enddef
// Macros for std::vector class specializations
// CSTYPE and CTYPE respectively correspond to the types in the cstype and ctype typemaps
%define SWIG_STD_VECTOR_SPECIALIZE(CSTYPE, CTYPE...)
// Macros for std::vector class specializations/enhancements
%define SWIG_STD_VECTOR_ENHANCED(CTYPE...)
namespace std {
template<> class vector<CTYPE > {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, CSTYPE, CTYPE)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CSTYPE, CTYPE)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, CTYPE)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(CTYPE)
};
}
%enddef
// Legacy macros
%define SWIG_STD_VECTOR_SPECIALIZE(CSTYPE, CTYPE...)
#warning SWIG_STD_VECTOR_SPECIALIZE macro deprecated, please see csharp/std_vector.i and switch to SWIG_STD_VECTOR_ENHANCED
SWIG_STD_VECTOR_ENHANCED(CTYPE)
%enddef
%define SWIG_STD_VECTOR_SPECIALIZE_MINIMUM(CSTYPE, CTYPE...)
namespace std {
template<> class vector<CTYPE > {
SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE)
};
}
#warning SWIG_STD_VECTOR_SPECIALIZE_MINIMUM macro deprecated, it is no longer required
%enddef
%{
@ -396,36 +392,38 @@ namespace std {
// primary (unspecialized) class template for std::vector
// does not require operator== to be defined
template<class T> class vector {
SWIG_STD_VECTOR_MINIMUM(T, T)
SWIG_STD_VECTOR_MINIMUM(T)
};
// specializations for pointers
template<class T> class vector<T*> {
SWIG_STD_VECTOR_MINIMUM(T, T*)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, T*)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(T*)
};
template<class T> class vector<const T*> {
SWIG_STD_VECTOR_MINIMUM(T, const T*)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, const value_type&, const T*)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(const T*)
};
// bool is a bit different in the C++ standard
template<> class vector<bool> {
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, bool, bool, bool)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool, bool)
SWIG_STD_VECTOR_MINIMUM_INTERNAL(IList, bool, bool)
SWIG_STD_VECTOR_EXTRA_OP_EQUALS_EQUALS(bool)
};
}
// template specializations for std::vector
// these provide extra collections methods as operator== is defined
SWIG_STD_VECTOR_SPECIALIZE(char, char)
SWIG_STD_VECTOR_SPECIALIZE(sbyte, signed char)
SWIG_STD_VECTOR_SPECIALIZE(byte, unsigned char)
SWIG_STD_VECTOR_SPECIALIZE(short, short)
SWIG_STD_VECTOR_SPECIALIZE(ushort, unsigned short)
SWIG_STD_VECTOR_SPECIALIZE(int, int)
SWIG_STD_VECTOR_SPECIALIZE(uint, unsigned int)
SWIG_STD_VECTOR_SPECIALIZE(int, long)
SWIG_STD_VECTOR_SPECIALIZE(uint, unsigned long)
SWIG_STD_VECTOR_SPECIALIZE(long, long long)
SWIG_STD_VECTOR_SPECIALIZE(ulong, unsigned long long)
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>
SWIG_STD_VECTOR_ENHANCED(char)
SWIG_STD_VECTOR_ENHANCED(signed char)
SWIG_STD_VECTOR_ENHANCED(unsigned char)
SWIG_STD_VECTOR_ENHANCED(short)
SWIG_STD_VECTOR_ENHANCED(unsigned short)
SWIG_STD_VECTOR_ENHANCED(int)
SWIG_STD_VECTOR_ENHANCED(unsigned int)
SWIG_STD_VECTOR_ENHANCED(long)
SWIG_STD_VECTOR_ENHANCED(unsigned long)
SWIG_STD_VECTOR_ENHANCED(long long)
SWIG_STD_VECTOR_ENHANCED(unsigned long long)
SWIG_STD_VECTOR_ENHANCED(float)
SWIG_STD_VECTOR_ENHANCED(double)
SWIG_STD_VECTOR_ENHANCED(std::string) // also requires a %include <std_string.i>

View file

@ -259,9 +259,15 @@ SWIGINTERN void SWIG_CSharpException(int code, const char *msg) {
/* rethrow the unknown exception */
#ifdef SWIGCSHARP
%typemap(throws,noblock=1, canthrow=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
#else
%typemap(throws,noblock=1) (...) {
SWIG_exception(SWIG_RuntimeError,"unknown exception");
}
#endif
#endif /* __cplusplus */

View file

@ -1,13 +1,16 @@
%include <intrusive_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_INTRUSIVE_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_INTRUSIVE_PTR_QNAMESPACE::intrusive_ptr< CONST TYPE >;
// destructor mods
// destructor wrapper customisation
%feature("unref") TYPE "(void)arg1; delete smartarg1;"
// Typemap customisations...
%typemap(in) CONST TYPE ($&1_type argp = 0, SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE > *smartarg = 0) %{
// plain value

View file

@ -1,15 +1,18 @@
%include <shared_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
// destructor wrapper customisation
%feature("unref") TYPE
//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
"(void)arg1; delete smartarg1;"
// Typemap customisations...
// plain value
%typemap(in) CONST TYPE ($&1_type argp = 0) %{

View file

@ -76,7 +76,7 @@ typedef struct {
/* this is the struct for wrapping arbitary packed binary data
(currently it is only used for member function pointers)
the data ordering is similar to swig_lua_userdata, but it is currently not possible
to tell the two structures apart within Swig, other than by looking at the type
to tell the two structures apart within SWIG, other than by looking at the type
*/
typedef struct {
swig_type_info *type;

View file

@ -1,17 +1,22 @@
%include <shared_ptr.i>
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
// destructor wrapper customisation
%feature("unref") TYPE
//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
"(void)arg1; delete smartarg1;"
// Feature to adapt the code generated in the swigregister functions for smart pointers
%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
// Typemap customisations...
// plain value
%typemap(in) CONST TYPE (void *argp, int res = 0) {
int newmem = 0;

View file

@ -1,4 +1,18 @@
#include <octave/version.h>
#ifndef OCTAVE_API_VERSION_NUMBER
// Hack to distinguish between Octave 3.2 and earlier versions before OCTAVE_API_VERSION_NUMBER existed
#define ComplexLU __ignore
#include <octave/CmplxLU.h>
#undef ComplexLU
#ifdef octave_Complex_LU_h
# define OCTAVE_API_VERSION_NUMBER 36
#else
# define OCTAVE_API_VERSION_NUMBER 37
#endif
#endif
SWIGRUNTIME bool SWIG_check_num_args(const char *func_name, int num_args, int max_args, int min_args, int varargs) {
if (num_args > max_args && !varargs)
@ -105,27 +119,35 @@ namespace Swig {
typedef std::map < void *, Director * > rtdir_map;
SWIGINTERN rtdir_map &get_rtdir_map() {
SWIGINTERN rtdir_map* get_rtdir_map() {
static swig_module_info *module = 0;
if (!module)
module = SWIG_GetModule(0);
assert(module);
if (!module)
return 0;
if (!module->clientdata)
module->clientdata = new rtdir_map;
return *(rtdir_map *) module->clientdata;
return (rtdir_map *) module->clientdata;
}
SWIGINTERNINLINE void set_rtdir(void *vptr, Director *d) {
get_rtdir_map()[vptr] = d;
rtdir_map* rm = get_rtdir_map();
if (rm)
(*rm)[vptr] = d;
}
SWIGINTERNINLINE void erase_rtdir(void *vptr) {
get_rtdir_map().erase(vptr);
rtdir_map* rm = get_rtdir_map();
if (rm)
(*rm).erase(vptr);
}
SWIGINTERNINLINE Director *get_rtdir(void *vptr) {
rtdir_map::const_iterator pos = get_rtdir_map().find(vptr);
Director *rtdir = (pos != get_rtdir_map().end())? pos->second : 0;
rtdir_map* rm = get_rtdir_map();
if (!rm)
return 0;
rtdir_map::const_iterator pos = rm->find(vptr);
Director *rtdir = (pos != rm->end())? pos->second : 0;
return rtdir;
}
}
@ -439,9 +461,15 @@ namespace Swig {
install_builtin_function(it->second.first->method, it->first,
it->second.first->doc?it->second.first->doc:std::string());
else if (it->second.second.is_defined()) {
#if OCTAVE_API_VERSION_NUMBER<37
link_to_global_variable(curr_sym_tab->lookup(it->first, true));
#else
symbol_table::varref(it->first);
symbol_table::mark_global(it->first);
#endif
set_global_value(it->first, it->second.second);
#if OCTAVE_API_VERSION_NUMBER<37
octave_swig_type *ost = Swig::swig_value_deref(it->second.second);
if (ost) {
const char* h = ost->help_text();
@ -450,6 +478,7 @@ namespace Swig {
sr->document(h);
}
}
#endif
}
}
}
@ -1352,6 +1381,11 @@ SWIGRUNTIME swig_module_info *SWIG_Octave_GetModule(void *clientdata) {
SWIGRUNTIME void SWIG_Octave_SetModule(void *clientdata, swig_module_info *pointer) {
octave_value ov = new octave_swig_packed(0, &pointer, sizeof(swig_module_info *));
const char *module_var = "__SWIG_MODULE__" SWIG_TYPE_TABLE_NAME SWIG_RUNTIME_VERSION;
#if OCTAVE_API_VERSION_NUMBER<37
link_to_global_variable(curr_sym_tab->lookup(module_var, true));
#else
symbol_table::varref(module_var);
symbol_table::mark_global(module_var);
#endif
set_global_value(module_var, ov);
}

View file

@ -72,11 +72,33 @@ DEFUN_DLD (SWIG_name,args,nargout,SWIG_name_d) {
module_ns->install_global();
module_ns->decref();
#if OCTAVE_API_VERSION_NUMBER<37
link_to_global_variable(curr_sym_tab->lookup(SWIG_name_d,true));
#else
symbol_table::varref(SWIG_name_d);
symbol_table::mark_global(SWIG_name_d);
#endif
set_global_value(SWIG_name_d,Swig::swig_value_ref(module_ns));
#if OCTAVE_API_VERSION_NUMBER>=37
mlock();
#endif
return octave_value_list();
}
// workaround bug in octave where installing global variable of custom type and then
// exiting without explicitly clearing the variable causes octave to segfault.
#if OCTAVE_API_VERSION_NUMBER>=37
struct oct_file_unload {
~oct_file_unload() {
string_vector vars = symbol_table::global_variable_names();
for (int i = 0; i < vars.length(); i++)
symbol_table::clear_global(vars[i]);
}
};
static oct_file_unload __unload;
#endif
%}

View file

@ -32,7 +32,7 @@
#define SWIG_SetConstant(name, obj) SWIG_Octave_SetConstant(module_ns,name,obj)
// raise
#define SWIG_Octave_Raise(obj, type, desc) error("c++-side threw an exception")
#define SWIG_Octave_Raise(OBJ, TYPE, DESC) error("C++ side threw an exception of type " TYPE)
#define SWIG_Raise(obj, type, desc) SWIG_Octave_Raise(obj, type, desc)
// Include the unified typemap library

View file

@ -7,6 +7,9 @@
#ifdef do_close
#undef do_close
#endif
#ifdef do_exec
#undef do_exec
#endif
#ifdef scalar
#undef scalar
#endif

View file

@ -18,6 +18,7 @@
/* for raw pointers */
#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags)
#define SWIG_ConvertPtrAndOwn(obj, pp, type, flags,own) SWIG_Perl_ConvertPtrAndOwn(SWIG_PERL_OBJECT_CALL obj, pp, type, flags, own)
#define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags)
/* for raw packed data */
@ -234,10 +235,14 @@ SWIG_TypeProxyCheck(const char *c, swig_type_info *ty) {
/* Function for getting a pointer value */
SWIGRUNTIME int
SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) {
SWIG_Perl_ConvertPtrAndOwn(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags, int *own) {
swig_cast_info *tc;
void *voidptr = (void *)0;
SV *tsv = 0;
if (own)
*own = 0;
/* If magical, apply more magic */
if (SvGMAGICAL(sv))
mg_get(sv);
@ -287,7 +292,11 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *
{
int newmemory = 0;
*ptr = SWIG_TypeCast(tc,voidptr,&newmemory);
assert(!newmemory); /* newmemory handling not yet implemented */
if (newmemory == SWIG_CAST_NEW_MEMORY) {
assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
if (own)
*own = *own | SWIG_CAST_NEW_MEMORY;
}
}
} else {
*ptr = voidptr;
@ -302,7 +311,7 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *
*/
SV *obj = sv;
HV *stash = SvSTASH(SvRV(obj));
GV *gv = *(GV**) hv_fetch(stash, "OWNER", 5, TRUE);
GV *gv = *(GV**)hv_fetch(stash, "OWNER", 5, TRUE);
if (isGV(gv)) {
HV *hv = GvHVn(gv);
/*
@ -317,9 +326,14 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *
return SWIG_OK;
}
SWIGRUNTIME int
SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) {
return SWIG_Perl_ConvertPtrAndOwn(sv, ptr, _t, flags, 0);
}
SWIGRUNTIME void
SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) {
if (ptr && (flags & SWIG_SHADOW)) {
if (ptr && (flags & (SWIG_SHADOW | SWIG_POINTER_OWN))) {
SV *self;
SV *obj=newSV(0);
HV *hash=newHV();
@ -328,7 +342,7 @@ SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, i
stash=SvSTASH(SvRV(obj));
if (flags & SWIG_POINTER_OWN) {
HV *hv;
GV *gv=*(GV**)hv_fetch(stash, "OWNER", 5, TRUE);
GV *gv = *(GV**)hv_fetch(stash, "OWNER", 5, TRUE);
if (!isGV(gv))
gv_init(gv, stash, "OWNER", 5, FALSE);
hv=GvHVn(gv);

View file

@ -199,6 +199,35 @@ as follows :
$1 = &dvalue;
}
%typemap(typecheck) int *REFERENCE, int &REFERENCE,
short *REFERENCE, short &REFERENCE,
long *REFERENCE, long &REFERENCE,
signed char *REFERENCE, signed char &REFERENCE,
bool *REFERENCE, bool &REFERENCE
{
$1 = SvROK($input) && SvIOK(SvRV($input));
}
%typemap(typecheck) double *REFERENCE, double &REFERENCE,
float *REFERENCE, float &REFERENCE
{
$1 = SvROK($input);
if($1) {
SV *tmpsv = SvRV($input);
$1 = SvNOK(tmpsv) || SvIOK(tmpsv);
}
}
%typemap(typecheck) unsigned int *REFERENCE, unsigned int &REFERENCE,
unsigned short *REFERENCE, unsigned short &REFERENCE,
unsigned long *REFERENCE, unsigned long &REFERENCE,
unsigned char *REFERENCE, unsigned char &REFERENCE
{
$1 = SvROK($input);
if($1) {
SV *tmpsv = SvRV($input);
$1 = SvUOK(tmpsv) || SvIOK(tmpsv);
}
}
%typemap(argout) double *REFERENCE, double &REFERENCE,
float *REFERENCE, float &REFERENCE
{
@ -211,7 +240,7 @@ as follows :
%typemap(argout) int *REFERENCE, int &REFERENCE,
short *REFERENCE, short &REFERENCE,
long *REFERENCE, long &REFERENCE,
signed char *REFERENCE, unsigned char &REFERENCE,
signed char *REFERENCE, signed char &REFERENCE,
bool *REFERENCE, bool &REFERENCE
{
SV *tempsv;

View file

@ -48,3 +48,6 @@
c.module_number = module_number;
zend_register_constant( &c TSRMLS_CC );
}
/* Handled as a global variable. */
%typemap(consttab) SWIGTYPE (CLASS::*) "";

198
Lib/php/director.swg Normal file
View file

@ -0,0 +1,198 @@
/* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution
* of SWIG, and the README file for authors - http://www.swig.org/release.html.
*
* director.swg
*
* This file contains support for director classes that proxy
* method calls from C++ to PHP extensions.
* ----------------------------------------------------------------------------- */
#ifndef SWIG_DIRECTOR_PHP_HEADER_
#define SWIG_DIRECTOR_PHP_HEADER_
#ifdef __cplusplus
#include <string>
#include <map>
/*
Use -DSWIG_DIRECTOR_STATIC if you prefer to avoid the use of the
'Swig' namespace. This could be useful for multi-modules projects.
*/
#ifdef SWIG_DIRECTOR_STATIC
/* Force anonymous (static) namespace */
#define Swig
#endif
namespace Swig {
/* memory handler */
struct GCItem
{
virtual ~GCItem() {}
virtual int get_own() const
{
return 0;
}
};
struct GCItem_var
{
GCItem_var(GCItem *item = 0) : _item(item)
{
}
GCItem_var& operator=(GCItem *item)
{
GCItem *tmp = _item;
_item = item;
delete tmp;
return *this;
}
~GCItem_var()
{
delete _item;
}
GCItem * operator->() const
{
return _item;
}
private:
GCItem *_item;
};
struct GCItem_Object : GCItem
{
GCItem_Object(int own) : _own(own)
{
}
virtual ~GCItem_Object()
{
}
int get_own() const
{
return _own;
}
private:
int _own;
};
template <typename Type>
struct GCItem_T : GCItem
{
GCItem_T(Type *ptr) : _ptr(ptr)
{
}
virtual ~GCItem_T()
{
delete _ptr;
}
private:
Type *_ptr;
};
class Director {
protected:
zval *swig_self;
typedef std::map<void*, GCItem_var> ownership_map;
mutable ownership_map owner;
public:
Director(zval* self) : swig_self(self) {
}
~Director() {
for (ownership_map::iterator i = owner.begin(); i != owner.end(); i++) {
owner.erase(i);
}
}
bool is_overriden_method(char *cname, char *lc_fname) {
zval classname;
zend_class_entry **ce;
zend_function *mptr;
int name_len = strlen(lc_fname);
ZVAL_STRING(&classname, cname, 0);
if (zend_lookup_class(Z_STRVAL_P(&classname), Z_STRLEN_P(&classname), &ce TSRMLS_CC) != SUCCESS) {
return false;
}
if (zend_hash_find(&(*ce)->function_table, lc_fname, name_len + 1, (void**) &mptr) != SUCCESS) {
return false;
}
// common.scope points to the declaring class
return strcmp(mptr->common.scope->name, cname);
}
template <typename Type>
void swig_acquire_ownership(Type *vptr) const
{
if (vptr) {
owner[vptr] = new GCItem_T<Type>(vptr);
}
}
};
/* base class for director exceptions */
class DirectorException {
protected:
std::string swig_msg;
public:
DirectorException(int code, const char *hdr, const char* msg)
: swig_msg(hdr)
{
if (strlen(msg)) {
swig_msg += " ";
swig_msg += msg;
}
SWIG_ErrorCode() = code;
SWIG_ErrorMsg() = swig_msg.c_str();
}
static void raise(int code, const char *hdr, const char* msg)
{
throw DirectorException(code, hdr, msg);
}
};
/* attempt to call a pure virtual method via a director method */
class DirectorPureVirtualException : public Swig::DirectorException
{
public:
DirectorPureVirtualException(const char* msg)
: DirectorException(E_ERROR, "SWIG director pure virtual method called", msg)
{
}
static void raise(const char *msg)
{
throw DirectorPureVirtualException(msg);
}
};
/* any php exception that occurs during a director method call */
class DirectorMethodException : public Swig::DirectorException
{
public:
DirectorMethodException(const char* msg = "")
: DirectorException(E_ERROR, "SWIG director method error", msg)
{
}
static void raise(const char *msg)
{
throw DirectorMethodException(msg);
}
};
}
#endif /* __cplusplus */
#endif

109
Lib/php/factory.i Normal file
View file

@ -0,0 +1,109 @@
/*
Implement a more natural wrap for factory methods, for example, if
you have:
---- geometry.h --------
struct Geometry {
enum GeomType{
POINT,
CIRCLE
};
virtual ~Geometry() {}
virtual int draw() = 0;
//
// Factory method for all the Geometry objects
//
static Geometry *create(GeomType i);
};
struct Point : Geometry {
int draw() { return 1; }
double width() { return 1.0; }
};
struct Circle : Geometry {
int draw() { return 2; }
double radius() { return 1.5; }
};
//
// Factory method for all the Geometry objects
//
Geometry *Geometry::create(GeomType type) {
switch (type) {
case POINT: return new Point();
case CIRCLE: return new Circle();
default: return 0;
}
}
---- geometry.h --------
You can use the %factory with the Geometry::create method as follows:
%newobject Geometry::create;
%factory(Geometry *Geometry::create, Point, Circle);
%include "geometry.h"
and Geometry::create will return a 'Point' or 'Circle' instance
instead of the plain 'Geometry' type. For example, in python:
circle = Geometry.create(Geometry.CIRCLE)
r = circle.radius()
where circle is a Circle proxy instance.
NOTES: remember to fully qualify all the type names and don't
use %factory inside a namespace declaration, ie, instead of
namespace Foo {
%factory(Geometry *Geometry::create, Point, Circle);
}
use
%factory(Foo::Geometry *Foo::Geometry::create, Foo::Point, Foo::Circle);
*/
/* for loop for macro with one argument */
%define %_formacro_1(macro, arg1,...)macro(arg1)
#if #__VA_ARGS__ != "__fordone__"
%_formacro_1(macro, __VA_ARGS__)
#endif
%enddef
/* for loop for macro with one argument */
%define %formacro_1(macro,...)%_formacro_1(macro,__VA_ARGS__,__fordone__)%enddef
%define %formacro(macro,...)%_formacro_1(macro,__VA_ARGS__,__fordone__)%enddef
/* for loop for macro with two arguments */
%define %_formacro_2(macro, arg1, arg2, ...)macro(arg1, arg2)
#if #__VA_ARGS__ != "__fordone__"
%_formacro_2(macro, __VA_ARGS__)
#endif
%enddef
/* for loop for macro with two arguments */
%define %formacro_2(macro,...)%_formacro_2(macro, __VA_ARGS__, __fordone__)%enddef
%define %_factory_dispatch(Type)
if (!dcast) {
Type *dobj = dynamic_cast<Type *>($1);
if (dobj) {
dcast = 1;
SWIG_SetPointerZval(return_value, SWIG_as_voidptr(dobj),$descriptor(Type *), $owner);
}
}%enddef
%define %factory(Method,Types...)
%typemap(out) Method {
int dcast = 0;
%formacro(%_factory_dispatch, Types)
if (!dcast) {
SWIG_SetPointerZval(return_value, SWIG_as_voidptr($1),$descriptor, $owner);
}
}%enddef

View file

@ -102,6 +102,16 @@
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&z_var, sizeof(zval *), NULL);
}
%typemap(varinit) SWIGTYPE (CLASS::*)
{
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
zval * resource;
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr);
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
}
%typemap(varin) int, unsigned int, short, unsigned short, long, unsigned long, signed char, unsigned char, enum SWIGTYPE
{
zval **z_var;
@ -213,6 +223,15 @@
$1 = ($1_ltype)_temp;
}
%typemap(varin) SWIGTYPE (CLASS::*)
{
zval **z_var;
zend_hash_find(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void**)&z_var);
void * p = (void*)zend_fetch_resource(*z_var TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, le_member_ptr);
memcpy(&$1, p, sizeof($1));
}
%typemap(varout) int,
unsigned int,
unsigned short,
@ -325,4 +344,12 @@ deliberate error cos this code looks bogus to me
SWIG_SetPointerZval(*z_var, (void*)$1, $1_descriptor, 0);
}
%typemap(varout) SWIGTYPE (CLASS::*)
{
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
zval * resource;
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr);
zend_hash_add(&EG(symbol_table), (char*)"$1", sizeof("$1"), (void*)&resource, sizeof(zval *), NULL);
}

View file

@ -52,6 +52,10 @@
%pass_by_val(long, CONVERT_INT_IN);
%pass_by_val(unsigned long, CONVERT_INT_IN);
%pass_by_val(signed long long, CONVERT_LONG_LONG_IN);
%pass_by_val(long long, CONVERT_LONG_LONG_IN);
%pass_by_val(unsigned long long, CONVERT_UNSIGNED_LONG_LONG_IN);
%pass_by_val(signed char, CONVERT_INT_IN);
%pass_by_val(char, CONVERT_CHAR_IN);
%pass_by_val(unsigned char, CONVERT_INT_IN);
@ -61,6 +65,8 @@
%pass_by_val(double, CONVERT_FLOAT_IN);
%pass_by_val(char *, CONVERT_STRING_IN);
%typemap(in) char *& = const char *&;
%typemap(directorout) char *& = const char *&;
// char array can be in/out, though the passed string may not be big enough...
// so we have to size it
@ -86,6 +92,14 @@
$1 = *tmp;
}
%typemap(directorout) SWIGTYPE ($&1_ltype tmp)
{
if(SWIG_ConvertPtr(*$input, (void **) &tmp, $&1_descriptor, 0) < 0 || tmp == NULL) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $&1_descriptor");
}
$result = *tmp;
}
%typemap(in) SWIGTYPE *,
SWIGTYPE []
{
@ -101,6 +115,14 @@
}
}
%typemap(in) SWIGTYPE *& ($*ltype temp)
{
if(SWIG_ConvertPtr(*$input, (void **) &temp, $*1_descriptor, 0) < 0) {
SWIG_PHP_Error(E_ERROR, "Type error in argument $argnum of $symname. Expected $*1_descriptor");
}
$1 = &temp;
}
%typemap(in) SWIGTYPE *DISOWN
{
if(SWIG_ConvertPtr(*$input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN ) < 0) {
@ -173,22 +195,124 @@
ZVAL_LONG(return_value,$1);
}
%typemap(out) long long
%{
if ((long long)LONG_MIN <= $1 && $1 <= (long long)LONG_MAX) {
return_value->value.lval = (long)($1);
return_value->type = IS_LONG;
} else {
char temp[256];
sprintf(temp, "%lld", $1);
ZVAL_STRING(return_value, temp, 1);
}
%}
%typemap(out) unsigned long long
%{
if ($1 <= (unsigned long long)LONG_MAX) {
return_value->value.lval = (long)($1);
return_value->type = IS_LONG;
} else {
char temp[256];
sprintf(temp, "%llu", $1);
ZVAL_STRING(return_value, temp, 1);
}
%}
%typemap(out) const int &,
const unsigned int &,
const short &,
const unsigned short &,
const long &,
const unsigned long &,
const signed char &,
const unsigned char &,
const bool &,
const size_t &,
const enum SWIGTYPE &
{
ZVAL_LONG(return_value,*$1);
}
%typemap(out) const long long &
%{
if ((long long)LONG_MIN <= *$1 && *$1 <= (long long)LONG_MAX) {
return_value->value.lval = (long)(*$1);
return_value->type = IS_LONG;
} else {
char temp[256];
sprintf(temp, "%lld", *$1);
ZVAL_STRING(return_value, temp, 1);
}
%}
%typemap(out) const unsigned long long &
%{
if (*$1 <= (unsigned long long)LONG_MAX) {
return_value->value.lval = (long)(*$1);
return_value->type = IS_LONG;
} else {
char temp[256];
sprintf(temp, "%llu", *$1);
ZVAL_STRING(return_value, temp, 1);
}
%}
%typemap(directorin) int,
unsigned int,
short,
unsigned short,
long,
unsigned long,
signed char,
unsigned char,
size_t,
enum SWIGTYPE
{
ZVAL_LONG($input,$1_name);
}
%typemap(out) bool
{
ZVAL_BOOL(return_value,($1)?1:0);
}
%typemap(out) const bool &
{
ZVAL_BOOL(return_value,(*$1)?1:0);
}
%typemap(directorin) bool
{
ZVAL_BOOL($input,($1_name)?1:0);
}
%typemap(out) float,
double
{
ZVAL_DOUBLE(return_value,$1);
}
%typemap(out) const float &,
const double &
{
ZVAL_DOUBLE(return_value,*$1);
}
%typemap(directorin) float,
double
{
ZVAL_DOUBLE($input,$1_name);
}
%typemap(out) char
{
ZVAL_STRINGL(return_value,&$1, 1, 1);
}
%typemap(out) const char &
{
ZVAL_STRINGL(return_value,&*$1, 1, 1);
}
%typemap(out) char *,
char []
{
@ -199,6 +323,15 @@
}
}
%typemap(out) char *&
{
if(!*$1) {
ZVAL_NULL(return_value);
} else {
ZVAL_STRING(return_value, (char *)*$1, 1);
}
}
%typemap(out) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
@ -206,6 +339,35 @@
SWIG_SetPointerZval(return_value, (void *)$1, $1_descriptor, $owner);
%}
%typemap(out) SWIGTYPE *&
%{
SWIG_SetPointerZval(return_value, (void *)*$1, $*1_descriptor, $owner);
%}
%typemap(directorin) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
%{
SWIG_SetPointerZval($input, (void *)&$1_name, $1_descriptor, $owner);
%}
%typemap(out) SWIGTYPE (CLASS::*)
{
void * p = emalloc(sizeof($1));
memcpy(p, &$1, sizeof($1));
zval * resource;
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, p, le_member_ptr);
SWIG_SetPointerZval(return_value, (void *)&$1, $1_descriptor, $owner);
}
%typemap(in) SWIGTYPE (CLASS::*)
{
void * p = (void*)zend_fetch_resource($input TSRMLS_CC, -1, SWIG_MEMBER_PTR, NULL, 1, le_member_ptr);
memcpy(&$1, p, sizeof($1));
}
%typemap(out) SWIGTYPE *DYNAMIC,
SWIGTYPE &DYNAMIC
{
@ -227,6 +389,15 @@
}
#endif
%typemap(directorin) SWIGTYPE
{
SWIG_SetPointerZval($input, SWIG_as_voidptr(&$1_name), $&1_descriptor, 2);
}
/* Array reference typemaps */
%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
%typemap(out) void "";
%typemap(out) char [ANY]
@ -240,7 +411,7 @@
// an argument to be converted from a different PHP type, you must convert
// it yourself before passing it (e.g. (string)4.7 or (int)"6").
%define %php_typecheck(_type,_prec,is)
%typemap(typecheck,precedence=_prec) _type
%typemap(typecheck,precedence=_prec) _type, const _type &
" $1 = (Z_TYPE_PP($input) == is); "
%enddef
@ -250,18 +421,19 @@
%php_typecheck(unsigned short,SWIG_TYPECHECK_UINT16,IS_LONG)
%php_typecheck(long,SWIG_TYPECHECK_INT64,IS_LONG)
%php_typecheck(unsigned long,SWIG_TYPECHECK_UINT64,IS_LONG)
%php_typecheck(long long,SWIG_TYPECHECK_INT64,IS_LONG)
%php_typecheck(unsigned long long,SWIG_TYPECHECK_UINT64,IS_LONG)
%php_typecheck(signed char,SWIG_TYPECHECK_INT8,IS_LONG)
%php_typecheck(unsigned char,SWIG_TYPECHECK_UINT8,IS_LONG)
%php_typecheck(size_t,SWIG_TYPECHECK_INT16,IS_LONG)
%php_typecheck(enum SWIGTYPE,SWIG_TYPECHECK_INT8,IS_LONG)
%php_typecheck(bool,SWIG_TYPECHECK_BOOL,IS_BOOL)
%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
%php_typecheck(char *,SWIG_TYPECHECK_STRING,IS_STRING)
%php_typecheck(char [],SWIG_TYPECHECK_STRING,IS_STRING)
%php_typecheck(float,SWIG_TYPECHECK_FLOAT,IS_DOUBLE)
%php_typecheck(double,SWIG_TYPECHECK_BOOL,IS_DOUBLE)
%php_typecheck(char,SWIG_TYPECHECK_CHAR,IS_STRING)
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) char *, char *&, char []
" $1 = (Z_TYPE_PP($input) == IS_STRING); "
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
{
@ -271,7 +443,8 @@
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *,
SWIGTYPE [],
SWIGTYPE &
SWIGTYPE &,
SWIGTYPE *&
{
void *tmp;
_v = (SWIG_ConvertPtr(*$input, (void**)&tmp, $1_descriptor, 0) >= 0);

View file

@ -8,5 +8,6 @@
%init %{
SWIG_php_minit {
SWIG_InitializeModule(0);
le_member_ptr = zend_register_list_destructors_ex(member_ptr_dtor, NULL, SWIG_MEMBER_PTR, module_number);
%}

View file

@ -1,25 +1,20 @@
/* -----------------------------------------------------------------------------
* phpkw.swg
*
* The 'keywords' in PHP are global, ie, the following names are fine
* when used as class methods.
* ----------------------------------------------------------------------------- */
#define PHPKW(x) %keywordwarn("'" `x` "' is a php keyword, renamed as 'c_" `x` "'",sourcefmt="%(lower)s", rename="c_%s",fullname=1) `x`
#define PHPKW(x) %keywordwarn("'" `x` "' is a PHP keyword, renamed as 'c_" `x` "'",sourcefmt="%(lower)s",rename="c_%s") `x`
%define PHPCN(x)
%keywordwarn("'" `x` "' is a php reserved class name, class renamed as 'c_" `x` "'",%$isclass,rename="c_%s") `x`;
%keywordwarn("'" `x` "' is a php reserved class name, constructor renamed as 'c_" `x` "'",%$isconstructor,rename="c_%s") `x`;
%enddef
#define PHPBN1(x) %builtinwarn("'" `x` "' conflicts with a built-in name in php",sourcefmt="%(lower)s",fullname=1) `x`
#define PHPBN2(x) %builtinwarn("'" `x` "' conflicts with a built-in name in php") "::" `x`
#define PHPCN(x) %keywordwarn("'" `x` "' is a PHP reserved class name, class renamed as 'c_" `x` "'",%$isclass,sourcefmt="%(lower)s",rename="c_%s") `x`
#define PHPBN1(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP",sourcefmt="%(lower)s") `x`
#define PHPBN2(x) %builtinwarn("'" `x` "' conflicts with a built-in name in PHP") "::" `x`
#define PHPFN(x) %keywordwarn("'" `x` "' is a PHP built-in function, renamed as 'c_" `x` "'",sourcefmt="%(lower)s",%$isfunction,%$not %$ismember,rename="c_%s") `x`
/*
From
http://aspn.activestate.com/ASPN/docs/PHP/reserved.html
http://php.net/manual/en/reserved.keywords.php
and reviewed by Olly Betts.
@ -27,76 +22,81 @@
*/
/* We classify these as kw since PHP will not run if used globally. */
/* "You cannot use any of the following words as constants, class names,
* function or method names. Using them as variable names is generally OK, but
* could lead to confusion."
*/
/* case insensitive */
PHPKW(__halt_compiler);
PHPKW(abstract);
PHPKW(and);
PHPKW(array);
PHPKW(as);
PHPKW(break);
PHPKW(case);
PHPKW(cfunction); /* No longer reserved in PHP5 */
PHPKW(catch);
PHPKW(class);
PHPKW(clone);
PHPKW(const);
PHPKW(continue);
PHPKW(declare);
PHPKW(default);
PHPKW(die);
PHPKW(die); // "Language construct"
PHPKW(do);
PHPKW(echo);
PHPKW(echo); // "Language construct"
PHPKW(else);
PHPKW(elseif);
PHPKW(empty);
PHPKW(empty); // "Language construct"
PHPKW(enddeclare);
PHPKW(endfor);
PHPKW(endforeach);
PHPKW(endif);
PHPKW(endswitch);
PHPKW(endwhile);
PHPKW(eval);
PHPKW(exit);
PHPKW(eval); // "Language construct"
PHPKW(exit); // "Language construct"
PHPKW(extends);
PHPKW(final);
PHPKW(for);
PHPKW(foreach);
PHPKW(function);
PHPKW(global);
PHPKW(goto); // As of PHP5.3
PHPKW(if);
PHPKW(include);
PHPKW(include_once);
PHPKW(isset);
PHPKW(list);
PHPKW(implements);
PHPKW(include); // "Language construct"
PHPKW(include_once); // "Language construct"
PHPKW(instanceof);
PHPKW(interface);
PHPKW(isset); // "Language construct"
PHPKW(list); // "Language construct"
PHPKW(namespace); // As of PHP5.3
PHPKW(new);
// PHPKW(old_function); /* No longer reserved in PHP5 */
PHPKW(or);
PHPKW(print);
PHPKW(require);
PHPKW(require_once);
PHPKW(return);
PHPKW(print); // "Language construct"
PHPKW(private);
PHPKW(protected);
PHPKW(public);
PHPKW(require); // "Language construct"
PHPKW(require_once); // "Language construct"
PHPKW(return); // "Language construct"
PHPKW(static);
PHPKW(switch);
PHPKW(unset);
PHPKW(throw);
PHPKW(try);
PHPKW(unset); // "Language construct"
PHPKW(use);
PHPKW(var);
PHPKW(while);
PHPKW(xor);
PHPKW(__FILE__);
PHPKW(__LINE__);
PHPKW(__FUNCTION__);
// Compile-time constants
PHPKW(__CLASS__);
/* Added in PHP5 */
PHPKW(__halt_compiler);
PHPKW(abstract);
PHPKW(catch);
PHPKW(clone);
PHPKW(final);
PHPKW(implements);
PHPKW(instanceof);
PHPKW(interface);
PHPKW(private);
PHPKW(protected);
PHPKW(public);
PHPKW(throw);
PHPKW(try);
PHPKW(__DIR__); // As of PHP5.3
PHPKW(__FILE__);
PHPKW(__FUNCTION__);
PHPKW(__METHOD__);
PHPKW(__NAMESPACE__); // As of PHP5.3
PHPKW(__LINE__);
/* We classify these as built-in names since they conflict, but PHP still runs */
@ -352,107 +352,131 @@ PHPBN2(E_STRICT);
PHPBN2(__COMPILER_HALT_OFFSET__);
/* Class names reserved by PHP */
PHPCN(stdClass);
PHPCN(__PHP_Incomplete_Class);
PHPCN(Directory);
/* case insensitive */
PHPCN(stdclass);
PHPCN(__php_incomplete_class);
PHPCN(directory);
/* Added in PHP5 (this list apparently depends which extensions you load by default). */
PHPCN(parent);
PHPCN(self);
PHPCN(Exception);
PHPCN(exception);
PHPCN(php_user_filter);
PHPCN(ErrorException);
PHPCN(XMLWriter);
PHPCN(LibXMLError);
PHPCN(SimpleXMLElement);
PHPCN(SoapClient);
PHPCN(SoapVar);
PHPCN(SoapServer);
PHPCN(SoapFault);
PHPCN(SoapParam);
PHPCN(SoapHeader);
PHPCN(RecursiveIteratorIterator);
PHPCN(FilterIterator);
PHPCN(RecursiveFilterIterator);
PHPCN(ParentIterator);
PHPCN(LimitIterator);
PHPCN(CachingIterator);
PHPCN(RecursiveCachingIterator);
PHPCN(IteratorIterator);
PHPCN(NoRewindIterator);
PHPCN(AppendIterator);
PHPCN(InfiniteIterator);
PHPCN(EmptyIterator);
PHPCN(ArrayObject);
PHPCN(ArrayIterator);
PHPCN(RecursiveArrayIterator);
PHPCN(SplFileInfo);
PHPCN(DirectoryIterator);
PHPCN(RecursiveDirectoryIterator);
PHPCN(SplFileObject);
PHPCN(SplTempFileObject);
PHPCN(SimpleXMLIterator);
PHPCN(LogicException);
PHPCN(BadFunctionCallException);
PHPCN(BadMethodCallException);
PHPCN(DomainException);
PHPCN(InvalidArgumentException);
PHPCN(LengthException);
PHPCN(OutOfRangeException);
PHPCN(RuntimeException);
PHPCN(OutOfBoundsException);
PHPCN(OverflowException);
PHPCN(RangeException);
PHPCN(UnderflowException);
PHPCN(UnexpectedValueException);
PHPCN(SplObjectStorage);
PHPCN(ReflectionException);
PHPCN(Reflection);
PHPCN(ReflectionFunction);
PHPCN(ReflectionParameter);
PHPCN(ReflectionMethod);
PHPCN(ReflectionClass);
PHPCN(ReflectionObject);
PHPCN(ReflectionProperty);
PHPCN(ReflectionExtension);
PHPCN(DOMException);
PHPCN(DOMStringList);
PHPCN(DOMNameList);
PHPCN(DOMImplementationList);
PHPCN(DOMImplementationSource);
PHPCN(DOMImplementation);
PHPCN(DOMNode);
PHPCN(DOMNameSpaceNode);
PHPCN(DOMDocumentFragment);
PHPCN(DOMDocument);
PHPCN(DOMNodeList);
PHPCN(DOMNamedNodeMap);
PHPCN(DOMCharacterData);
PHPCN(DOMAttr);
PHPCN(DOMElement);
PHPCN(DOMText);
PHPCN(DOMComment);
PHPCN(DOMTypeinfo);
PHPCN(DOMUserDataHandler);
PHPCN(DOMDomError);
PHPCN(DOMErrorHandler);
PHPCN(DOMLocator);
PHPCN(DOMConfiguration);
PHPCN(DOMCdataSection);
PHPCN(DOMDocumentType);
PHPCN(DOMNotation);
PHPCN(DOMEntity);
PHPCN(DOMEntityReference);
PHPCN(DOMProcessingInstruction);
PHPCN(DOMStringExtend);
PHPCN(DOMXPath);
PHPCN(XMLReader);
PHPCN(SQLiteDatabase);
PHPCN(SQLiteResult);
PHPCN(SQLiteUnbuffered);
PHPCN(SQLiteException);
PHPCN(errorexception);
PHPCN(xmlwriter);
PHPCN(libxmlerror);
PHPCN(simplexmlelement);
PHPCN(soapclient);
PHPCN(soapvar);
PHPCN(soapserver);
PHPCN(soapfault);
PHPCN(soapparam);
PHPCN(soapheader);
PHPCN(recursiveiteratoriterator);
PHPCN(filteriterator);
PHPCN(recursivefilteriterator);
PHPCN(parentiterator);
PHPCN(limititerator);
PHPCN(cachingiterator);
PHPCN(recursivecachingiterator);
PHPCN(iteratoriterator);
PHPCN(norewinditerator);
PHPCN(appenditerator);
PHPCN(infiniteiterator);
PHPCN(emptyiterator);
PHPCN(arrayobject);
PHPCN(arrayiterator);
PHPCN(recursivearrayiterator);
PHPCN(splfileinfo);
PHPCN(directoryiterator);
PHPCN(recursivedirectoryiterator);
PHPCN(splfileobject);
PHPCN(spltempfileobject);
PHPCN(simplexmliterator);
PHPCN(logicexception);
PHPCN(badfunctioncallexception);
PHPCN(badmethodcallexception);
PHPCN(domainexception);
PHPCN(invalidargumentexception);
PHPCN(lengthexception);
PHPCN(outofrangeexception);
PHPCN(runtimeexception);
PHPCN(outofboundsexception);
PHPCN(overflowexception);
PHPCN(rangeexception);
PHPCN(underflowexception);
PHPCN(unexpectedvalueexception);
PHPCN(splobjectstorage);
PHPCN(reflectionexception);
PHPCN(reflection);
PHPCN(reflectionfunction);
PHPCN(reflectionparameter);
PHPCN(reflectionmethod);
PHPCN(reflectionclass);
PHPCN(reflectionobject);
PHPCN(reflectionproperty);
PHPCN(reflectionextension);
PHPCN(domexception);
PHPCN(domstringlist);
PHPCN(domnamelist);
PHPCN(domimplementationlist);
PHPCN(domimplementationsource);
PHPCN(domimplementation);
PHPCN(domnode);
PHPCN(domnamespacenode);
PHPCN(domdocumentfragment);
PHPCN(domdocument);
PHPCN(domnodelist);
PHPCN(domnamednodemap);
PHPCN(domcharacterdata);
PHPCN(domattr);
PHPCN(domelement);
PHPCN(domtext);
PHPCN(domcomment);
PHPCN(domtypeinfo);
PHPCN(domuserdatahandler);
PHPCN(domdomerror);
PHPCN(domerrorhandler);
PHPCN(domlocator);
PHPCN(domconfiguration);
PHPCN(domcdatasection);
PHPCN(domdocumenttype);
PHPCN(domnotation);
PHPCN(domentity);
PHPCN(domentityreference);
PHPCN(domprocessinginstruction);
PHPCN(domstringextend);
PHPCN(domxpath);
PHPCN(xmlreader);
PHPCN(sqlitedatabase);
PHPCN(sqliteresult);
PHPCN(sqliteunbuffered);
PHPCN(sqliteexception);
PHPCN(datetime);
/* Built-in PHP functions (incomplete). */
PHPFN(cos);
PHPFN(sin);
PHPFN(tan);
PHPFN(acos);
PHPFN(asin);
PHPFN(atan);
PHPFN(atan2);
PHPFN(cosh);
PHPFN(sinh);
PHPFN(tanh);
PHPFN(exp);
PHPFN(log);
PHPFN(log10);
PHPFN(pow);
PHPFN(sqrt);
PHPFN(ceil);
PHPFN(floor);
PHPFN(fmod);
PHPFN(min);
PHPFN(max);
#undef PHPKW
#undef PHPBN1
#undef PHPBN2
#undef PHPCN
#undef PHPFN

View file

@ -10,6 +10,7 @@ extern "C" {
#include "zend.h"
#include "zend_API.h"
#include "php.h"
#include "ext/standard/php_string.h"
#ifdef ZEND_RAW_FENTRY
/* ZEND_RAW_FENTRY was added somewhere between 5.2.0 and 5.2.3 */
@ -21,9 +22,18 @@ extern "C" {
# define SWIG_ZEND_NAMED_FE(ZN, N, A) ZEND_NAMED_FE(ZN, N, A)
#endif
#ifndef Z_SET_ISREF_P
// For PHP < 5.3
# define Z_SET_ISREF_P(z) (z)->is_ref = 1
#endif
#ifndef Z_SET_REFCOUNT_P
// For PHP < 5.3
# define Z_SET_REFCOUNT_P(z, rc) (z)->refcount = (rc)
#endif
#define SWIG_LONG_CONSTANT(N, V) zend_register_long_constant((char*)#N, sizeof(#N), V, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
#define SWIG_DOUBLE_CONSTANT(N, V) zend_register_double_constant((char*)#N, sizeof(#N), V, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
#define SWIG_STRING_CONSTANT(N, V) zend_register_stringl_constant((char*)#N, sizeof(#N), V, strlen(V), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
#define SWIG_STRING_CONSTANT(N, V) zend_register_stringl_constant((char*)#N, sizeof(#N), (char*)(V), strlen(V), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC)
#define SWIG_CHAR_CONSTANT(N, V) do {\
static char swig_char = (V);\
zend_register_stringl_constant((char*)#N, sizeof(#N), &swig_char, 1, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC);\
@ -72,7 +82,7 @@ static int default_error_code = E_ERROR;
/* used to wrap returned objects in so we know whether they are newobject
and need freeing, or not */
typedef struct _swig_object_wrapper {
typedef struct {
void * ptr;
int newobject;
} swig_object_wrapper;
@ -81,6 +91,7 @@ typedef struct _swig_object_wrapper {
static ZEND_RSRC_DTOR_FUNC(SWIG_landfill) { (void)rsrc; }
#define SWIG_SetPointerZval(a,b,c,d) SWIG_ZTS_SetPointerZval(a,b,c,d TSRMLS_CC)
#define SWIG_as_voidptr(a) const_cast< void * >(static_cast< const void * >(a))
static void
SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject TSRMLS_DC) {
@ -98,7 +109,37 @@ SWIG_ZTS_SetPointerZval(zval *z, void *ptr, swig_type_info *type, int newobject
value=(swig_object_wrapper *)emalloc(sizeof(swig_object_wrapper));
value->ptr=ptr;
value->newobject=newobject;
ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
if (newobject <= 1) {
/* Just register the pointer as a resource. */
ZEND_REGISTER_RESOURCE(z, value, *(int *)(type->clientdata));
} else {
/*
* Wrap the resource in an object, the resource will be accessible
* via the "_cPtr" member. This is currently only used by
* directorin typemaps.
*/
value->newobject = 0;
zval *resource;
MAKE_STD_ZVAL(resource);
ZEND_REGISTER_RESOURCE(resource, value, *(int *)(type->clientdata));
zend_class_entry **ce = NULL;
zval *classname;
MAKE_STD_ZVAL(classname);
/* _p_Foo -> Foo */
ZVAL_STRING(classname, (char*)type->name+3, 1);
/* class names are stored in lowercase */
php_strtolower(Z_STRVAL_PP(&classname), Z_STRLEN_PP(&classname));
if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &ce TSRMLS_CC) != SUCCESS) {
/* class does not exist */
object_init(z);
} else {
object_init_ex(z, *ce);
}
Z_SET_REFCOUNT_P(z, 1);
Z_SET_ISREF_P(z);
zend_hash_update(HASH_OF(z), (char*)"_cPtr", sizeof("_cPtr"), (void*)&resource, sizeof(zval), NULL);
FREE_ZVAL(classname);
}
return;
}
zend_error(E_ERROR, "Type: %s not registered with zend",type->name);
@ -153,7 +194,7 @@ SWIG_ZTS_ConvertResourcePtr(zval *z, swig_type_info *ty, int flags TSRMLS_DC) {
char *type_name;
value = (swig_object_wrapper *) zend_list_find(z->value.lval, &type);
if ( flags && SWIG_POINTER_DISOWN ) {
if ( flags & SWIG_POINTER_DISOWN ) {
value->newobject = 0;
}
p = value->ptr;
@ -217,3 +258,12 @@ static void SWIG_Php_SetModule(swig_module_info *pointer) {
TSRMLS_FETCH();
REGISTER_MAIN_LONG_CONSTANT(const_name, (long) pointer, 0);
}
#define SWIG_MEMBER_PTR ((char*)"CLASS::*")
static void member_ptr_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
efree(rsrc->ptr);
}
static int le_member_ptr;

View file

@ -27,8 +27,6 @@ namespace std {
map(const map<K,T> &);
unsigned int size() const;
%rename(is_empty) empty;
bool empty() const;
void clear();
%extend {
T& get(const K& key) throw (std::out_of_range) {
@ -52,6 +50,9 @@ namespace std {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
bool is_empty() const {
return self->empty();
}
}
};
@ -67,8 +68,6 @@ namespace std {
map(const map<K,T> &);
unsigned int size() const;
%rename(is_empty) empty;
bool empty() const;
void clear();
%extend {
T& get(K key) throw (std::out_of_range) {
@ -92,6 +91,9 @@ namespace std {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
bool is_empty() const {
return self->empty();
}
}
};
%enddef
@ -104,8 +106,6 @@ namespace std {
map(const map<K,T> &);
unsigned int size() const;
%rename(is_empty) empty;
bool empty() const;
void clear();
%extend {
T get(const K& key) throw (std::out_of_range) {
@ -129,6 +129,9 @@ namespace std {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
bool is_empty() const {
return self->empty();
}
}
};
%enddef
@ -142,8 +145,6 @@ namespace std {
map(const map<K,T> &);
unsigned int size() const;
%rename(is_empty) empty;
bool empty() const;
void clear();
%extend {
T get(K key) throw (std::out_of_range) {
@ -167,6 +168,9 @@ namespace std {
std::map<K,T >::iterator i = self->find(key);
return i != self->end();
}
bool is_empty() const {
return self->empty();
}
}
};
%enddef

View file

@ -32,6 +32,11 @@ namespace std {
$1.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
%}
%typemap(directorout) string %{
convert_to_string_ex($input);
$result.assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
%}
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING) const string& %{
$1 = ( Z_TYPE_PP($input) == IS_STRING ) ? 1 : 0;
%}
@ -40,6 +45,10 @@ namespace std {
ZVAL_STRINGL($result, const_cast<char*>($1.data()), $1.size(), 1);
%}
%typemap(directorin) string %{
ZVAL_STRINGL($input, const_cast<char*>($1_name.data()), $1_name.size(), 1);
%}
%typemap(out) const string & %{
ZVAL_STRINGL($result, const_cast<char*>($1->data()), $1->size(), 1);
%}
@ -60,6 +69,14 @@ namespace std {
$1 = &temp;
%}
%typemap(directorout) string & (std::string *temp) %{
convert_to_string_ex($input);
temp = new std::string;
temp->assign(Z_STRVAL_PP($input), Z_STRLEN_PP($input));
swig_acquire_ownership(temp);
$result = temp;
%}
%typemap(argout) string & %{
ZVAL_STRINGL(*($input), const_cast<char*>($1->data()), $1->size(), 1);
%}

View file

@ -1,131 +1,102 @@
/* -----------------------------------------------------------------------------
* std_vector.i
*
* SWIG typemaps for std::vector types
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::vector
//
// The aim of all that follows would be to integrate std::vector with
// PHP as much as possible, namely, to allow the user to pass and
// be returned PHP lists.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
// the parameter being read-only, either a PHP sequence or a
// previously wrapped std::vector<T> can be passed.
// -- f(std::vector<T>&), f(std::vector<T>*):
// the parameter must be modified; therefore, only a wrapped std::vector
// can be passed.
// -- std::vector<T> f():
// the vector is returned by copy; therefore, a PHP sequence of T:s
// is returned which is most easily used in other PHP functions
// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
// const std::vector<T>* f():
// the vector is returned by reference; therefore, a wrapped std::vector
// is returned
// ------------------------------------------------------------------------
%{
#include <vector>
#include <algorithm>
#include <stdexcept>
%}
// exported class
namespace std {
template<class T> class vector {
// add generic typemaps here
public:
vector(unsigned int size = 0);
unsigned int size() const;
%rename(is_empty) empty;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(const T& x);
%extend {
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
T& get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("vector index out of range");
}
}
};
template<class T> class vector {
public:
typedef size_t size_type;
typedef T value_type;
typedef const value_type& const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
void clear();
%rename(push) push_back;
void push_back(const value_type& x);
%extend {
bool is_empty() const {
return $self->empty();
}
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
// specializations for built-ins
%define specialize_std_vector(T)
template<> class vector<T> {
// add specialized typemaps here
public:
vector(unsigned int size = 0);
unsigned int size() const;
%rename(is_empty) empty;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(T x);
%extend {
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
T get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("vector index out of range");
}
}
};
%enddef
specialize_std_vector(bool);
specialize_std_vector(char);
specialize_std_vector(int);
specialize_std_vector(short);
specialize_std_vector(long);
specialize_std_vector(unsigned char);
specialize_std_vector(unsigned int);
specialize_std_vector(unsigned short);
specialize_std_vector(unsigned long);
specialize_std_vector(float);
specialize_std_vector(double);
// bool specialization
template<> class vector<bool> {
public:
typedef size_t size_type;
typedef bool value_type;
typedef bool const_reference;
vector();
vector(size_type n);
size_type size() const;
size_type capacity() const;
void reserve(size_type n);
void clear();
%rename(push) push_back;
void push_back(const value_type& x);
%extend {
bool is_empty() const {
return $self->empty();
}
bool pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
bool x = self->back();
self->pop_back();
return x;
}
const_reference get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const value_type& val) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = val;
else
throw std::out_of_range("vector index out of range");
}
}
};
}
%define specialize_std_vector(T)
#warning "specialize_std_vector - specialization for type T no longer needed"
%enddef

View file

@ -109,9 +109,7 @@ int_typemap(long long);
}
%typemap(in) TYPE *REFERENCE (long long lvalue)
%{
// FIXME won't work for values which don't fit in a long...
convert_to_long_ex($input);
lvalue = (long long) (*$input)->value.lval;
CONVERT_LONG_LONG_IN(lvalue, long long, $input)
$1 = &lvalue;
%}
%typemap(argout) long long *REFERENCE
@ -125,6 +123,17 @@ int_typemap(long long);
ZVAL_STRING((*$arg), temp, 1);
}
%}
%typemap(argout) long long &OUTPUT
%{
if ((long long)LONG_MIN <= *arg$argnum && *arg$argnum <= (long long)LONG_MAX) {
($result)->value.lval = (long)(*arg$argnum);
($result)->type = IS_LONG;
} else {
char temp[256];
sprintf(temp, "%lld", *arg$argnum);
ZVAL_STRING($result, temp, 1);
}
%}
int_typemap(unsigned long long);
%typemap(argout,fragment="t_output_helper") unsigned long long *OUTPUT
{
@ -141,9 +150,7 @@ int_typemap(unsigned long long);
}
%typemap(in) TYPE *REFERENCE (unsigned long long lvalue)
%{
// FIXME won't work for values which don't fit in a long...
convert_to_long_ex($input);
lvalue = (unsigned long long) (*$input)->value.lval;
CONVERT_UNSIGNED_LONG_LONG_IN(lvalue, unsigned long long, $input)
$1 = &lvalue;
%}
%typemap(argout) unsigned long long *REFERENCE
@ -157,6 +164,17 @@ int_typemap(unsigned long long);
ZVAL_STRING((*$arg), temp, 1);
}
%}
%typemap(argout) unsigned long long &OUTPUT
%{
if (*arg$argnum <= (unsigned long long)LONG_MAX) {
($result)->value.lval = (long)(*arg$argnum);
($result)->type = IS_LONG;
} else {
char temp[256];
sprintf(temp, "%llu", *arg$argnum);
ZVAL_STRING($result, temp, 1);
}
%}
%typemap(in) float *INOUT = float *INPUT;
%typemap(in) double *INOUT = double *INPUT;
@ -178,11 +196,13 @@ int_typemap(unsigned long long);
%typemap(in) short &INOUT = short *INPUT;
%typemap(in) long &INOUT = long *INPUT;
%typemap(in) long long &INOUT = long long *INPUT;
%typemap(in) long long &INPUT = long long *INPUT;
%typemap(in) unsigned &INOUT = unsigned *INPUT;
%typemap(in) unsigned short &INOUT = unsigned short *INPUT;
%typemap(in) unsigned long &INOUT = unsigned long *INPUT;
%typemap(in) unsigned char &INOUT = unsigned char *INPUT;
%typemap(in) unsigned long long &INOUT = unsigned long long *INPUT;
%typemap(in) unsigned long long &INPUT = unsigned long long *INPUT;
%typemap(argout) float *INOUT = float *OUTPUT;
%typemap(argout) double *INOUT= double *OUTPUT;

View file

@ -9,6 +9,42 @@
lvar = (t) Z_LVAL_PP(invar);
%enddef
%define CONVERT_LONG_LONG_IN(lvar,t,invar)
switch ((*(invar))->type) {
case IS_DOUBLE:
lvar = (t) (*(invar))->value.dval;
break;
case IS_STRING: {
char * endptr;
errno = 0;
lvar = (t) strtoll((*(invar))->value.str.val, &endptr, 10);
if (*endptr && !errno) break;
/* FALL THRU */
}
default:
convert_to_long_ex(invar);
lvar = (t) (*(invar))->value.lval;
}
%enddef
%define CONVERT_UNSIGNED_LONG_LONG_IN(lvar,t,invar)
switch ((*(invar))->type) {
case IS_DOUBLE:
lvar = (t) (*(invar))->value.dval;
break;
case IS_STRING: {
char * endptr;
errno = 0;
lvar = (t) strtoull((*(invar))->value.str.val, &endptr, 10);
if (*endptr && !errno) break;
/* FALL THRU */
}
default:
convert_to_long_ex(invar);
lvar = (t) (*(invar))->value.lval;
}
%enddef
%define CONVERT_INT_OUT(lvar,invar)
lvar = (t) Z_LVAL_PP(invar);
%enddef
@ -33,10 +69,24 @@
%enddef
%define %pass_by_val( TYPE, CONVERT_IN )
%typemap(in) TYPE, const TYPE &
%typemap(in) TYPE
%{
CONVERT_IN($1,$1_ltype,$input);
%}
%typemap(in) const TYPE & ($*1_ltype temp)
%{
CONVERT_IN(temp,$*1_ltype,$input);
$1 = &temp;
%}
%typemap(directorout) TYPE
%{
CONVERT_IN($result,$1_ltype,$input);
%}
%typemap(directorout) const TYPE & ($*1_ltype temp)
%{
CONVERT_IN(temp,$*1_ltype,$input);
$result = &temp;
%}
%enddef
%fragment("t_output_helper","header") %{
@ -49,6 +99,7 @@ t_output_helper( zval **target, zval *o) {
}
if ( (*target)->type == IS_NULL ) {
REPLACE_ZVAL_VALUE(target,o,1);
FREE_ZVAL(o);
return;
}
zval *tmp;

View file

@ -6,18 +6,23 @@
#define SHARED_PTR_DISOWN 0
#endif
// Language specific macro implementing all the customisations for handling the smart pointer
%define SWIG_SHARED_PTR_TYPEMAPS(PROXYCLASS, CONST, TYPE...)
// %naturalvar is as documented for member variables
%naturalvar TYPE;
%naturalvar SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< CONST TYPE >;
// destructor mods
// destructor wrapper customisation
%feature("unref") TYPE
//"if (debug_shared) { cout << \"deleting use_count: \" << (*smartarg1).use_count() << \" [\" << (boost::get_deleter<SWIG_null_deleter>(*smartarg1) ? std::string(\"CANNOT BE DETERMINED SAFELY\") : ( (*smartarg1).get() ? (*smartarg1)->getValue() : std::string(\"NULL PTR\") )) << \"]\" << endl << flush; }\n"
"(void)arg1; delete smartarg1;"
// Feature to adapt the code generated in the swigregister functions for smart pointers
%feature("smartptr", noblock=1) TYPE { SWIG_SHARED_PTR_QNAMESPACE::shared_ptr< TYPE > }
// Typemap customisations...
// plain value
%typemap(in) CONST TYPE (void *argp, int res = 0) {
int newmem = 0;

View file

@ -234,7 +234,7 @@ namespace Swig {
try {
throw;
} catch (DirectorException& e) {
std::cerr << "Swig Director exception caught:" << std::endl
std::cerr << "SWIG Director exception caught:" << std::endl
<< e.getMessage() << std::endl;
} catch (std::exception& e) {
std::cerr << "std::exception caught: "<< e.what() << std::endl;
@ -273,12 +273,12 @@ namespace Swig {
class DirectorTypeMismatchException : public Swig::DirectorException {
public:
DirectorTypeMismatchException(PyObject *error, const char* msg="")
: Swig::DirectorException(error, "Swig director type mismatch", msg)
: Swig::DirectorException(error, "SWIG director type mismatch", msg)
{
}
DirectorTypeMismatchException(const char* msg="")
: Swig::DirectorException(PyExc_TypeError, "Swig director type mismatch", msg)
: Swig::DirectorException(PyExc_TypeError, "SWIG director type mismatch", msg)
{
}
@ -297,7 +297,7 @@ namespace Swig {
class DirectorMethodException : public Swig::DirectorException {
public:
DirectorMethodException(const char* msg = "")
: DirectorException(PyExc_RuntimeError, "Swig director method error.", msg)
: DirectorException(PyExc_RuntimeError, "SWIG director method error.", msg)
{
}
@ -312,7 +312,7 @@ namespace Swig {
{
public:
DirectorPureVirtualException(const char* msg = "")
: DirectorException(PyExc_RuntimeError, "Swig director pure virtual method called", msg)
: DirectorException(PyExc_RuntimeError, "SWIG director pure virtual method called", msg)
{
}

View file

@ -279,15 +279,15 @@ SWIG_Python_FixMethods(PyMethodDef *methods,
}
}
if (ci) {
size_t shift = (ci->ptype) - types;
swig_type_info *ty = types_initial[shift];
size_t ldoc = (c - methods[i].ml_doc);
size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
char *ndoc = (char*)malloc(ldoc + lptr + 10);
if (ndoc) {
char *buff = ndoc;
void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
if (ptr) {
void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue : 0;
if (ptr) {
size_t shift = (ci->ptype) - types;
swig_type_info *ty = types_initial[shift];
size_t ldoc = (c - methods[i].ml_doc);
size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
char *ndoc = (char*)malloc(ldoc + lptr + 10);
if (ndoc) {
char *buff = ndoc;
strncpy(buff, methods[i].ml_doc, ldoc);
buff += ldoc;
strncpy(buff, "swig_ptr: ", 10);

View file

@ -1086,7 +1086,7 @@ SWIG_Python_ConvertPtrAndOwn(PyObject *obj, void **ptr, swig_type_info *ty, int
int newmemory = 0;
*ptr = SWIG_TypeCast(tc,vptr,&newmemory);
if (newmemory == SWIG_CAST_NEW_MEMORY) {
assert(own);
assert(own); /* badly formed typemap which will lead to a memory leak - it must set and use own to delete *ptr */
if (own)
*own = *own | SWIG_CAST_NEW_MEMORY;
}
@ -1160,10 +1160,10 @@ SWIG_Python_ConvertFunctionPtr(PyObject *obj, void **ptr, swig_type_info *ty) {
/* here we get the method pointer for callbacks */
const char *doc = (((PyCFunctionObject *)obj) -> m_ml -> ml_doc);
const char *desc = doc ? strstr(doc, "swig_ptr: ") : 0;
if (desc) {
if (desc)
desc = ty ? SWIG_UnpackVoidPtr(desc + 10, &vptr, ty->name) : 0;
if (!desc) return SWIG_ERROR;
}
if (!desc)
return SWIG_ERROR;
if (ty) {
swig_cast_info *tc = SWIG_TypeCheck(desc,ty);
if (tc) {

View file

@ -20,11 +20,12 @@
typedef std::map<K,T> map_type;
static int asptr(PyObject *obj, map_type **val) {
int res = SWIG_ERROR;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (PyDict_Check(obj)) {
SwigVar_PyObject items = PyObject_CallMethod(obj,(char *)"items",NULL);
%#if PY_VERSION_HEX >= 0x03000000
/* In Python 3.x the ".items()" method return a dict_items object */
items = PySequence_Fast(items, ".items() havn't returned a sequence!");
/* In Python 3.x the ".items()" method returns a dict_items object */
items = PySequence_Fast(items, ".items() didn't return a sequence!");
%#endif
res = traits_asptr_stdseq<std::map<K,T>, std::pair<K, T> >::asptr(items, val);
} else {
@ -32,6 +33,7 @@
res = SWIG_ConvertPtr(obj,(void**)&p,swig::type_info<map_type>(),0);
if (SWIG_IsOK(res) && val) *val = p;
}
SWIG_PYTHON_THREAD_END_BLOCK;
return res;
}
};
@ -47,10 +49,10 @@
if (desc && desc->clientdata) {
return SWIG_NewPointerObj(new map_type(map), desc, SWIG_POINTER_OWN);
} else {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
size_type size = map.size();
int pysize = (size <= (size_type) INT_MAX) ? (int) size : -1;
if (pysize < 0) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetString(PyExc_OverflowError,
"map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
@ -62,6 +64,7 @@
swig::SwigVar_PyObject val = swig::from(i->second);
PyDict_SetItem(obj, key, val);
}
SWIG_PYTHON_THREAD_END_BLOCK;
return obj;
}
}
@ -165,8 +168,8 @@
PyObject* keys() {
Map::size_type size = self->size();
int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetString(PyExc_OverflowError,
"map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
@ -177,14 +180,15 @@
for (int j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(keyList, j, swig::from(i->first));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return keyList;
}
PyObject* values() {
Map::size_type size = self->size();
int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetString(PyExc_OverflowError,
"map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
@ -195,14 +199,15 @@
for (int j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(valList, j, swig::from(i->second));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return valList;
}
PyObject* items() {
Map::size_type size = self->size();
int pysize = (size <= (Map::size_type) INT_MAX) ? (int) size : -1;
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
if (pysize < 0) {
SWIG_PYTHON_THREAD_BEGIN_BLOCK;
PyErr_SetString(PyExc_OverflowError,
"map size not valid in python");
SWIG_PYTHON_THREAD_END_BLOCK;
@ -213,6 +218,7 @@
for (int j = 0; j < pysize; ++i, ++j) {
PyList_SET_ITEM(itemList, j, swig::from(*i));
}
SWIG_PYTHON_THREAD_END_BLOCK;
return itemList;
}

View file

@ -50,7 +50,7 @@ SWIG_InitializeModule(0);
%typemap(scheck) SWIGTYPE[ANY]
%{
# assert(length($input) > $1_dim0)
assert(all(sapply($input, class) == "$R_class"))
assert(all(sapply($input, class) == "$R_class"));
%}
%typemap(out) void "";
@ -122,14 +122,14 @@ SWIG_InitializeModule(0);
/* Handling vector case to avoid warnings,
although we just use the first one. */
%typemap(scheck) unsigned int %{
assert(length($input) == 1 && $input >= 0, "All values must be non-negative")
assert(length($input) == 1 && $input >= 0, "All values must be non-negative");
%}
%typemap(scheck) int, long %{
if(length($input) > 1) {
warning("using only the first element of $input")
}
warning("using only the first element of $input");
};
%}

View file

@ -60,11 +60,11 @@
%typemap(scoercein) std::string, std::string *, std::string &
%{ $input = as($input, "character"); %}
%typemap(scoercein) enum SWIGTYPE
%{ $input = enumToInteger($input, "$R_class") %}
%{ $input = enumToInteger($input, "$R_class"); %}
%typemap(scoercein) enum SWIGTYPE &
%{ $input = enumToInteger($input, "$R_class") %}
%{ $input = enumToInteger($input, "$R_class"); %}
%typemap(scoercein) enum SWIGTYPE *
%{ $input = enumToInteger($input, "$R_class") %}
%{ $input = enumToInteger($input, "$R_class"); %}
%typemap(scoercein) SWIGTYPE, SWIGTYPE *, SWIGTYPE &
@ -84,14 +84,14 @@
%typemap(scoercein) SWIGTYPE[ANY]
%{
if(is.list($input))
assert(all(sapply($input, class) == "$R_class"))
assert(all(sapply($input, class) == "$R_class"));
%}
/* **************************************************************** */
%typemap(scoercein) bool, bool *, bool &
"$input = as.logical($input) ";
"$input = as.logical($input);";
%typemap(scoercein) int,
int *,
int &,
@ -100,30 +100,30 @@
long *,
long &,
long[ANY]
"$input = as.integer($input) ";
"$input = as.integer($input); ";
%typemap(scoercein) char *, string, std::string,
string &, std::string &
%{ $input = as($input, "character") %}
%{ $input = as($input, "character"); %}
%typemap(scoerceout) enum SWIGTYPE
%{ $result = enumFromInteger($result, "$R_class") %}
%{ $result = enumFromInteger($result, "$R_class"); %}
%typemap(scoerceout) enum SWIGTYPE &
%{ $result = enumFromInteger($result, "$R_class") %}
%{ $result = enumFromInteger($result, "$R_class"); %}
%typemap(scoerceout) enum SWIGTYPE *
%{ $result = enumToInteger($result, "$R_class") %}
%{ $result = enumToInteger($result, "$R_class"); %}
%typemap(scoerceout) SWIGTYPE
%{ class($result) <- "$&R_class" %}
%{ class($result) <- "$&R_class"; %}
%typemap(scoerceout) SWIGTYPE &
%{ class($result) <- "$R_class" %}
%{ class($result) <- "$R_class"; %}
%typemap(scoerceout) SWIGTYPE *
%{ class($result) <- "$R_class" %}
%{ class($result) <- "$R_class"; %}
/* Override the SWIGTYPE * above. */
%typemap(scoerceout) char,

5
Lib/r/std_map.i Normal file
View file

@ -0,0 +1,5 @@
%fragment("StdMapTraits","header")
%{
%}
%include <std/std_map.i>

View file

@ -1 +1,5 @@
%include<std/std_pair.i>
%fragment("StdPairTraits","header")
%{
%}
%include<std/std_pair.i>

View file

@ -173,7 +173,7 @@ namespace Swig {
try {
throw;
} catch (DirectorException& e) {
std::cerr << "Swig Director exception caught:" << std::endl
std::cerr << "SWIG Director exception caught:" << std::endl
<< e.getMessage() << std::endl;
} catch (std::exception& e) {
std::cerr << "std::exception caught: "<< e.what() << std::endl;
@ -209,12 +209,12 @@ namespace Swig {
class DirectorTypeMismatchException : public Swig::DirectorException {
public:
DirectorTypeMismatchException(VALUE error, const char *msg="")
: Swig::DirectorException(error, "Swig director type mismatch", msg)
: Swig::DirectorException(error, "SWIG director type mismatch", msg)
{
}
DirectorTypeMismatchException(const char *msg="")
: Swig::DirectorException(rb_eTypeError, "Swig director type mismatch", msg)
: Swig::DirectorException(rb_eTypeError, "SWIG director type mismatch", msg)
{
}
@ -235,7 +235,7 @@ namespace Swig {
}
DirectorMethodException(const char* msg = "")
: Swig::DirectorException(rb_eRuntimeError, "Swig director method error.", msg) {
: Swig::DirectorException(rb_eRuntimeError, "SWIG director method error.", msg) {
}
static void raise(VALUE error)
@ -249,7 +249,7 @@ namespace Swig {
{
public:
DirectorPureVirtualException(const char* msg = "")
: DirectorException(rb_eRuntimeError, "Swig director pure virtual method called", msg)
: DirectorException(rb_eRuntimeError, "SWIG director pure virtual method called", msg)
{
}

View file

@ -1,6 +1,6 @@
%wrapper %{
#include "ruby.h"
#include <ruby.h>
int
main(argc, argv)

View file

@ -443,11 +443,10 @@ namespace swig
%typemap(out,noblock=1,fragment="RubySequence_Cont")
std::pair<const_iterator, const_iterator> {
$result = rb_ary_new2(2);
RARRAY_PTR($result)[0] = SWIG_NewPointerObj(swig::make_const_iterator(%static_cast($1,const $type &).first),
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN);
RARRAY_PTR($result)[1] = SWIG_NewPointerObj(swig::make_const_iterator(%static_cast($1,const $type &).second),
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN);
RARRAY_LEN($result) = 2;
rb_ary_push($result, SWIG_NewPointerObj(swig::make_const_iterator(%static_cast($1,const $type &).first),
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN));
rb_ary_push($result, SWIG_NewPointerObj(swig::make_const_iterator(%static_cast($1,const $type &).second),
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN));
}
// std::map/multimap/set allow returning std::pair< iterator, iterator > from
@ -456,11 +455,10 @@ namespace swig
%typemap(out,noblock=1,fragment="RubySequence_Cont")
std::pair<iterator, iterator> {
$result = rb_ary_new2(2);
RARRAY_PTR($result)[0] = SWIG_NewPointerObj(swig::make_const_iterator(%static_cast($1,const $type &).first),
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN);
RARRAY_PTR($result)[1] = SWIG_NewPointerObj(swig::make_const_iterator(%static_cast($1,const $type &).second),
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN);
RARRAY_LEN($result) = 2;
rb_ary_push($result, SWIG_NewPointerObj(swig::make_const_iterator(%static_cast($1,const $type &).first),
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN));
rb_ary_push($result, SWIG_NewPointerObj(swig::make_const_iterator(%static_cast($1,const $type &).second),
swig::ConstIterator::descriptor(),SWIG_POINTER_OWN));
}
@ -563,7 +561,8 @@ namespace swig
{
Sequence::const_iterator i = $self->begin();
Sequence::const_iterator e = $self->end();
VALUE str = rb_str_new2( swig::type_name< Sequence >() );
const char *type_name = swig::type_name< Sequence >();
VALUE str = rb_str_new2(type_name);
str = rb_str_cat2( str, " [" );
bool comma = false;
VALUE tmp;
@ -872,31 +871,8 @@ namespace swig
}
%enddef
// ..I don't think %swig_sequence_methods_val are really used at all anymore...
%define %swig_sequence_methods_val(Sequence...)
%swig_sequence_methods_common(%arg(Sequence))
%extend {
VALUE __getitem__(difference_type i) {
VALUE r = Qnil;
try {
r = swig::from< Sequence::value_type >( *(swig::cgetpos(self, i)) );
}
catch( std::out_of_range )
{
}
return r;
}
VALUE __setitem__(difference_type i, value_type x) {
std::size_t len = $self->size();
if ( i < 0 ) i = len - i;
else if ( static_cast<std::size_t>(i) >= len )
$self->resize( i+1, x );
else *(swig::getpos(self,i)) = x;
return swig::from< Sequence::value_type >( x );
}
}
%swig_sequence_methods(%arg(Sequence))
%enddef
@ -950,7 +926,7 @@ namespace swig
}
catch( std::invalid_argument )
{
rb_raise( rb_eArgError,
rb_raise( rb_eArgError, "%s",
Ruby_Format_TypeError( "",
swig::type_name<Sequence::value_type>(),
__FUNCTION__, idx+2, elem ));
@ -977,7 +953,7 @@ namespace swig
}
catch( std::invalid_argument )
{
rb_raise( rb_eArgError,
rb_raise( rb_eArgError, "%s",
Ruby_Format_TypeError( "",
swig::type_name<Sequence::value_type>(),
__FUNCTION__, idx+2, elem ));
@ -1032,7 +1008,7 @@ namespace swig {
if (seq) {
VALUE lastErr = rb_gv_get("$!");
if (lastErr == Qnil) {
rb_raise(rb_eTypeError, e.what());
rb_raise(rb_eTypeError, "%s", e.what());
}
}
return SWIG_ERROR;
@ -1072,7 +1048,7 @@ namespace swig {
if (seq) {
VALUE lastErr = rb_gv_get("$!");
if (lastErr == Qnil) {
rb_raise(rb_eTypeError, e.what());
rb_raise(rb_eTypeError, "%s", e.what());
}
}
return SWIG_ERROR;
@ -1109,9 +1085,8 @@ namespace swig {
int i = 0;
for (const_iterator it = seq.begin();
it != seq.end(); ++it, ++i) {
RARRAY_PTR(obj)[i] = swig::from< value_type >(*it);
rb_ary_push(obj, swig::from< value_type >(*it));
}
RARRAY_LEN(obj) = size;
rb_obj_freeze(obj); // treat as immutable result
return obj;
} else {

View file

@ -72,7 +72,7 @@
catch ( const std::invalid_argument& )
{
rb_raise(rb_eTypeError,
"Yield block did not return a valid element for " #Container);
"Yield block did not return a valid element for " "Container");
}
return $self;

View file

@ -1,5 +1,14 @@
#include <ruby.h>
/* Ruby 1.9.1 has a "memoisation optimisation" when compiling with GCC which
* breaks using rb_intern as an lvalue, as SWIG does. We work around this
* issue for now by disabling this.
* https://sourceforge.net/tracker/?func=detail&aid=2859614&group_id=1645&atid=101645
*/
#ifdef rb_intern
# undef rb_intern
#endif
/* Remove global macros defined in Ruby's win32.h */
#ifdef write
# undef write
@ -10,6 +19,12 @@
#ifdef bind
# undef bind
#endif
#ifdef close
# undef close
#endif
#ifdef connect
# undef connect
#endif
/* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */

View file

@ -193,7 +193,7 @@ SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val)
}
%fragment(SWIG_AsVal_frag(double),"header",fragment="SWIG_ruby_failed") {
%ruby_aux_method(double, NUM2DBL, (type == T_FLOAT ? NUM2DBL(obj) : (type == T_FIXNUM ? (double) FIX2INT(obj) : rb_big2dbl(obj))))
%ruby_aux_method(double, NUM2DBL, NUM2DBL(obj))
SWIGINTERN int
SWIG_AsVal_dec(double)(VALUE obj, double *val)

View file

@ -42,7 +42,7 @@
/* Error manipulation */
#define SWIG_ErrorType(code) SWIG_Ruby_ErrorType(code)
#define SWIG_Error(code, msg) rb_raise(SWIG_Ruby_ErrorType(code), msg)
#define SWIG_Error(code, msg) rb_raise(SWIG_Ruby_ErrorType(code), "%s", msg)
#define SWIG_fail goto fail
@ -97,7 +97,7 @@ static ID swig_call_id = 0;
++swig_virtual_calls;
# define SWIG_RELEASE_STACK --swig_virtual_calls;
# define Ruby_DirectorTypeMismatchException(x) \
rb_raise( rb_eTypeError, x ); return c_result;
rb_raise( rb_eTypeError, "%s", x ); return c_result;
static unsigned int swig_virtual_calls = 0;

View file

@ -345,7 +345,8 @@
{
Map::const_iterator i = $self->begin();
Map::const_iterator e = $self->end();
VALUE str = rb_str_new2( swig::type_name< Map >() );
const char *type_name = swig::type_name< Map >();
VALUE str = rb_str_new2( type_name );
str = rb_str_cat2( str, " {" );
bool comma = false;
VALUE tmp;

View file

@ -115,7 +115,8 @@
{
MultiMap::iterator i = $self->begin();
MultiMap::iterator e = $self->end();
VALUE str = rb_str_new2( swig::type_name< MultiMap >() );
const char *type_name = swig::type_name< MultiMap >();
VALUE str = rb_str_new2( type_name );
str = rb_str_cat2( str, " {" );
VALUE tmp;
while ( i != e )

View file

@ -118,13 +118,11 @@
static VALUE from(const std::pair<T,U>& val) {
VALUE obj = rb_ary_new2(2);
RARRAY_PTR(obj)[0] = swig::from<
typename swig::noconst_traits<T >::noconst_type>(val.first);
RARRAY_PTR(obj)[1] = swig::from(val.second);
RARRAY_LEN(obj) = 2;
rb_define_singleton_method(obj, "second",
rb_ary_push(obj, swig::from<typename swig::noconst_traits<T >::noconst_type>(val.first));
rb_ary_push(obj, swig::from(val.second));
rb_define_singleton_method(obj, "second",
VALUEFUNC(_wrap_pair_second), 0 );
rb_define_singleton_method(obj, "second=",
rb_define_singleton_method(obj, "second=",
VALUEFUNC(_wrap_pair_second_eq), 1 );
rb_obj_freeze(obj); // treat as immutable tuple
return obj;
@ -148,7 +146,8 @@
VALUE inspect() const
{
VALUE tmp;
VALUE str = rb_str_new2( swig::type_name< pair >() );
const char *type_name = swig::type_name< pair >();
VALUE str = rb_str_new2( type_name );
str = rb_str_cat2( str, " (" );
tmp = swig::from( $self->first );
tmp = rb_obj_as_string( tmp );

View file

@ -170,10 +170,9 @@
%typemap(out,noblock=1,fragment="RubyPairBoolOutputIterator")
std::pair<iterator, bool> {
$result = rb_ary_new2(2);
RARRAY_PTR($result)[0] = SWIG_NewPointerObj(swig::make_set_nonconst_iterator(%static_cast($1,$type &).first),
swig::Iterator::descriptor(),SWIG_POINTER_OWN);
RARRAY_PTR($result)[1] = SWIG_From(bool)(%static_cast($1,const $type &).second);
RARRAY_LEN($result) = 2;
rb_ary_push($result, SWIG_NewPointerObj(swig::make_set_nonconst_iterator(%static_cast($1,$type &).first),
swig::Iterator::descriptor(),SWIG_POINTER_OWN));
rb_ary_push($result, SWIG_From(bool)(%static_cast($1,const $type &).second));
}
%extend {

View file

@ -1,3 +1,7 @@
// The main implementation detail in using this smart pointer of a type is to customise the code generated
// to use a pointer to the smart pointer of the type, rather than the usual pointer to the underlying type.
// So for some type T, shared_ptr<T> * is used rather than T *.
// shared_ptr namespaces could be boost or std or std::tr1
// For example for std::tr1, use:
// #define SWIG_SHARED_PTR_NAMESPACE std

View file

@ -24,7 +24,7 @@
};
*/
%define %std_deque_methods(T)
%define %std_deque_methods_noempty(T)
typedef T &reference;
typedef const T& const_reference;
@ -38,7 +38,6 @@
unsigned int size() const;
unsigned int max_size() const;
void resize(unsigned int n, T c = T());
bool empty() const;
const_reference front();
const_reference back();
void push_front(const T& x);
@ -66,7 +65,7 @@
throw std::out_of_range("deque index out of range");
}
void delitem(int i) throw (std::out_of_range) {
int size = int(self->size());
int size = int(self->size());
if (i<0) i+= size;
if (i>=0 && i<size) {
self->erase(self->begin()+i);
@ -74,7 +73,7 @@
throw std::out_of_range("deque index out of range");
}
}
std::deque<T> getslice(int i, int j) {
std::deque<T> getslice(int i, int j) {
int size = int(self->size());
if (i<0) i = size+i;
if (j<0) j = size+j;
@ -109,15 +108,27 @@
self->erase(self->begin()+i,self->begin()+j);
}
};
%enddef
#ifdef SWIGPHP
%define %std_deque_methods(T)
%extend {
bool is_empty() const {
return self->empty();
}
};
%std_deque_methods_noempty(T)
%enddef
#else
%define %std_deque_methods(T)
bool empty() const;
%std_deque_methods_noempty(T)
%enddef
#endif
namespace std {
template<class T> class deque {
public:
%std_deque_methods(T);
};
}

View file

@ -134,6 +134,46 @@ namespace std {
%std_vector_methods_val(vector);
};
// ***
// const pointer specialization
// ***
template<class _Tp, class _Alloc >
class vector<const _Tp *, _Alloc > {
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef const _Tp * value_type;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef value_type reference;
typedef value_type const_reference;
typedef _Alloc allocator_type;
%traits_swigtype(_Tp);
%fragment(SWIG_Traits_frag(std::vector<const _Tp *, _Alloc >), "header",
fragment=SWIG_Traits_frag(_Tp),
fragment="StdVectorTraits") {
namespace swig {
template <> struct traits<std::vector<const _Tp *, _Alloc > > {
typedef value_category category;
static const char* type_name() {
return "std::vector<const " #_Tp " *," #_Alloc " >";
}
};
}
}
%typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<const _Tp *, _Alloc >);
#ifdef %swig_vector_methods_val
// Add swig/language extra methods
%swig_vector_methods_val(std::vector<const _Tp *, _Alloc >);
#endif
%std_vector_methods_val(vector);
};
// ***
// ***
// bool specialization

View file

@ -136,6 +136,11 @@
#define %nocallback %feature("callback","0")
#define %clearcallback %feature("callback","")
/* the %nestedworkaround directive */
#define %nestedworkaround %feature("nestedworkaround")
#define %nonestedworkaround %feature("nestedworkaround","0")
#define %clearnestedworkaround %feature("nestedworkaround","")
/* the %fastdispatch directive */
#define %fastdispatch %feature("fastdispatch")
#define %nofastdispatch %feature("fastdispatch","0")
@ -152,7 +157,7 @@
#define %clearnaturalvar %feature("naturalvar","")
/* valuewrapper directives */
#define %valuewrapper %feature("valuewrapper",)
#define %valuewrapper %feature("valuewrapper")
#define %clearvaluewrapper %feature("valuewrapper","")
#define %novaluewrapper %feature("novaluewrapper")
#define %clearnovaluewrapper %feature("novaluewrapper","")

View file

@ -13,17 +13,17 @@
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
// -- f(std::vector< T >), f(const std::vector< T >&), f(const std::vector< T >*):
// the parameter being read-only, either a Tcl list or a
// previously wrapped std::vector<T> can be passed.
// -- f(std::vector<T>&), f(std::vector<T>*):
// previously wrapped std::vector< T > can be passed.
// -- f(std::vector< T >&), f(std::vector< T >*):
// the parameter must be modified; therefore, only a wrapped std::vector
// can be passed.
// -- std::vector<T> f():
// -- std::vector< T > f():
// the vector is returned by copy; therefore, a Tcl list of T:s
// is returned which is most easily used in other Tcl functions procs
// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
// const std::vector<T>* f():
// -- std::vector< T >& f(), std::vector< T >* f(), const std::vector< T >& f(),
// const std::vector< T >* f():
// the vector is returned by reference; therefore, a wrapped std::vector
// is returned
// ------------------------------------------------------------------------
@ -82,7 +82,7 @@ int SwigDouble_As(Tcl_Interp *interp, Tcl_Obj *o, Type *val) {
namespace std {
template<class T> class vector {
%typemap(in) vector<T> (std::vector<T> *v) {
%typemap(in) vector< T > (std::vector< T > *v) {
Tcl_Obj **listobjv;
int nitems;
int i;
@ -92,11 +92,11 @@ namespace std {
$&1_descriptor, 0) == 0){
$1 = *v;
} else {
// It isn't a vector<T> so it should be a list of T's
// It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input, \
&nitems, &listobjv) == TCL_ERROR)
return TCL_ERROR;
$1 = std::vector<T>();
$1 = std::vector< T >();
for (i = 0; i < nitems; i++) {
if ((SWIG_ConvertPtr(listobjv[i],(void **) &temp,
$descriptor(T *),0)) != 0) {
@ -110,8 +110,8 @@ namespace std {
}
}
%typemap(in) const vector<T>* (std::vector<T> *v, std::vector<T> w),
const vector<T>& (std::vector<T> *v, std::vector<T> w) {
%typemap(in) const vector< T >* (std::vector< T > *v, std::vector< T > w),
const vector< T >& (std::vector< T > *v, std::vector< T > w) {
Tcl_Obj **listobjv;
int nitems;
int i;
@ -121,11 +121,11 @@ namespace std {
$&1_descriptor, 0) == 0) {
$1 = v;
} else {
// It isn't a vector<T> so it should be a list of T's
// It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR)
return TCL_ERROR;
w = std::vector<T>();
w = std::vector< T >();
for (i = 0; i < nitems; i++) {
if ((SWIG_ConvertPtr(listobjv[i],(void **) &temp,
$descriptor(T *),0)) != 0) {
@ -140,7 +140,7 @@ namespace std {
}
}
%typemap(out) vector<T> {
%typemap(out) vector< T > {
for (unsigned int i=0; i<$1.size(); i++) {
T* ptr = new T((($1_type &)$1)[i]);
Tcl_ListObjAppendElement(interp, $result, \
@ -150,18 +150,18 @@ namespace std {
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> {
%typecheck(SWIG_TYPECHECK_VECTOR) vector< T > {
Tcl_Obj **listobjv;
int nitems;
T* temp;
std::vector<T> *v;
std::vector< T > *v;
if(SWIG_ConvertPtr($input, (void **) &v, \
$&1_descriptor, 0) == 0) {
/* wrapped vector */
$1 = 1;
} else {
// It isn't a vector<T> so it should be a list of T's
// It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR)
$1 = 0;
@ -178,19 +178,19 @@ namespace std {
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&,
const vector<T>* {
%typecheck(SWIG_TYPECHECK_VECTOR) const vector< T >&,
const vector< T >* {
Tcl_Obj **listobjv;
int nitems;
T* temp;
std::vector<T> *v;
std::vector< T > *v;
if(SWIG_ConvertPtr($input, (void **) &v, \
$1_descriptor, 0) == 0){
/* wrapped vector */
$1 = 1;
} else {
// It isn't a vector<T> so it should be a list of T's
// It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR)
$1 = 0;
@ -210,7 +210,7 @@ namespace std {
public:
vector(unsigned int size = 0);
vector(unsigned int size, const T& value);
vector(const vector<T> &);
vector(const vector< T > &);
unsigned int size() const;
bool empty() const;
@ -248,9 +248,9 @@ namespace std {
// specializations for built-ins
%define specialize_std_vector(T, CONVERT_FROM, CONVERT_TO)
template<> class vector<T> {
template<> class vector< T > {
%typemap(in) vector<T> (std::vector<T> *v){
%typemap(in) vector< T > (std::vector< T > *v){
Tcl_Obj **listobjv;
int nitems;
int i;
@ -260,11 +260,11 @@ namespace std {
$&1_descriptor, 0) == 0) {
$1 = *v;
} else {
// It isn't a vector<T> so it should be a list of T's
// It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR)
return TCL_ERROR;
$1 = std::vector<T>();
$1 = std::vector< T >();
for (i = 0; i < nitems; i++) {
if (CONVERT_FROM(interp, listobjv[i], &temp) == TCL_ERROR)
return TCL_ERROR;
@ -273,8 +273,8 @@ namespace std {
}
}
%typemap(in) const vector<T>& (std::vector<T> *v,std::vector<T> w),
const vector<T>* (std::vector<T> *v,std::vector<T> w) {
%typemap(in) const vector< T >& (std::vector< T > *v,std::vector< T > w),
const vector< T >* (std::vector< T > *v,std::vector< T > w) {
Tcl_Obj **listobjv;
int nitems;
int i;
@ -284,11 +284,11 @@ namespace std {
$1_descriptor, 0) == 0) {
$1 = v;
} else {
// It isn't a vector<T> so it should be a list of T's
// It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR)
return TCL_ERROR;
w = std::vector<T>();
w = std::vector< T >();
for (i = 0; i < nitems; i++) {
if (CONVERT_FROM(interp, listobjv[i], &temp) == TCL_ERROR)
return TCL_ERROR;
@ -298,25 +298,25 @@ namespace std {
}
}
%typemap(out) vector<T> {
%typemap(out) vector< T > {
for (unsigned int i=0; i<$1.size(); i++) {
Tcl_ListObjAppendElement(interp, $result, \
CONVERT_TO((($1_type &)$1)[i]));
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> {
%typecheck(SWIG_TYPECHECK_VECTOR) vector< T > {
Tcl_Obj **listobjv;
int nitems;
T temp;
std::vector<T> *v;
std::vector< T > *v;
if(SWIG_ConvertPtr($input, (void **) &v, \
$&1_descriptor, 0) == 0){
/* wrapped vector */
$1 = 1;
} else {
// It isn't a vector<T> so it should be a list of T's
// It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR)
$1 = 0;
@ -331,19 +331,19 @@ namespace std {
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&,
const vector<T>*{
%typecheck(SWIG_TYPECHECK_VECTOR) const vector< T >&,
const vector< T >*{
Tcl_Obj **listobjv;
int nitems;
T temp;
std::vector<T> *v;
std::vector< T > *v;
if(SWIG_ConvertPtr($input, (void **) &v, \
$1_descriptor, 0) == 0){
/* wrapped vector */
$1 = 1;
} else {
// It isn't a vector<T> so it should be a list of T's
// It isn't a vector< T > so it should be a list of T's
if(Tcl_ListObjGetElements(interp, $input,
&nitems, &listobjv) == TCL_ERROR)
$1 = 0;
@ -361,7 +361,7 @@ namespace std {
public:
vector(unsigned int size = 0);
vector(unsigned int size, const T& value);
vector(const vector<T> &);
vector(const vector< T > &);
unsigned int size() const;
bool empty() const;

View file

@ -22,6 +22,11 @@ SWIGEXPORT int SWIG_init(Tcl_Interp *);
}
#endif
/* Compatibility version for TCL stubs */
#ifndef SWIG_TCL_STUBS_VERSION
#define SWIG_TCL_STUBS_VERSION "8.1"
#endif
%}
%init %{
@ -74,10 +79,18 @@ SWIGEXPORT int SWIG_init(Tcl_Interp *interp) {
int i;
if (interp == 0) return TCL_ERROR;
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, (char*)"8.1", 0) == NULL) {
/* (char*) cast is required to avoid compiler warning/error for Tcl < 8.4. */
if (Tcl_InitStubs(interp, (char*)SWIG_TCL_STUBS_VERSION, 0) == NULL) {
return TCL_ERROR;
}
#endif
#ifdef USE_TK_STUBS
/* (char*) cast is required to avoid compiler warning/error. */
if (Tk_InitStubs(interp, (char*)SWIG_TCL_STUBS_VERSION, 0) == NULL) {
return TCL_ERROR;
}
#endif
Tcl_PkgProvide(interp, (char*)SWIG_name, (char*)SWIG_version);
#ifdef SWIG_namespace

View file

@ -1,8 +1,8 @@
/* -----------------------------------------------------------------------------
* typemaps.i
*
* Swig typemap library for Tcl8. This file contains various sorts
* of typemaps for modifying Swig's code generation.
* SWIG typemap library for Tcl8. This file contains various sorts
* of typemaps for modifying SWIG's code generation.
* ----------------------------------------------------------------------------- */
#if !defined(SWIG_USE_OLD_TYPEMAPS)

View file

@ -18,7 +18,7 @@ typedef struct SWIGCDATA {
%typemap(out,noblock=1,fragment="SWIG_FromCharPtrAndSize") SWIGCDATA {
%set_output(SWIG_FromCharPtrAndSize($1.data,$1.len));
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int SIZE);
%typemap(in) (const void *indata, size_t inlen) = (char *STRING, size_t SIZE);
/* -----------------------------------------------------------------------------
@ -67,7 +67,8 @@ SWIGCDATA cdata_##NAME(TYPE *ptr, size_t nelements = 1);
%cdata(void);
/* Memory move function */
/* Memory move function. Due to multi-argument typemaps this appears to be wrapped as
void memmove(void *data, const char *s); */
void memmove(void *data, const void *indata, size_t inlen);

View file

@ -444,15 +444,15 @@ SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val)
%define %ensure_fragment(Fragment)
%fragment(`Fragment`,"header") {
%#error "Swig language implementation must provide the Fragment fragment"
%#error "SWIG language implementation must provide the Fragment fragment"
}
%enddef
%define %ensure_type_fragments(Type)
%fragment(SWIG_From_frag(Type),"header") {
%#error "Swig language implementation must provide a SWIG_From_frag(Type) fragment"
%#error "SWIG language implementation must provide a SWIG_From_frag(Type) fragment"
}
%fragment(SWIG_AsVal_frag(Type),"header") {
%#error "Swig language implementation must provide a SWIG_AsVal_frag(Type) fragment"
%#error "SWIG language implementation must provide a SWIG_AsVal_frag(Type) fragment"
}
%enddef

View file

@ -20,7 +20,7 @@
Casting Operations:
-------------------
Swig provides the following casting macros, which implement the
SWIG provides the following casting macros, which implement the
corresponding C++ casting operations:
%const_cast(a, Type) const_cast<Type >(a)
@ -173,7 +173,7 @@ nocppval
#endif /* __cplusplus */
/* -----------------------------------------------------------------------------
* Swig names and mangling
* SWIG names and mangling
* ----------------------------------------------------------------------------- */
#define %mangle(Type...) #@Type
@ -210,7 +210,7 @@ nocppval
%define %formacro_2(macro,...)%_formacro_2(macro, __VA_ARGS__, __fordone__)%enddef
/* -----------------------------------------------------------------------------
* Swig flags
* SWIG flags
* ----------------------------------------------------------------------------- */
/*