// SWIG typemaps for std::list types
// based on existing std_vector.i
// ------------------------------------------------------------------------
// The aim of all that follows would be to integrate std::list with
// Perl as much as possible, namely, to allow the user to pass and
// be returned Perl arrays.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
// -- f(std::list<T>), f(const std::list<T>&), f(const std::list<T>*):
// the parameter being read-only, either a Perl sequence or a
// previously wrapped std::list<T> can be passed.
// -- f(std::list<T>&), f(std::list<T>*):
// the parameter must be modified; therefore, only a wrapped std::list
// the list is returned by copy; therefore, a Perl sequence of T:s
// is returned which is most easily used in other Perl functions
// -- std::list<T>& f(), std::list<T>* f(), const std::list<T>& f(),
// const std::list<T>* f():
// the list is returned by reference; therefore, a wrapped std::list
// ------------------------------------------------------------------------
template<class T> class list {
%typemap(in) list<T> (std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1) {
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
SWIG_croak("Type error in argument $argnum of "
"Expected an array of " #T);
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
%typemap(in) const list<T>& (std::list<T> temp,
const list<T>* (std::list<T> temp,
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
SWIG_croak("Type error in argument $argnum of "
"Expected an array of " #T);
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
std::list<T>::const_iterator i;
for (i=$1.begin(), j=0; i!=$1.end(); i++, j++) {
SWIG_MakePtr(svs[j], (void*) ptr,
$descriptor(T *), $shadow|$owner);
AV *myav = av_make(len, svs);
$result = newRV_noinc((SV*) myav);
%typecheck(SWIG_TYPECHECK_LIST) list<T> {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_&descriptor,0) != -1) {
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
/* an empty sequence can be of any type */
/* check the first element only */
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
%typecheck(SWIG_TYPECHECK_LIST) const list<T>&,
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
/* an empty sequence can be of any type */
/* check the first element only */
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
unsigned int size() const;
void push_back(const T& x);
// specializations for built-ins
%define specialize_std_list(T,CHECK_T,TO_T,FROM_T)
template<> class list<T> {
%typemap(in) list<T> (std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1){
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
SWIG_croak("Type error in argument $argnum of "
"Expected an array of " #T);
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
%typemap(in) const list<T>& (std::list<T> temp,
const list<T>* (std::list<T> temp,
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
temp.push_back(TO_T(*tv));
SWIG_croak("Type error in argument $argnum of "
"Expected an array of " #T);
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
std::list<T>::const_iterator i;
for (i=$1.begin(), j=0; i!=$1.end(); i++, j++) {
AV *myav = av_make(len, svs);
$result = newRV_noinc((SV*) myav);
%typecheck(SWIG_TYPECHECK_LIST) list<T> {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_&descriptor,0) != -1) {
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
/* an empty sequence can be of any type */
/* check the first element only */
%typecheck(SWIG_TYPECHECK_LIST) const list<T>&,
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
/* an empty sequence can be of any type */
/* check the first element only */
unsigned int size() const;
specialize_std_list(bool,SvIOK,SvIVX,sv_setiv);
specialize_std_list(char,SvIOK,SvIVX,sv_setiv);
specialize_std_list(int,SvIOK,SvIVX,sv_setiv);
specialize_std_list(short,SvIOK,SvIVX,sv_setiv);
specialize_std_list(long,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned char,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned int,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned short,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned long,SvIOK,SvIVX,sv_setiv);
specialize_std_list(float,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_list(double,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_list(std::string,SvPOK,SvPVX,SwigSvFromString);