| 46 | } // namespace |
| 47 | |
| 48 | void bindPyContext(py::module & m) |
| 49 | { |
| 50 | ContextRcPtr DEFAULT = Context::Create(); |
| 51 | |
| 52 | auto clsContext = |
| 53 | py::class_<Context, ContextRcPtr>( |
| 54 | m.attr("Context")); |
| 55 | |
| 56 | auto clsStringVarNameIterator = |
| 57 | py::class_<StringVarNameIterator>( |
| 58 | clsContext, "StringVarNameIterator"); |
| 59 | |
| 60 | auto clsStringVarIterator = |
| 61 | py::class_<StringVarIterator>( |
| 62 | clsContext, "StringVarIterator"); |
| 63 | |
| 64 | auto clsSearchPathIterator = |
| 65 | py::class_<SearchPathIterator>( |
| 66 | clsContext, "SearchPathIterator"); |
| 67 | |
| 68 | clsContext |
| 69 | .def(py::init(&Context::Create), |
| 70 | DOC(Context, Create)) |
| 71 | .def(py::init([](const std::string & workingDir, |
| 72 | const std::vector<std::string> & searchPaths, |
| 73 | const std::map<std::string, std::string> stringVars, |
| 74 | EnvironmentMode environmentMode) |
| 75 | { |
| 76 | ContextRcPtr p = Context::Create(); |
| 77 | if (!workingDir.empty()) { p->setWorkingDir(workingDir.c_str()); } |
| 78 | |
| 79 | if (!searchPaths.empty()) |
| 80 | { |
| 81 | for (const auto & path : searchPaths) |
| 82 | { |
| 83 | p->addSearchPath(path.c_str()); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | if (!stringVars.empty()) |
| 88 | { |
| 89 | for (const auto & var: stringVars) |
| 90 | { |
| 91 | p->setStringVar(var.first.c_str(), var.second.c_str()); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | p->setEnvironmentMode(environmentMode); |
| 96 | return p; |
| 97 | }), |
| 98 | "workingDir"_a = DEFAULT->getWorkingDir(), |
| 99 | "searchPaths"_a = getSearchPathsStdVec(DEFAULT), |
| 100 | "stringVars"_a = getStringVarsStdMap(DEFAULT), |
| 101 | "environmentMode"_a = DEFAULT->getEnvironmentMode(), |
| 102 | DOC(Context, Create)) |
| 103 | |
| 104 | .def("__deepcopy__", [](const ConstContextRcPtr & self, py::dict) |
| 105 | { |
no test coverage detected