Add SWIG macros

pull/1726/head
Daniele Forsi IU5HKX 2025-06-21 17:43:46 +02:00
rodzic c453cc788d
commit 68633fa627
2 zmienionych plików z 93 dodań i 1 usunięć

Wyświetl plik

@ -9,7 +9,7 @@ AM_CPPFLAGS = @AM_CPPFLAGS@ -I$(top_srcdir)/include -I$(top_srcdir)/bindings \
AM_CFLAGS = @AM_CPPFLAGS@ -fno-strict-aliasing
AM_CXXFLAGS = -O2
SWGFILES = hamlib.swg ignore.swg rig.swg rotator.swg amplifier.swg
SWGFILES = hamlib.swg ignore.swg rig.swg rotator.swg amplifier.swg macros.swg
SWGDEP = \
$(top_srcdir)/include/hamlib/rig.h \

Wyświetl plik

@ -0,0 +1,92 @@
/*
Common SWIG macros
*/
/*
* Macro GET_TOKEN
*
* function_prefix:
* the first part of the function name (eg. one of: amp_ rig_ rot_)
*
* function_name:
* the name that will be seen in the bindings and that creates a valid Hamlib function
* name when appended to the function_prefix
*
* class_pointer:
* the pointer to the instance of the class (eg. one of self->amp self->rig self->rot)
*/
%define GET_TOKEN(function_prefix, function_name, class_pointer)
PyObject * ##function_name(hamlib_token_t token)
{
int value;
self->error_status = ##function_prefix ##function_name(##class_pointer, token, &value);
if (self->error_status != RIG_OK)
return Py_None;
return PyLong_FromLong(value);
}
%enddef
/*
* Macro GET_VALUE_T
*
* function_prefix:
* the first part of the function name (eg. one of: amp_ rig_ rot_)
*
* function_name:
* the name that creates a valid Hamlib function name when appended to the
* function_prefix
*
* class_pointer:
* the pointer to the instance of the class (eg. one of self->amp self->rig self->rot)
*
* level_prefix:
* the prefix of the macro that checks the datatype (eg. one of AMP_ RIG_ ROT_)
*/
%define GET_VALUE_T(function_prefix, function_name, class_pointer, level_prefix)
PyObject * ##function_name(hamlib_token_t token)
{
value_t value;
self->error_status = ##function_prefix ##function_name(##class_pointer, token, &value);
if (self->error_status != RIG_OK)
return Py_None;
#if defined(##level_prefix LEVEL_IS_FLOAT)
if (##level_prefix LEVEL_IS_FLOAT(token))
return PyFloat_FromDouble(value.f);
#endif
#if defined(##level_prefix LEVEL_IS_STRING)
if (##level_prefix LEVEL_IS_STRING(token))
return PyUnicode_FromString(value.s);
#endif
return PyLong_FromLong(value.i);
}
%enddef
/*
* Macro ROT_GET_LONG
*
* function_name:
* the name that will be seen in the bindings when appended to get_
* and that creates a valid Hamlib function when appended to rot_get_
* eg. ROT_GET_LONG(func) creates Rot.get_func() that calls rot_get_func()
*/
%define ROT_GET_LONG(function_name)
GET_TOKEN(rot_, get_ ##function_name, self->rot)
%enddef
/*
* Macro ROT_GET_VALUE_T
*
* function_name:
* the name that will be seen in the bindings when appended to get_
* and that creates a valid Hamlib function when appended to rot_get_
* eg. ROT_GET_VALUE_T(level) creates Rot.get_level() that calls rot_get_level()
*/
%define ROT_GET_VALUE_T(function_name)
GET_VALUE_T(rot_, get_ ##function_name, self->rot, ROT_)
%enddef