-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathschedule_py.cc
44 lines (37 loc) · 1.02 KB
/
schedule_py.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "schedule_lib.h"
#include <boost/python.hpp>
#include <google/protobuf/text_format.h>
#include <boost/foreach.hpp>
#include <boost/python/class.hpp>
#include <boost/python/module.hpp>
#include <boost/python/def.hpp>
#include <boost/python/list.hpp>
#include <boost/python/extract.hpp>
#include <boost/python/object.hpp>
#include <boost/python/stl_iterator.hpp>
#include <boost/python/handle.hpp>
namespace py = boost::python;
using namespace std;
using namespace schedule;
class SchedulerWrapper {
public:
string MakeSchedule(const string& tasks_str) {
Tasks tasks;
Schedules schedules;
string schedules_str;
tasks.ParseFromString(tasks_str);
if (make_schedule(tasks, &schedules)) {
schedules.SerializeToString(&schedules_str);
return schedules_str;
} else {
return "";
}
}
};
BOOST_PYTHON_MODULE(schedule_pylib) {
// below, we prepend an underscore to methods that will be replaced
// in Python
py::class_<SchedulerWrapper>("Scheduler")
.def("MakeSchedule", &SchedulerWrapper::MakeSchedule)
;
}