New templated method SwigValueInit to initialise all types - used initially for return types in director methods
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10063 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
08a45afc1b
commit
421eb7ae60
3 changed files with 18 additions and 4 deletions
18
Lib/swig.swg
18
Lib/swig.swg
|
|
@ -632,7 +632,7 @@ namespace std {
|
|||
#ifdef __cplusplus
|
||||
%insert("runtime") %{
|
||||
#ifdef __cplusplus
|
||||
template<class T> class SwigValueWrapper {
|
||||
template<typename T> class SwigValueWrapper {
|
||||
T *tt;
|
||||
public:
|
||||
SwigValueWrapper() : tt(0) { }
|
||||
|
|
@ -644,7 +644,21 @@ public:
|
|||
T *operator&() { return tt; }
|
||||
private:
|
||||
SwigValueWrapper& operator=(const SwigValueWrapper<T>& rhs);
|
||||
};
|
||||
};%}
|
||||
|
||||
/*
|
||||
* SwigValueInit() is a generic initialisation solution as the following approach:
|
||||
*
|
||||
* T c_result = T();
|
||||
*
|
||||
* doesn't compile for all types for example:
|
||||
*
|
||||
* unsigned int c_result = unsigned int();
|
||||
*/
|
||||
%insert("runtime") %{
|
||||
template <typename T> T SwigValueInit() {
|
||||
return T();
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3184,7 +3184,7 @@ public:
|
|||
if (!is_void && !ignored_method) {
|
||||
if (!SwigType_isclass(returntype)) {
|
||||
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
|
||||
String *construct_result = NewStringf("= %s()", SwigType_lstr(returntype, 0));
|
||||
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
|
||||
Delete(construct_result);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -3293,7 +3293,7 @@ public:
|
|||
if (!is_void && (!ignored_method || pure_virtual)) {
|
||||
if (!SwigType_isclass(returntype)) {
|
||||
if (!(SwigType_ispointer(returntype) || SwigType_isreference(returntype))) {
|
||||
String *construct_result = NewStringf("= %s()", SwigType_lstr(returntype, 0));
|
||||
String *construct_result = NewStringf("= SwigValueInit< %s >()", SwigType_lstr(returntype, 0));
|
||||
Wrapper_add_localv(w, "c_result", SwigType_lstr(returntype, "c_result"), construct_result, NIL);
|
||||
Delete(construct_result);
|
||||
} else {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue