Add std::unique support
Simple copy of current auto_ptr support (just suppport for functions returning std::unique_ptr). Closes #1722
This commit is contained in:
parent
1993b334a6
commit
299880e6a6
14 changed files with 443 additions and 15 deletions
53
Examples/test-suite/cpp11_std_unique_ptr.i
Normal file
53
Examples/test-suite/cpp11_std_unique_ptr.i
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
%module cpp11_std_unique_ptr
|
||||
|
||||
#if defined(SWIGCSHARP) || defined(SWIGJAVA) || defined(SWIGPYTHON) || defined(SWIGRUBY)
|
||||
|
||||
%include "std_unique_ptr.i"
|
||||
|
||||
%unique_ptr(Klass)
|
||||
|
||||
%inline %{
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include "swig_examples_lock.h"
|
||||
|
||||
class Klass {
|
||||
public:
|
||||
explicit Klass(const char* label) :
|
||||
m_label(label)
|
||||
{
|
||||
SwigExamples::Lock lock(critical_section);
|
||||
total_count++;
|
||||
}
|
||||
|
||||
const char* getLabel() const { return m_label.c_str(); }
|
||||
|
||||
~Klass()
|
||||
{
|
||||
SwigExamples::Lock lock(critical_section);
|
||||
total_count--;
|
||||
}
|
||||
|
||||
static int getTotal_count() { return total_count; }
|
||||
|
||||
private:
|
||||
static SwigExamples::CriticalSection critical_section;
|
||||
static int total_count;
|
||||
|
||||
std::string m_label;
|
||||
};
|
||||
|
||||
SwigExamples::CriticalSection Klass::critical_section;
|
||||
int Klass::total_count = 0;
|
||||
|
||||
%}
|
||||
|
||||
%inline %{
|
||||
|
||||
std::unique_ptr<Klass> makeKlassUniquePtr(const char* label) {
|
||||
return std::unique_ptr<Klass>(new Klass(label));
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue