1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
/* -----------------------------------------------------------------------------
* attribute.swg
*
* Attribute implementation
* ----------------------------------------------------------------------------- */
/*
The following macros convert a pair of set/get methods
into a "native" attribute.
*/
//
// Define SWIG_ATTRIBUTE_TEMPLATE if you want to use templates instead of macros for the C++ get and set wrapper methods
// Does not always generate compilable code, use at your peril!
//
//#define SWIG_ATTRIBUTE_TEMPLATE
%define %attribute_custom(Class, AttributeType, AttributeName, GetMethod, SetMethod, GetMethodCall, SetMethodCall)
%ignore Class::GetMethod();
%ignore Class::GetMethod() const;
#if #SetMethod != #AttributeName
%ignore Class::SetMethod;
#endif
%extend Class {
AttributeType AttributeName;
}
#if defined(__cplusplus) && defined(SWIG_ATTRIBUTE_TEMPLATE)
%{
template < class C > inline AttributeType %mangle(Class) ##_## AttributeName ## _get(const C* self_) {
return GetMethodCall;
}
template < class C > inline AttributeType %mangle(Class) ##_## AttributeName ## _get(C* self_) {
return GetMethodCall;
}
template < class C > inline void %mangle(Class) ##_## AttributeName ## _set(C* self_, AttributeType val_) {
SetMethodCall;
}
%}
#else
%{
#define %mangle(Class) ##_## AttributeName ## _get(self_) GetMethodCall
#define %mangle(Class) ##_## AttributeName ## _set(self_, val_) SetMethodCall
%}
#endif
%enddef
%define %attribute_readonly(Class, AttributeType, AttributeName, GetMethod, GetMethodCall)
%ignore Class::GetMethod();
%ignore Class::GetMethod() const;
%immutable Class::AttributeName;
%extend Class {
AttributeType AttributeName;
}
#if defined(__cplusplus) && defined(SWIG_ATTRIBUTE_TEMPLATE)
%{
template < class C > inline AttributeType %mangle(Class) ##_## AttributeName ## _get(const C* self_) {
return GetMethodCall;
}
template < class C > inline AttributeType %mangle(Class) ##_## AttributeName ## _get(C* self_) {
return GetMethodCall;
}
%}
#else
%{
#define %mangle(Class) ##_## AttributeName ## _get(self_) GetMethodCall
%}
#endif
%enddef
// User macros
%define %attribute(Class, AttributeType, AttributeName, GetMethod, SetMethod...)
#if #SetMethod != ""
%attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, GetMethod, SetMethod, self_->GetMethod(), self_->SetMethod(val_))
#else
%attribute_readonly(%arg(Class), %arg(AttributeType), AttributeName, GetMethod, self_->GetMethod())
#endif
%enddef
%define %attribute2(Class, AttributeType, AttributeName, GetMethod, SetMethod...)
#if #SetMethod != ""
%attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, GetMethod, SetMethod, &self_->GetMethod(), self_->SetMethod(*val_))
#else
%attribute_readonly(%arg(Class), %arg(AttributeType), AttributeName, GetMethod, &self_->GetMethod())
#endif
%enddef
%define %attributeref(Class, AttributeType, AttributeName, AccessorMethod...)
#if #AccessorMethod != ""
%attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, AccessorMethod, AccessorMethod, self_->AccessorMethod(), self_->AccessorMethod() = val_)
#else
%attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, AttributeName, AttributeName, self_->AttributeName(), self_->AttributeName() = val_)
#endif
%enddef
%define %attribute2ref(Class, AttributeType, AttributeName, AccessorMethod...)
#if #AccessorMethod != ""
%attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, AccessorMethod, AccessorMethod, &self_->AccessorMethod(), self_->AccessorMethod() = *val_)
#else
%attribute_custom(%arg(Class), %arg(AttributeType), AttributeName, AttributeName, AttributeName, &self_->AttributeName(), self_->AttributeName() = *val_)
#endif
%enddef
%define %attributeval(Class, AttributeType, AttributeName, GetMethod, SetMethod...)
%{
#define %mangle(Class) ##_## AttributeName ## _get(self_) new AttributeType(self_->GetMethod())
%}
#if #SetMethod != ""
%{
#define %mangle(Class) ##_## AttributeName ## _set(self_, val_) self_->SetMethod(*val_)
%}
#if #SetMethod != #AttributeName
%ignore Class::SetMethod;
#endif
#else
%immutable Class::AttributeName;
#endif
%ignore Class::GetMethod();
%ignore Class::GetMethod() const;
%newobject Class::AttributeName;
%extend Class {
AttributeType AttributeName;
}
%enddef
%define %attributestring(Class, AttributeType, AttributeName, GetMethod, SetMethod...)
%{
#define %mangle(Class) ##_## AttributeName ## _get(self_) *new AttributeType(self_->GetMethod())
%}
#if #SetMethod != ""
%{
#define %mangle(Class) ##_## AttributeName ## _set(self_, val_) self_->SetMethod(val_)
%}
#if #SetMethod != #AttributeName
%ignore Class::SetMethod;
#endif
#else
%immutable Class::AttributeName;
#endif
%ignore Class::GetMethod();
%ignore Class::GetMethod() const;
%newobject Class::AttributeName;
%typemap(newfree) const AttributeType &AttributeName "delete $1;"
%extend Class {
AttributeType AttributeName;
}
%enddef
|