【发布时间】:2012-11-29 09:23:55
【问题描述】:
我有两个 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 然后分配一个新的引用,还是我必须为类中的所有结构和函数获取新引用并使用这些引用创建一个新类?
【问题讨论】:
-
在问题本身中发布此内容
-
您究竟想通过“转换 C++ 对象”来完成什么?
boost::python是为了实现互操作性,所以我假设您想用 Python 代码使 C++ 应用程序“可扩展”,对吧?也许cython.org 可以帮助你? -
嗯,我正在开发用 c++ 编写的客户端到服务平台,以及服务必须用 python 编写的逻辑。直到现在我一直在使用 boost,但最近我被要求更改解释器我不能再使用 boost 的方法
标签: c++ python python-c-api