将我自己的get/set c++成员函数视为SWIG中的成员变量
Treat my own get/set C++ member functions as a member variable in SWIG?
在最低级别,SWIG通过生成一对访问器函数来处理c++类成员变量,例如from:
class List {
public:
int length;
...
};
痛饮创建:
int List_length_get(List *obj) { return obj->length; }
int List_length_set(List *obj, int value) {
obj->length = value;
return value;
}
我是否可以提供自己的访问器,并告诉SWIG使用它们在Python中创建"虚拟"成员变量?例如:
class List {
public:
int setLength(int aLength) { _length = aLength; return _length; }
int getLength() { return _length; }
...
private:
int _length;
...
};
告诉SWIG让我这样做:
>>> l = List();
>>> print(l.length)
在Python中?
我希望我没有侵犯任何版权。
从http://swig.10945.n7.nabble.com/attribute-directive-and-C-templates-td11288.html我最近发现了如何使用
attribute.i
和%attribute
指令创建具有自定义行为的属性,如下面(多余的)示例:%attribute(Point, int, x, getX, setX); %attribute(Point, int, y, getY, setY); class Point { public: int getX() { return _x }; void setX(int x) { _x = x }; int getY() { return _y }; void setY(int y) { _y = y }; private: int _x; int _y; }
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 助记符和指向成员语法的指针
- 用于访问容器<T>数据成员的正确 API
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 找不到成员对象:没有名为get_event()的成员,也处理多态性和向量
- 嵌套在类中时无法设置成员数据
- 使用 Swig 在成员中包装具有互斥锁的 C++ 类时出现问题
- 如何在 SWIG 中包装可变参数模板类的可变参数模板成员函数?
- 如何使用 SWIG 枚举枚举成员
- 使用SWIG包装C 类,该类调用另一个对象成员函数
- 当返回对成员变量的引用时,SWIG-Java内存管理
- 如何使用P/Invoke使用SWIG类型映射将结构成员从c++编组到c#
- 将我自己的get/set c++成员函数视为SWIG中的成员变量
- 错误 C2039: 'type_name': 不是 的成员 'swig::traits<Bar>'
- 不能在SWIG包装器中公开私有基类成员函数