~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to bindings/python/src/filesystem.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2008-07-02 10:46:21 UTC
  • Revision ID: james.westby@ubuntu.com-20080702104621-jzx3pfke9lkcxfxn
Tags: upstream-0.13.1
ImportĀ upstreamĀ versionĀ 0.13.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright Daniel Wallin 2006. Use, modification and distribution is
 
2
// subject to the Boost Software License, Version 1.0. (See accompanying
 
3
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
4
 
 
5
#include <boost/python.hpp>
 
6
#include <boost/filesystem/path.hpp>
 
7
 
 
8
using namespace boost::python;
 
9
 
 
10
struct path_to_python
 
11
{
 
12
    static PyObject* convert(boost::filesystem::path const& p)
 
13
    {
 
14
        return incref(object(p.string()).ptr());
 
15
    }
 
16
};
 
17
 
 
18
struct path_from_python
 
19
{
 
20
    path_from_python()
 
21
    {
 
22
        converter::registry::push_back(
 
23
            &convertible, &construct, type_id<boost::filesystem::path>()
 
24
        );
 
25
    }
 
26
 
 
27
    static void* convertible(PyObject* x)
 
28
    {
 
29
        return PyString_Check(x) ? x : 0;
 
30
    }
 
31
 
 
32
    static void construct(PyObject* x, converter::rvalue_from_python_stage1_data* data)
 
33
    {
 
34
        void* storage = ((converter::rvalue_from_python_storage<
 
35
            boost::filesystem::path
 
36
        >*)data)->storage.bytes;
 
37
        new (storage) boost::filesystem::path(PyString_AsString(x));
 
38
        data->convertible = storage;
 
39
    }
 
40
};
 
41
 
 
42
void bind_filesystem()
 
43
{
 
44
    to_python_converter<boost::filesystem::path, path_to_python>();
 
45
    path_from_python();
 
46
 
 
47
    using namespace boost::filesystem;
 
48
    if (path::default_name_check_writable())
 
49
        path::default_name_check(no_check);
 
50
}
 
51