PageRenderTime 22ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/refcount.i

#
Swig | 123 lines | 92 code | 31 blank | 0 comment | 0 complexity | f6b1cfe9b08e82c6e27bcc044bbbcaf5 MD5 | raw file
  1%module refcount
  2
  3%warnfilter(SWIGWARN_IGNORE_OPERATOR_EQ,SWIGWARN_LANG_IDENTIFIER);
  4
  5%{ 
  6#include <iostream> 
  7#include "refcount.h"
  8%}
  9
 10//
 11// using the %refobject/%unrefobject directives you can activate the
 12// reference counting for RCObj and all its descendents at once
 13//
 14
 15%refobject   RCObj "$this->addref();"
 16%unrefobject RCObj "$this->delref();"
 17
 18%include "refcount.h"
 19
 20%newobject B::create(A* a);
 21%newobject global_create(A* a);
 22%newobject B::cloner();
 23%newobject Factory::create(A* a);
 24%newobject Factory::create2(A* a);
 25
 26
 27 
 28%inline %{
 29
 30  struct A : RCObj
 31  {
 32    A() {}
 33    
 34    ~A() 
 35    {
 36      // std::cout << "deleting a" << std::endl;
 37    }
 38
 39#ifdef SWIGRUBY 
 40    // fix strange ruby + virtual derivation problem
 41    using RCObjBase::ref_count;
 42#endif
 43  };
 44
 45  struct A1 : A 
 46  {
 47  protected:
 48    A1() {}
 49  };
 50
 51  struct A2 : A
 52  {
 53  };
 54
 55  struct A3 : A1, private A2
 56  {    
 57  };
 58
 59%}
 60
 61#if defined(SWIGPYTHON)
 62%extend_smart_pointer(RCPtr<A>);
 63%template(RCPtr_A) RCPtr<A>;
 64#endif
 65
 66%inline %{
 67  
 68  struct B : RCObj
 69  {
 70    B(A* a) : _a(a) {}
 71    
 72    A* get_a() 
 73    {
 74      return _a;
 75    }
 76    
 77    static B* create(A* a)
 78    {
 79      return new B(a);
 80    }
 81    
 82    B* cloner() 
 83    {
 84      return new B(_a);
 85    }
 86
 87    ~B() 
 88    {
 89      // std::cout << "deleting b" << std::endl;
 90    }
 91
 92    RCPtr<A> get_rca() {
 93      return _a;      
 94    }
 95
 96  private:
 97    RCPtr<A> _a;
 98  };
 99
100class B* global_create(A* a)
101{
102  return new B(a);
103}
104
105struct Factory {
106  static B* create(A* a)
107  {
108    return new B(a);
109  }
110  B* create2(A* a)
111  {
112    return new B(a);
113  }
114};
115
116%}
117
118#if defined(SWIGPYTHON) || defined(SWIGOCTAVE)
119
120%include <std_vector.i>
121%template(vector_A) std::vector<RCPtr<A> >;
122
123#endif