Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Donate
Please sign in before you donate.
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
1 Star 0 Fork 11

ding465398889/ffpython

forked from EvanZhaoOwn/ffpython
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (1)
master
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
The license selected for the repository is subject to the license used by the main branch of the repository.
master
Branches (1)
master
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (1)
master
ffpython
/
example.cpp
ffpython
/
example.cpp
example.cpp 4.86 KB
Copy Edit Raw Blame History
Evan Zhao authored 2014年04月23日 19:16 +08:00 . add more support cache pyobject
#ifdef _WIN32
#include <cstdlib>
#endif
#include "ffpython.h"
#define TestGuard(X, Y) printf("-------%s begin-----------\n", X);try {Y;}catch(exception& e_){printf("exception<%s>\n", e_.what());}\
printf("-------%s end-----------\n", X);
void test_base(ffpython_t& ffpython)
{
printf("sys.version=%s\n", ffpython.get_global_var<string>("sys", "version").c_str());
ffpython.set_global_var("fftest", "global_var", "OhNice");
printf("fftest.global_var=%s\n", ffpython.get_global_var<string>("fftest", "global_var").c_str());
printf("time.asctime=%s\n", ffpython.call<string>("time", "asctime").c_str());
int a1 = 100; float a2 = 3.14f; string a3 = "OhWell";
ffpython.call<void>("fftest", "test_base", a1, a2, a3);
}
void test_stl(ffpython_t& ffpython)
{
vector<int> a1;a1.push_back(100);a1.push_back(200);
list<string> a2; a2.push_back("Oh");a2.push_back("Nice");
vector<list<string> > a3;a3.push_back(a2);
ffpython.call<bool>("fftest", "test_stl", a1, a2, a3);
}
void test_return_stl(ffpython_t& ffpython)
{
typedef map<string, list<vector<int> > > ret_t;
ret_t val = ffpython.call<ret_t>("fftest", "test_return_stl");
}
static int print_val(int a1, float a2, const string& a3, const vector<double>& a4)
{
printf("%s[%d,%f,%s,%d]\n", __FUNCTION__, a1, a2, a3.c_str(), a4.size());
return 0;
}
struct ops_t
{
static list<int> return_stl()
{
list<int> ret;ret.push_back(1024);
printf("%s\n", __FUNCTION__);
return ret;
}
};
void test_reg_function()
{
ffpython_t ffpython;//("ext1");
ffpython.reg(&print_val, "print_val")
.reg(&ops_t::return_stl, "return_stl");
ffpython.init("ext1");
ffpython.call<void>("fftest", "test_reg_function");
}
class foo_t
{
public:
foo_t(int v_):m_value(v_)
{
printf("%s\n", __FUNCTION__);
}
virtual ~foo_t()
{
printf("%s\n", __FUNCTION__);
}
int get_value() const { return m_value; }
void set_value(int v_) { m_value = v_; }
void test_stl(map<string, list<int> >& v_)
{
printf("%s\n", __FUNCTION__);
}
int m_value;
};
class dumy_t: public foo_t
{
public:
dumy_t(int v_):foo_t(v_)
{
printf("%s\n", __FUNCTION__);
}
~dumy_t()
{
printf("%s\n", __FUNCTION__);
}
void dump()
{
printf("%s\n", __FUNCTION__);
}
};
static foo_t* obj_test(dumy_t* p)
{
printf("%s\n", __FUNCTION__);
return p;
}
void test_register_base_class(ffpython_t& ffpython)
{
ffpython.reg_class<foo_t, PYCTOR(int)>("foo_t")
.reg(&foo_t::get_value, "get_value")
.reg(&foo_t::set_value, "set_value")
.reg(&foo_t::test_stl, "test_stl")
.reg_property(&foo_t::m_value, "m_value");
ffpython.reg_class<dumy_t, PYCTOR(int)>("dumy_t", "dumy_t class inherit foo_t ctor <int>", "foo_t")
.reg(&dumy_t::dump, "dump");
ffpython.reg(obj_test, "obj_test");
ffpython.init("ext2");
ffpython.call<void>("fftest", "test_register_base_class");
};
void test_register_inherit_class(ffpython_t& ffpython)
{
ffpython.call<void>("fftest", "test_register_inherit_class");
};
void test_cpp_obj_to_py(ffpython_t& ffpython)
{
foo_t tmp_foo(2013);
vector<foo_t*> vt;
vt.push_back(&tmp_foo);
ffpython.call<void>("fftest", "test_cpp_obj_to_py", &tmp_foo);
printf("test_cpp_obj_to_py changed m_value=%d\n", tmp_foo.m_value);
ffpython.call<void>("fftest", "test_cpp_obj_to_py_ext", vt);
}
void test_cpp_obj_py_obj(ffpython_t& ffpython)
{
dumy_t tmp_foo(2013);
foo_t* p = ffpython.call<foo_t*>("fftest", "test_cpp_obj_py_obj", &tmp_foo);
p = NULL;
}
void test_py_class_lambda(ffpython_t& ffpython)
{
PyObject* pobj = ffpython.call<PyObject*>("fftest", "test_cpp_obj_return_py_obj");
ffpython.obj_call<void>(pobj, "sayHi", 1, string("soNice"));
PyObject* pFunc= ffpython.call<PyObject*>("fftest", "test_cpp_obj_return_py_lambda");
ffpython.call_lambda<void>(pFunc, 112233);
Py_XDECREF(pFunc);
Py_XDECREF(pobj);
}
int main(int argc, char* argv[])
{
Py_Initialize();
ffpython_t::add_path("./");
ffpython_t ffpython;//("ext2");
TestGuard("test_base", test_base(ffpython));
TestGuard("test_stl", test_stl(ffpython));
TestGuard("test_reg_function", test_reg_function());
TestGuard("test_register_base_class", test_register_base_class(ffpython));
TestGuard("test_register_inherit_class", test_register_inherit_class(ffpython));
TestGuard("test_cpp_obj_to_py", test_cpp_obj_to_py(ffpython));
TestGuard("test_cpp_obj_py_obj", test_cpp_obj_py_obj(ffpython));
TestGuard("test_py_class_lambda", test_py_class_lambda(ffpython));
#ifdef _WIN32
system("pause");
#endif
Py_Finalize();
printf("main exit...\n");
return 0;
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

About

ffpython is a c++ lib,which is to simplify embedding python and extend python. For example, call python function, register c++ function to python, register c++ class to python, on one implement c++ header file.
Cancel

Releases

No release

Contributors

All

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/dragondjf/ffpython.git
git@gitee.com:dragondjf/ffpython.git
dragondjf
ffpython
ffpython
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /