加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何将C对象转换为PyObject?

发布时间:2020-12-16 07:02:26 所属栏目:百科 来源:网络整理
导读:我有两个c对象 int queueIndex Timer timer_obj 这是定时器类的定义 class Timer{private: struct timeval tStart; /** @brief Stores the system time when the timer is started */ struct timeval tFinish; /** @brief Stores the system time when the t
我有两个c对象

int queueIndex
    Timer timer_obj

这是定时器类的定义

class Timer
{

private:
    struct timeval tStart; /**< @brief Stores the system time when the timer is started */
    struct timeval tFinish; /**< @brief Stores the system time when the timer is stopped */

protected:
    float getElapsedTime(struct timeval,struct timeval);

public:
    Timer();
    string currentTime();
    float currentElapsedTime();
    void restart();
    float stop();
    int high_pres_usleep_untill(unsigned long long int);
    string getStringStartTimer();
    void setStartTimerFromString(string);
    void sleep(long int);
    unsigned long long int get_clock();

我需要将这两个对象转换为PyObj *.我正在使用boost :: python来实现此目的.我现在希望在没有boost或swig的情况下完成它.
我成功转换了索引,但我对timer_obj一无所知

PyObject* pyo=PyInt_FromLong(queueIndex)

如果有人可以帮我解决这个问题,我会感激不尽.我只需要一个你不需要给我完整代码的例子.同样在类中定义的函数有点复杂,所以我没有在这里给它们.是否有可能转换timer_obj然后分配一个新的引用或者我是否必须为类中的所有结构和函数获取新的引用并创建一个带有这些引用的新类?

解决方法

你需要做的是创建一个 extension type.不幸的是,这个过程相对复杂,需要几百行代码.这是boost :: python和SWIG的整个python,用于删除所有样板文件.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读