Fwd: access enclosing class name in a %macro to allow defining attributes without having to use the %attribute macro
Alessio M <[email protected]> Fri, 3 Nov 2023 14:23:57 +0000
| Newsgroups | gmane.comp.programming.swig |
|---|---|
| Message-ID | <CAL_VXba-+ux3dRNSVAsDd=ybP9LnDqfM_6eZXC00RwHmxtnVDA@mail.gmail.com> |
Greetings
Question: can a %macro in SWIG somehow access the name of the enclosing
class type in a statement like %mangle(...)?
The objective here is to avoid having to use the %attribute macros
I would prefer to write hpp files as follows and just %include them without
any need for %attribute
// foo.hpp
class Foo {
READONLY_PROPERTY(Bar, bar);
};
Following the technique used in attributes.swg I came up with the following
possible definition for a READONLY_PROPERTY C++ macro.
The only issue is the %mangle(Class) statement. If I could access the
enclosing class name, then this would work quite nicely.
Thank you for any advice you can provide
#ifndef SWIG
#define READONLY_PROPERTY(Type, Name) Type Name() const
#else // SWIG defined
#define READONLY_PROPERTY(Type, Name)
\
%ignore Name() const;
\
Type Name() const;
\
%immutable Name;
\
%extend {
\
Type Name;
\
}
\
%{
\
template < class C > inline Type %mangle(Class) ##_## Name ##
_get(const C* self_) { \
return self_->Name();
\
}
\
%}
_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user