/tags/rel-1.3.35/Lib/guile/std_pair.i
Swig | 871 lines | 824 code | 23 blank | 24 comment | 0 complexity | 86710b40c524f78b092b4a4b8399a534 MD5 | raw file
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
- /* -----------------------------------------------------------------------------
- * 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_pair.i
- *
- * SWIG typemaps for std::pair
- * ----------------------------------------------------------------------------- */
- %include <std_common.i>
- %include <exception.i>
- // ------------------------------------------------------------------------
- // std::pair
- //
- // See std_vector.i for the rationale of typemap application
- // ------------------------------------------------------------------------
- %{
- #include <utility>
- %}
- // exported class
- namespace std {
- template<class T, class U> struct pair {
- %typemap(in) pair<T,U> (std::pair<T,U>* m) {
- if (gh_pair_p($input)) {
- T* x;
- U* y;
- SCM first, second;
- first = gh_car($input);
- second = gh_cdr($input);
- x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0);
- y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0);
- $1 = std::make_pair(*x,*y);
- } else {
- $1 = *(($&1_type)
- SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0));
- }
- }
- %typemap(in) const pair<T,U>& (std::pair<T,U> temp,
- std::pair<T,U>* m),
- const pair<T,U>* (std::pair<T,U> temp,
- std::pair<T,U>* m) {
- if (gh_pair_p($input)) {
- T* x;
- U* y;
- SCM first, second;
- first = gh_car($input);
- second = gh_cdr($input);
- x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0);
- y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0);
- temp = std::make_pair(*x,*y);
- $1 = &temp;
- } else {
- $1 = ($1_ltype)
- SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0);
- }
- }
- %typemap(out) pair<T,U> {
- T* x = new T($1.first);
- U* y = new U($1.second);
- SCM first = SWIG_NewPointerObj(x,$descriptor(T *), 1);
- SCM second = SWIG_NewPointerObj(y,$descriptor(U *), 1);
- $result = gh_cons(first,second);
- }
- %typecheck(SWIG_TYPECHECK_PAIR) pair<T,U> {
- /* native pair? */
- if (gh_pair_p($input)) {
- T* x;
- U* y;
- SCM first = gh_car($input);
- SCM second = gh_cdr($input);
- if (SWIG_ConvertPtr(first,(void**) &x,
- $descriptor(T *), 0) == 0 &&
- SWIG_ConvertPtr(second,(void**) &y,
- $descriptor(U *), 0) == 0) {
- $1 = 1;
- } else {
- $1 = 0;
- }
- } else {
- /* wrapped pair? */
- std::pair<T,U >* m;
- if (SWIG_ConvertPtr($input,(void **) &m,
- $&1_descriptor, 0) == 0)
- $1 = 1;
- else
- $1 = 0;
- }
- }
- %typecheck(SWIG_TYPECHECK_PAIR) const pair<T,U>&,
- const pair<T,U>* {
- /* native pair? */
- if (gh_pair_p($input)) {
- T* x;
- U* y;
- SCM first = gh_car($input);
- SCM second = gh_cdr($input);
- if (SWIG_ConvertPtr(first,(void**) &x,
- $descriptor(T *), 0) == 0 &&
- SWIG_ConvertPtr(second,(void**) &y,
- $descriptor(U *), 0) == 0) {
- $1 = 1;
- } else {
- $1 = 0;
- }
- } else {
- /* wrapped pair? */
- std::pair<T,U >* m;
- if (SWIG_ConvertPtr($input,(void **) &m,
- $1_descriptor, 0) == 0)
- $1 = 1;
- else
- $1 = 0;
- }
- }
- pair();
- pair(T first, U second);
- pair(const pair& p);
- template <class U1, class U2> pair(const pair<U1, U2> &p);
- T first;
- U second;
- };
- // specializations for built-ins
- %define specialize_std_pair_on_first(T,CHECK,CONVERT_FROM,CONVERT_TO)
- template<class U> struct pair<T,U> {
- %typemap(in) pair<T,U> (std::pair<T,U>* m) {
- if (gh_pair_p($input)) {
- U* y;
- SCM first, second;
- first = gh_car($input);
- second = gh_cdr($input);
- if (!CHECK(first))
- SWIG_exception(SWIG_TypeError,
- "map<" #T "," #U "> expected");
- y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0);
- $1 = std::make_pair(CONVERT_FROM(first),*y);
- } else {
- $1 = *(($&1_type)
- SWIG_MustGetPtr($input,$&1_descriptor,$argnum, 0));
- }
- }
- %typemap(in) const pair<T,U>& (std::pair<T,U> temp,
- std::pair<T,U>* m),
- const pair<T,U>* (std::pair<T,U> temp,
- std::pair<T,U>* m) {
- if (gh_pair_p($input)) {
- U* y;
- SCM first, second;
- first = gh_car($input);
- second = gh_cdr($input);
- if (!CHECK(first))
- SWIG_exception(SWIG_TypeError,
- "map<" #T "," #U "> expected");
- y = (U*) SWIG_MustGetPtr(second,$descriptor(U *),$argnum, 0);
- temp = std::make_pair(CONVERT_FROM(first),*y);
- $1 = &temp;
- } else {
- $1 = ($1_ltype)
- SWIG_MustGetPtr($input,$1_descriptor,$argnum, 0);
- }
- }
- %typemap(out) pair<T,U> {
- U* y = new U($1.second);
- SCM second = SWIG_NewPointerObj(y,$descriptor(U *), 1);
- $result = gh_cons(CONVERT_TO($1.first),second);
- }
- %typecheck(SWIG_TYPECHECK_PAIR) pair<T,U> {
- /* native pair? */
- if (gh_pair_p($input)) {
- U* y;
- SCM first = gh_car($input);
- SCM second = gh_cdr($input);
- if (CHECK(first) &&
- SWIG_ConvertPtr(second,(void**) &y,
- $descriptor(U *), 0) == 0) {
- $1 = 1;
- } else {
- $1 = 0;
- }
- } else {
- /* wrapped pair? */
- std::pair<T,U >* m;
- if (SWIG_ConvertPtr($input,(void **) &m,
- $&1_descriptor, 0) == 0)
- $1 = 1;
- else
- $1 = 0;
- }
- }
- %typecheck(SWIG_TYPECHECK_PAIR) const pair<T,U>&,
- const pair<T,U>* {
- /* native pair? */
- if (gh_pair_p($input)) {
- U* y;
- SCM first = gh_car($input);
- SCM second = gh_cdr($input);
- if (CHECK(first) &&
- SWIG_ConvertPtr(second,(void**) &y,
- $descriptor(U *), 0) == 0) {
- $1 = 1;
- } else {
- $1 = 0;
- }
- } else {
- /* wrapped pair? */
- std::pair<T,U >* m;
- if (SWIG_ConvertPtr($input,(void **) &m,
- $1_descriptor, 0) == 0)
- $1 = 1;
- else
- $1 = 0;
- }
- }
- pair();
- pair(T first, U second);
- pair(const pair& p);
- template <class U1, class U2> pair(const pair<U1, U2> &p);
- T first;
- U second;
- };
- %enddef
- %define specialize_std_pair_on_second(U,CHECK,CONVERT_FROM,CONVERT_TO)
- template<class T> struct pair<T,U> {
- %typemap(in) pair<T,U> (std::pair<T,U>* m) {
- if (gh_pair_p($input)) {
- T* x;
- SCM first, second;
- first = gh_car($input);
- second = gh_cdr($input);
- x = (T*) SWIG_MustGetPtr(first,$descriptor(T *),$argnum, 0);
- if (!CHECK(second))
- SWIG_exception(SWIG_TypeError,
- "map<" #T "," #U "> expected");
- $1 = std::make_pair(*x,CONVERT_FROM(second));
- } else {
-