Skip to content
Snippets Groups Projects
Commit 7fa5b929 authored by Julien Malik's avatar Julien Malik
Browse files

ENH: put swig macros in specific files

parent e4d45c8c
No related branches found
No related tags found
No related merge requests found
......@@ -16,5 +16,6 @@ FOREACH(swigfile ${swigfiles})
ENDFOREACH(swigfile ${swigfiles})
# TODO: add build dependency with the macro files
SWIG_ADD_MODULE(core python core.i)
SWIG_LINK_LIBRARIES(core ${PYTHON_LIBRARIES} OTBWrapperCore)
%include <exception.i>
%include <typemaps.i>
// This macro replaces the use of itk::SmartPointer.
// class_name is class name without namespace qualifiers.
// Reference: http://www.nabble.com/attachment/16653644/0/SwigRefCount.i
%define DECLARE_REF_COUNT_CLASS(class_name)
// pointers and references
%typemap(out) class_name *, class_name & {
// always tell SWIG_NewPointerObj we're the owner
$result = SWIG_NewPointerObj((void *) $1, $1_descriptor, 1);
if ($1) {
$1->Register();
}
}
// transform smart pointers in raw pointers
%typemap(out) class_name##_Pointer {
// get the raw pointer from the smart pointer
class_name * ptr = $1;
// always tell SWIG_NewPointerObj we're the owner
$result = SWIG_NewPointerObj((void *) ptr, $descriptor(class_name *), 1);
// register the object, it it exists
if (ptr) {
ptr->Register();
}
}
// transform smart pointers in raw pointers
%typemap(out) class_name##_Pointer & {
// get the raw pointer from the smart pointer
class_name * ptr = *$1;
// always tell SWIG_NewPointerObj we're the owner
$result = SWIG_NewPointerObj((void *) ptr, $descriptor(class_name *), 1);
// register the object, it it exists
if (ptr) {
ptr->Register();
}
}
// make "deletion" in scripting language just decrement ref. count
%extend class_name {
public:
~class_name() {self->UnRegister();};
}
%ignore class_name::~class_name;
%ignore class_name##_Pointer;
%pythoncode {
def class_name##_New():
return class_name.New()
}
%enddef
%include <exception.i>
%include <typemaps.i>
// This macro replaces the use of itk::SmartPointer.
// class_name is class name without namespace qualifiers.
// Reference: http://www.nabble.com/attachment/16653644/0/SwigRefCount.i
%define DECLARE_REF_COUNT_CLASS(class_name)
// pointers and references
%typemap(out) class_name *, class_name & {
// always tell SWIG_NewPointerObj we're the owner
$result = SWIG_NewPointerObj((void *) $1, $1_descriptor, 1);
if ($1) {
$1->Register();
}
}
// transform smart pointers in raw pointers
%typemap(out) class_name##_Pointer {
// get the raw pointer from the smart pointer
class_name * ptr = $1;
// always tell SWIG_NewPointerObj we're the owner
$result = SWIG_NewPointerObj((void *) ptr, $descriptor(class_name *), 1);
// register the object, it it exists
if (ptr) {
ptr->Register();
}
}
// transform smart pointers in raw pointers
%typemap(out) class_name##_Pointer & {
// get the raw pointer from the smart pointer
class_name * ptr = *$1;
// always tell SWIG_NewPointerObj we're the owner
$result = SWIG_NewPointerObj((void *) ptr, $descriptor(class_name *), 1);
// register the object, it it exists
if (ptr) {
ptr->Register();
}
}
// make "deletion" in scripting language just decrement ref. count
%extend class_name {
public:
~class_name() {self->UnRegister();};
}
%ignore class_name::~class_name;
%ignore class_name##_Pointer;
%pythoncode {
def class_name##_New():
return class_name.New()
}
%enddef
%include "itkMacro.i"
%include "RefCountMacro.i"
%module core
%{
......@@ -88,9 +31,7 @@ enum DefaultValueMode
*/
ABSOLUTE
};
}
}
......@@ -104,62 +45,36 @@ class Parameter : public itkObject
{
public:
/** Standard class typedef */
typedef Parameter Self;
typedef itkObject Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Defining ::New() static method */
static Parameter_Pointer New(void);
/** Set the parameter name */
void SetName (const char*);
itkSetStringMacro(Name);
itkGetStringMacro(Name);
/** Get the parameter name */
const char* GetName() const;
itkSetStringMacro(Description);
itkGetStringMacro(Description);
/** Set the parameter description */
void SetDescription (const char*);
itkSetStringMacro(Key);
itkGetStringMacro(Key);
/** Get the parameter description */
const char* GetDescription() const;
itkSetMacro(Mandatory,bool);
itkGetMacro(Mandatory,bool);
itkBooleanMacro(Mandatory);
/** Set the parameter key */
void SetKey (const char*);
itkSetEnumMacro(DefaultValueMode, otb::Wrapper::DefaultValueMode);
itkGetEnumMacro(DefaultValueMode, otb::Wrapper::DefaultValueMode);
/** Get the parameter key */
const char* GetKey() const;
/** Set the parameter mandatory flag */
void SetMandatory (bool);
/** Get the parameter mandatory flag */
bool GetMandatory();
/** Toogle the parameter mandatory flag */
void MandatoryOn ();
void MandatoryOff ();
/** Set the default value mode */
virtual void SetDefaultValueMode (const otb::Wrapper::DefaultValueMode _arg);
/** Get the default value mode */
otb::Wrapper::DefaultValueMode GetDefaultValueMode() const;
/** Reset to the the default value. Default implementation does
* nothing
*/
virtual void Reset();
protected:
protected:
Parameter();
/** Destructor */
//~Parameter();
private:
private:
Parameter(const Parameter &);
void operator =(const Parameter&);
......@@ -179,10 +94,10 @@ class Parameter_Pointer
Parameter * GetPointer() const;
bool operator<(Parameter_Pointer const & r) const;
bool operator>(Parameter_Pointer const & r) const;
// bool operator<=(Parameter_Pointer const & r) const;
// bool operator>=(Parameter_Pointer const & r) const;
// Parameter_Pointer & operator=(Parameter_Pointer const & r);
// Parameter_Pointer & operator=(Parameter * r);
bool operator<=(Parameter_Pointer const & r) const;
bool operator>=(Parameter_Pointer const & r) const;
Parameter_Pointer & operator=(Parameter_Pointer const & r);
Parameter_Pointer & operator=(Parameter * r);
Parameter * Print(std::ostream & os) const;
private:
void Register();
......
%define itkSetStringMacro(name)
void Set##name (const char* _arg);
%enddef
%define itkGetStringMacro(name)
const char* Get##name () const;
%enddef
%define itkSetMacro(name, type)
void Set##name (type _arg);
%enddef
%define itkGetMacro(name, type)
type Get##name ();
%enddef
%define itkBooleanMacro(name)
void name##On ();
void name##Off ();
%enddef
%define itkSetEnumMacro(name, type)
void Set##name (const type _arg);
%enddef
%define itkGetEnumMacro(name, type)
type Get##name () const;
%enddef
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment