06/15/2006: mutandiz
[allegrocl] Add initial support for std::list container class. Fix a few bugs in helper functions. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9165 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6ed1cebc22
commit
080fa80ff3
3 changed files with 247 additions and 4 deletions
|
|
@ -1,6 +1,11 @@
|
|||
Version 1.3.30 (in progress)
|
||||
============================
|
||||
|
||||
06/15/2006: mutandiz
|
||||
[allegrocl]
|
||||
Add initial support for std::list container class.
|
||||
Fix a few bugs in helper functions.
|
||||
|
||||
05/13/2006: wsfulton
|
||||
[Java] Replace JNIEXPORT with SWIGEXPORT, thereby enabling the possibility
|
||||
of using gcc -fvisibility=hidden for potentially smaller faster loading wrappers.
|
||||
|
|
|
|||
|
|
@ -257,8 +257,13 @@ $body)"
|
|||
(defun scm-p1 (form)
|
||||
(let* ((info (second form))
|
||||
(id (car info))
|
||||
(id-args (cddr info)))
|
||||
(apply *swig-identifier-converter* id id-args)))
|
||||
(id-args (if (eq (car form) 'swig-dispatcher)
|
||||
(cdr info)
|
||||
(cddr info))))
|
||||
(apply *swig-identifier-converter* id
|
||||
(progn (when (eq (car form) 'swig-dispatcher)
|
||||
(remf id-args :arities))
|
||||
id-args))))
|
||||
|
||||
(defmacro defswig1 (name (&rest args) &body body)
|
||||
`(progn (defmacro ,name ,args
|
||||
|
|
@ -275,7 +280,9 @@ $body)"
|
|||
(read-from-string string nil "eof" :preserve-whitespace t)
|
||||
(if (and (symbolp result) (eql position (length string)))
|
||||
result
|
||||
(intern string))))
|
||||
(multiple-value-bind (sym)
|
||||
(intern string)
|
||||
sym))))
|
||||
|
||||
(defun full-name (id type arity class)
|
||||
(case type
|
||||
|
|
@ -396,7 +403,7 @@ $body)"
|
|||
,@(maybe-return-value symbol defun-args))))))
|
||||
|
||||
(defswig1 swig-defmethod ((name &optional (mangled-name name)
|
||||
&key (type :operator) class arity)
|
||||
&key (type :operator) class arity)
|
||||
ffargs kwargs
|
||||
&body body)
|
||||
(let* ((symbol (id-convert-and-export name :type type
|
||||
|
|
|
|||
231
Lib/allegrocl/std_list.i
Executable file
231
Lib/allegrocl/std_list.i
Executable file
|
|
@ -0,0 +1,231 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* 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.
|
||||
*
|
||||
* std_list.i
|
||||
*
|
||||
* SWIG typemaps for std::list types
|
||||
*
|
||||
* To use, add:
|
||||
*
|
||||
* %include "std_list.i"
|
||||
*
|
||||
* to your interface file. You will also need to include a template directive
|
||||
* for each instance of the list container you want to use in your application.
|
||||
* e.g.
|
||||
*
|
||||
* %template (intlist) std::list<int>;
|
||||
* %template (floatlist) std::list<float>;
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "inout_typemaps.i"\
|
||||
%module std_list
|
||||
%warnfilter(468) std::list;
|
||||
|
||||
%{
|
||||
#include <list>
|
||||
#include <stdexcept>
|
||||
%}
|
||||
|
||||
|
||||
namespace std{
|
||||
template<class T> class list
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T &reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T &iterator;
|
||||
typedef const T& const_iterator;
|
||||
|
||||
list();
|
||||
list(unsigned int size, const T& value = T());
|
||||
list(const list<T> &);
|
||||
|
||||
~list();
|
||||
void assign(unsigned int n, const T& value);
|
||||
void swap(list<T> &x);
|
||||
|
||||
const_reference front();
|
||||
const_reference back();
|
||||
const_iterator begin();
|
||||
const_iterator end();
|
||||
|
||||
void resize(unsigned int n, T c = T());
|
||||
bool empty() const;
|
||||
|
||||
void push_front(const T& INPUT);
|
||||
void push_back(const T& INPUT);
|
||||
|
||||
|
||||
void pop_front();
|
||||
void pop_back();
|
||||
void clear();
|
||||
unsigned int size() const;
|
||||
unsigned int max_size() const;
|
||||
void resize(unsigned int n, const T& INPUT);
|
||||
|
||||
void remove(const T& INPUT);
|
||||
void unique();
|
||||
void reverse();
|
||||
void sort();
|
||||
|
||||
%extend
|
||||
{
|
||||
const_reference __getitem__(int i) throw (std::out_of_range)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
int size = int(self->size());
|
||||
if (i<0) i += size;
|
||||
if (i>=0 && i<size)
|
||||
{
|
||||
for (int k=0;k<i;k++)
|
||||
{
|
||||
first++;
|
||||
}
|
||||
return *first;
|
||||
}
|
||||
else throw std::out_of_range("list index out of range");
|
||||
}
|
||||
void __setitem__(int i, const T& INPUT) throw (std::out_of_range)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
int size = int(self->size());
|
||||
if (i<0) i += size;
|
||||
if (i>=0 && i<size)
|
||||
{
|
||||
for (int k=0;k<i;k++)
|
||||
{
|
||||
first++;
|
||||
}
|
||||
*first = INPUT;
|
||||
}
|
||||
else throw std::out_of_range("list index out of range");
|
||||
}
|
||||
void __delitem__(int i) throw (std::out_of_range)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
int size = int(self->size());
|
||||
if (i<0) i += size;
|
||||
if (i>=0 && i<size)
|
||||
{
|
||||
for (int k=0;k<i;k++)
|
||||
{
|
||||
first++;
|
||||
}
|
||||
self->erase(first);
|
||||
}
|
||||
else throw std::out_of_range("list index out of range");
|
||||
}
|
||||
std::list<T> __getslice__(int i,int j)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
std::list<T>::iterator end = self->end();
|
||||
|
||||
int size = int(self->size());
|
||||
if (i<0) i += size;
|
||||
if (j<0) j += size;
|
||||
if (i<0) i = 0;
|
||||
if (j>size) j = size;
|
||||
if (i>=j) i=j;
|
||||
if (i>=0 && i<size && j>=0)
|
||||
{
|
||||
for (int k=0;k<i;k++)
|
||||
{
|
||||
first++;
|
||||
}
|
||||
for (int m=0;m<j;m++)
|
||||
{
|
||||
end++;
|
||||
}
|
||||
std::list<T> tmp(j-i);
|
||||
if (j>i) std::copy(first,end,tmp.begin());
|
||||
return tmp;
|
||||
}
|
||||
else throw std::out_of_range("list index out of range");
|
||||
}
|
||||
void __delslice__(int i,int j)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
std::list<T>::iterator end = self->end();
|
||||
|
||||
int size = int(self->size());
|
||||
if (i<0) i += size;
|
||||
if (j<0) j += size;
|
||||
if (i<0) i = 0;
|
||||
if (j>size) j = size;
|
||||
|
||||
for (int k=0;k<i;k++)
|
||||
{
|
||||
first++;
|
||||
}
|
||||
for (int m=0;m<=j;m++)
|
||||
{
|
||||
end++;
|
||||
}
|
||||
self->erase(first,end);
|
||||
}
|
||||
void __setslice__(int i,int j, const std::list<T>& v)
|
||||
{
|
||||
std::list<T>::iterator first = self->begin();
|
||||
std::list<T>::iterator end = self->end();
|
||||
|
||||
int size = int(self->size());
|
||||
if (i<0) i += size;
|
||||
if (j<0) j += size;
|
||||
if (i<0) i = 0;
|
||||
if (j>size) j = size;
|
||||
|
||||
for (int k=0;k<i;k++)
|
||||
{
|
||||
first++;
|
||||
}
|
||||
for (int m=0;m<=j;m++)
|
||||
{
|
||||
end++;
|
||||
}
|
||||
if (int(v.size()) == j-i)
|
||||
{
|
||||
std::copy(v.begin(),v.end(),first);
|
||||
}
|
||||
else {
|
||||
self->erase(first,end);
|
||||
if (i+1 <= int(self->size()))
|
||||
{
|
||||
first = self->begin();
|
||||
for (int k=0;k<i;k++)
|
||||
{
|
||||
first++;
|
||||
}
|
||||
self->insert(first,v.begin(),v.end());
|
||||
}
|
||||
else self->insert(self->end(),v.begin(),v.end());
|
||||
}
|
||||
|
||||
}
|
||||
unsigned int __len__()
|
||||
{
|
||||
return self->size();
|
||||
}
|
||||
bool __nonzero__()
|
||||
{
|
||||
return !(self->empty());
|
||||
}
|
||||
void append(const T& INPUT)
|
||||
{
|
||||
self->push_back(INPUT);
|
||||
}
|
||||
void pop()
|
||||
{
|
||||
self->pop_back();
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue