swig/Examples/test-suite/director_unwrap_result.i
William S Fulton 2f55379687 Improve director unwrap detection for the return type
Resolve the return type to correctly determine if the type is a pointer or
reference to a director class.

SwigType_refptr_count_return() recently added as a simpler fix is no
longer needed.

The conventional approach of using the "type" rather than "decl" to
analyse the return type is used instead too.

Issue #1823
2022-10-10 08:45:26 +01:00

93 lines
1.8 KiB
OpenEdge ABL

%module(directors="1") director_unwrap_result
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) Storage;
%warnfilter(SWIGWARN_TYPEMAP_DIRECTOROUT_PTR) StorageTmpl;
%feature("director") Element;
%feature("director") Storage;
%feature("director") StorageTmpl;
%inline %{
class Element {
Element* self;
Element** selfptr;
public:
Element() {
self = this;
selfptr = &self;
}
virtual ~Element() {}
Element **getPtrPtr() {
return &self;
}
Element ***getPtrPtrPtr() {
return &selfptr;
}
};
typedef Element * element_ptr_t;
typedef Element & element_ref_t;
class Storage {
public:
virtual ~Storage() {}
virtual Element **getIt() = 0;
Element getElement() {
return **getIt();
}
Element* const getElementPtr() {
return *getIt();
}
Element& getElementRef() {
return **getIt();
}
Element* const *getElementPtrPtr() {
return getIt();
}
Element *&getElementPtrRef() {
return *getIt();
}
element_ref_t getElementRefTypedef() {
return **getIt();
}
element_ptr_t getElementPtrTypedef() {
return *getIt();
}
element_ptr_t &getElementPtrRefTypedef() {
return *getIt();
}
};
template<class T> class StorageTmpl {
public:
virtual ~StorageTmpl() {}
virtual T &getIt() = 0;
T getVal() {
return getIt();
}
T *getPtr() {
return &getIt();
}
T &getRef() {
return getIt();
}
};
%}
%template(ElementStorage) StorageTmpl<Element>;
%template(ElementPtrStorage) StorageTmpl<Element *>;
%template(ElementPtrPtrStorage) StorageTmpl<Element *const *>;
%inline %{
template<class T> T getParam(T t) {
return t;
}
%}
%template(getIntParam) getParam<int>;
%template(getIntPtrParam) getParam<int*>;
%template(getElementPtrParam) getParam<Element *>;