/
niceSOFT
/
swig
Обзор
Документация
Войти
/
niceSOFT
/
swig
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Examples/test-suite/template_methods.i
120 строк
4 KB
William S Fulton
Advanced %rename fixes for templates
25 апр 2026, 00:56
25 апр 2026, 00:56
ce06e2f
Код
Авторство
О чём код?
// Test %ignore and %rename for templated methods %module template_methods %warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve1<float>(); %warnfilter(SWIGWARN_LANG_TEMPLATE_METHOD_IGNORE) convolve3<float>(); %include <std_string.i> /////////////////// %ignore convolve1<float>(float a); %inline %{ template <typename ImageT> int convolve1() { return 0; } template <typename ImageT> void convolve1(ImageT a) { ImageT t = a; (void)t; } %} %template() convolve1<float>; %template(convolve1Bool) convolve1<bool>; /////////////////// %ignore convolve2<float>(float a); %inline %{ template <typename ImageT> int convolve2() { return 0; } template <typename ImageT> void convolve2(ImageT a) { ImageT t = a; (void)t; } %} %template(convolve2Float) convolve2<float>; /////////////////// %rename(convolve3FloatRenamed) convolve3<float>(float a); %inline %{ template <typename ImageT> int convolve3() { return 0; } template <typename ImageT> void convolve3(ImageT a) { ImageT t = a; (void)t; } %} %template() convolve3<float>; /////////////////// %rename(convolve4FloatRenamed) convolve4<float>(float a); %inline %{ template <typename ImageT> int convolve4() { return 0; } template <typename ImageT> void convolve4(ImageT a) { ImageT t = a; (void)t; } %} %template(convolve4Float) convolve4<float>; /////////////////// %rename(convolve5FloatRenamed) convolve5<float>; %ignore convolve5<bool>; %inline %{ template <typename ImageT> int convolve5() { return 0; } template <typename ImageT> void convolve5(ImageT a) { ImageT t = a; (void)t; } %} %template() convolve5<float>; %template() convolve5<bool>; //////////////////////////////////////////////////////////////////////////// %rename(KlassTMethodBoolRenamed) Klass::tmethod(bool); %rename(KlassStaticTMethodBoolRenamed) Klass::statictmethod(bool); %inline %{ struct Klass { template<typename X> X tmethod(X x) { return x; } template<typename X> void tmethod() {} template<typename X> static X statictmethod(X x) { return x; } template<typename X> static void statictmethod() {} }; %} %template(KlassTMethodBool) Klass::tmethod<bool>; %template(KlassStaticTMethodBool) Klass::statictmethod<bool>; //////////////////////////////////////////////////////////////////////////// // Rename just one of the overloaded instance and static methods %rename("ClayBoolRenamed_%s") Clay::cmethod(bool); %rename("ClayBoolStaticRenamed_%s") Clay::staticcmethod(bool); // Rename all the methods %rename("ClayIntRenamed_%s") Clay::cmethod<int>; %rename("ClayIntStaticRenamed_%s") Clay::staticcmethod<int>; %inline %{ struct Clay { template<typename X> X cmethod(X x) { return x; } template<typename X> void cmethod() {} template<typename X> static X staticcmethod(X x) { return x; } template<typename X> static void staticcmethod() {} }; %} %template(ClayCMethodBool) Clay::cmethod<bool>; %template(ClayStaticCMethodBool) Clay::staticcmethod<bool>; %template(ClayCMethodInt) Clay::cmethod<int>; %template(ClayStaticCMethodInt) Clay::staticcmethod<int>; //////////////////////////////////////////////////////////////////////////// %inline %{ class ComponentProperties{ public: ComponentProperties() {} ~ComponentProperties() {} template <typename T1> void adda(std::string key, T1 val) {} template <typename T1, typename T2> void adda(std::string key1, T1 val1, std::string key2, T2 val2) {} template <typename T1, typename T2, typename T3> void adda(std::string key1, T1 val1, std::string key2, T2 val2, std::string key3, T3 val3) {} }; %} %extend ComponentProperties { %template(adda) adda<std::string, double>; %template(adda) adda<std::string, std::string, std::string>; // ERROR OCCURS HERE %template(adda) adda<int, int, int>; }