MCPcopy Create free account
hub / github.com/TNG/boost-python-examples / main

Function main

13-AutoInstantiation/auto_instance.cpp:15–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13#endif
14
15int main(int argc, char** argv)
16{
17 try {
18 PyImport_AppendInittab((char*)"myextension", INIT_MODULE);
19 Py_Initialize();
20 object main_module = import("__main__");
21 dict main_namespace = extract<dict>(main_module.attr("__dict__"));
22 object myextension = import("myextension");
23 dict myextension_namespace = extract<dict>(myextension.attr("__dict__"));
24
25 exec_file( str("auto_instance.py"), main_namespace, main_namespace);
26 object BaseClass = myextension_namespace["Base"];
27 PyTypeObject* base_class = reinterpret_cast<PyTypeObject*>(BaseClass.ptr());
28
29 list keys = main_namespace.keys();
30 for (unsigned int i = 0; i<len(keys) ; ++i) {
31 object k = keys[i];
32 object item = main_namespace[k];
33 PyObject* item_ptr = item.ptr();
34 if ( PyType_Check(item_ptr) != 0 ) {
35 PyTypeObject* type_obj = reinterpret_cast<PyTypeObject*>(item_ptr);
36 if ( ( type_obj != base_class) && ( PyType_IsSubtype( type_obj, base_class) > 0) ) {
37 object obj = item();
38 const Base& base_obj = extract<Base>(obj);
39 std::cout << base_obj.name() << std::endl;
40 }
41 }
42 }
43
44 } catch (error_already_set& e) {
45 PyErr_PrintEx(0);
46 return 1;
47 }
48 return 0;
49}

Callers

nothing calls this directly

Calls 1

nameMethod · 0.45

Tested by

no test coverage detected