00001
00002
00003
00004
00005
00006
00007
00008 #include <boost/python.hpp>
00009 #include <boost/filesystem/path.hpp>
00010
00011 using namespace boost::python;
00012
00013 struct path_to_python
00014 {
00015 static PyObject* convert(boost::filesystem::path const& p)
00016 {
00017 return incref(object(p.string()).ptr());
00018 }
00019 };
00020
00021 struct path_from_python
00022 {
00023 path_from_python()
00024 {
00025 converter::registry::push_back(
00026 &convertible, &construct, type_id<boost::filesystem::path>()
00027 );
00028 }
00029
00030 static void* convertible(PyObject* x)
00031 {
00032 return PyString_Check(x) ? x : 0;
00033 }
00034
00035 static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
00036 {
00037 void* storage = ((converter::rvalue_from_python_storage<
00038 boost::filesystem::path
00039 >*)data)->storage.bytes;
00040 new (storage) boost::filesystem::path(PyString_AsString(x));
00041 data->convertible = storage;
00042 }
00043 };
00044
00045 void bind_filesystem()
00046 {
00047 to_python_converter<boost::filesystem::path, path_to_python>();
00048 path_from_python();
00049
00050 boost::filesystem::path::default_name_check(boost::filesystem::native);
00051 }
00052