-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfileobj_example.cpp
56 lines (33 loc) · 994 Bytes
/
fileobj_example.cpp
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
45
46
47
48
49
50
51
52
53
54
55
// fileobj_example.cpp
//
// Copyright (c) 2009 - Michele De Stefano ([email protected])
//
// Distributed under the MIT License (See accompanying file COPYING)
/**
* \example fileobj_example.cpp
*
* A simple Python extension module that shows the mds_utils::python::FileObj usage.
*/
#include <boost/python.hpp>
#include <mds_utils/python/fileobj.hpp>
#include <iostream>
using namespace boost;
using namespace python;
using namespace std;
namespace mdspy = mds_utils::python;
double read_double(object &py_file) {
mdspy::FileObj fobj(py_file);
istream &ifs(fobj);
double val;
ifs.read(reinterpret_cast<char*>(&val),sizeof(double));
return val;
}
void write_double(object &py_file,double val) {
mdspy::FileObj fobj(py_file);
ostream &ofs(fobj);
ofs.write(reinterpret_cast<char*>(const_cast<double*>(&val)),sizeof(double));
}
BOOST_PYTHON_MODULE(fileobj_example) {
def("read_double",read_double);
def("write_double",write_double);
}