use forward declaration to treat the dependency of fragments
This commit is contained in:
parent
377d439964
commit
b32854bc59
4 changed files with 35 additions and 16 deletions
|
|
@ -9,9 +9,9 @@
|
|||
#include <vector>
|
||||
%}
|
||||
|
||||
%include std_vector.i
|
||||
%include std_map.i
|
||||
%include std_shared_ptr.i
|
||||
%include <std_vector.i>
|
||||
%include <std_map.i>
|
||||
%include <std_shared_ptr.i>
|
||||
|
||||
%{
|
||||
|
||||
|
|
|
|||
|
|
@ -3,12 +3,11 @@
|
|||
* The Ruby classes, for C++
|
||||
* ------------------------------------------------------------ */
|
||||
%include <rubyclasses.swg>
|
||||
%include <rubystdcommon_forward.swg>
|
||||
|
||||
%fragment("StdTraits","header",fragment="StdTraitsCommon")
|
||||
%fragment("StdTraits","header",fragment="StdTraitsCommon",fragment="StdTraitsForwardDeclaration")
|
||||
{
|
||||
|
||||
%#define SWIG_RUBYSTDCOMMON
|
||||
|
||||
namespace swig {
|
||||
/*
|
||||
Traits that provides the from method
|
||||
|
|
|
|||
14
Lib/ruby/rubystdcommon_forward.swg
Normal file
14
Lib/ruby/rubystdcommon_forward.swg
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
%fragment("StdTraitsForwardDeclaration","header")
|
||||
{
|
||||
namespace swig {
|
||||
template <class Type> struct traits_asptr;
|
||||
template <class Type> struct traits_asval;
|
||||
struct pointer_category;
|
||||
template <class Type, class Category> struct traits_as;
|
||||
template<class Type> struct traits_from;
|
||||
template <class Type> struct noconst_traits;
|
||||
template <class Type> swig_type_info* type_info();
|
||||
template <class Type> const char* type_name();
|
||||
template <class Type> VALUE from(const Type& val);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,16 +1,15 @@
|
|||
#define SWIG_SHARED_PTR_NAMESPACE std
|
||||
%include <boost_shared_ptr.i>
|
||||
%include <rubystdcommon_forward.swg>
|
||||
|
||||
|
||||
/*
|
||||
* We want to put the following code after the fragment "StdTraits" at rubystdcommon.swg.
|
||||
* This code is needed if and only if the fragment and this std_shared_ptr.i are included at the same time.
|
||||
* They don't always require each other. The order of including them is not predetermined either.
|
||||
* So specifying the dependecy by using %fragment does not work.
|
||||
*/
|
||||
%wrapper %{
|
||||
#ifdef SWIG_RUBYSTDCOMMON
|
||||
%fragment("StdSharedPtrTraits","header",fragment="StdTraitsForwardDeclaration")
|
||||
{
|
||||
namespace swig {
|
||||
/*
|
||||
template specialization for functions defined in rubystdcommon.swg.
|
||||
here we should treat smart pointers in a way different from the way we treat raw pointers.
|
||||
*/
|
||||
template <class Type>
|
||||
struct traits_asptr<std::shared_ptr<Type> > {
|
||||
static int asptr(VALUE obj, std::shared_ptr<Type> **val) {
|
||||
|
|
@ -84,6 +83,11 @@ namespace swig {
|
|||
}
|
||||
};
|
||||
|
||||
/*
|
||||
we have to remove the const qualifier to work around a BUG
|
||||
SWIG_TypeQuery("std::shared_ptr<const Type>") == NULL,
|
||||
which is caused by %template treating const qualifiers not properly.
|
||||
*/
|
||||
template<class Type>
|
||||
struct traits_from<std::shared_ptr<const Type> > {
|
||||
static VALUE from(const std::shared_ptr<const Type>& val) {
|
||||
|
|
@ -92,5 +96,7 @@ namespace swig {
|
|||
}
|
||||
};
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
}
|
||||
|
||||
//force the fragment.
|
||||
%fragment("StdSharedPtrTraits");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue