Skip to content

Commit 02bd853

Browse files
committed
Fix Issue #14. Code formatting
1 parent e75522d commit 02bd853

1,491 files changed

Lines changed: 155205 additions & 154846 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 95 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,129 @@
1-
/*!
1+
/*!
22
* \file bindings/python/include/TFEL/Python/MapConverter.hxx
33
* \brief
44
* \author Helfer Thomas
55
* \brief 11 mars 2013
6-
* \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7-
* reserved.
8-
* This project is publicly released under either the GNU GPL Licence
9-
* or the CECILL-A licence. A copy of thoses licences are delivered
10-
* with the sources of TFEL. CEA or EDF may also distribute this
11-
* project under specific licensing conditions.
6+
* \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7+
* reserved.
8+
* This project is publicly released under either the GNU GPL Licence
9+
* or the CECILL-A licence. A copy of thoses licences are delivered
10+
* with the sources of TFEL. CEA or EDF may also distribute this
11+
* project under specific licensing conditions.
1212
*/
1313

1414
#ifndef LIB_TFEL_PYTHON_MAPCONVERTER_H_
15-
#define LIB_TFEL_PYTHON_MAPCONVERTER_H_
15+
#define LIB_TFEL_PYTHON_MAPCONVERTER_H_
1616

17-
#include<map>
17+
#include <map>
1818

19-
#include<boost/python.hpp>
20-
#include<boost/python/stl_iterator.hpp>
19+
#include <boost/python.hpp>
20+
#include <boost/python/stl_iterator.hpp>
2121

22-
namespace tfel
23-
{
22+
namespace tfel {
2423

25-
namespace python
26-
{
24+
namespace python {
2725

2826
/*!
2927
* convert map converter to python dict
3028
*/
31-
template<typename K,
32-
typename V>
33-
struct map_to_python_dict
34-
{
35-
static PyObject* convert(const std::map<K,V>& v)
36-
{
37-
using namespace std;
38-
using namespace boost::python;
39-
using boost::python::iterator;
40-
typename map<K,V>::const_iterator p;
41-
dict d;
42-
for(p=v.begin();p!=v.end();++p){
43-
d[p->first] = p->second;
44-
}
45-
return incref(d.ptr());
29+
template <typename K, typename V>
30+
struct map_to_python_dict {
31+
static PyObject* convert(const std::map<K, V>& v) {
32+
using namespace std;
33+
using namespace boost::python;
34+
using boost::python::iterator;
35+
typename map<K, V>::const_iterator p;
36+
dict d;
37+
for (p = v.begin(); p != v.end(); ++p) {
38+
d[p->first] = p->second;
39+
}
40+
return incref(d.ptr());
4641
}
4742
};
4843

49-
template<typename K,
50-
typename V>
51-
struct map_from_python_dict
52-
{
53-
54-
map_from_python_dict()
55-
{
56-
using boost::python::type_id;
57-
using namespace boost::python::converter;
58-
registry::push_back(&convertible,&construct,
59-
type_id<std::map<K,V> > ());
44+
template <typename K, typename V>
45+
struct map_from_python_dict {
46+
map_from_python_dict() {
47+
using boost::python::type_id;
48+
using namespace boost::python::converter;
49+
registry::push_back(&convertible, &construct,
50+
type_id<std::map<K, V>>());
6051
}
6152

62-
static void* convertible(PyObject * ptr)
63-
{
64-
using namespace boost::python;
65-
if (!PyDict_Check(ptr)){
66-
return nullptr;
67-
}
68-
handle<> h(borrowed(ptr));
69-
dict d(h);
70-
list keys = d.keys();
71-
list values = d.values();
72-
stl_input_iterator<object> pk(keys);
73-
stl_input_iterator<object> pv(values);
74-
stl_input_iterator<object> pe;
75-
while(pk!=pe){
76-
extract<K> k(*pk);
77-
extract<V> v(*pv);
78-
if(!k.check()){
79-
return nullptr;
80-
}
81-
if(!v.check()){
82-
return nullptr;
83-
}
84-
++pk;
85-
++pv;
86-
}
87-
return ptr;
53+
static void* convertible(PyObject* ptr) {
54+
using namespace boost::python;
55+
if (!PyDict_Check(ptr)) {
56+
return nullptr;
57+
}
58+
handle<> h(borrowed(ptr));
59+
dict d(h);
60+
list keys = d.keys();
61+
list values = d.values();
62+
stl_input_iterator<object> pk(keys);
63+
stl_input_iterator<object> pv(values);
64+
stl_input_iterator<object> pe;
65+
while (pk != pe) {
66+
extract<K> k(*pk);
67+
extract<V> v(*pv);
68+
if (!k.check()) {
69+
return nullptr;
70+
}
71+
if (!v.check()) {
72+
return nullptr;
73+
}
74+
++pk;
75+
++pv;
76+
}
77+
return ptr;
8878
}
8979

90-
static void construct(PyObject* ptr,
91-
boost::python::converter::rvalue_from_python_stage1_data * data)
92-
{
93-
using namespace boost::python;
94-
using namespace boost::python::converter;
95-
typedef rvalue_from_python_storage<std::map<K,V> > py_storage;
96-
using std::map;
97-
assert(PyDict_Check(ptr));
98-
handle<> h(borrowed(ptr));
99-
dict d(h);
100-
list keys = d.keys();
101-
list values = d.values();
102-
stl_input_iterator<object> pk(keys);
103-
stl_input_iterator<object> pv(values);
104-
stl_input_iterator<object> pe;
105-
// Grab pointer to memory into which to construct the new map<T>
106-
void* storage = reinterpret_cast<py_storage *>(data)->storage.bytes;
107-
// in-place construct the new map<T> using the character data
108-
// extraced from the python object
109-
new (storage) map<K,V>();
110-
map<K,V>& m = *(static_cast<map<K,V> *>(storage));
111-
while(pk!=pe){
112-
extract<K> k(*pk);
113-
extract<V> v(*pv);
114-
assert(k.check());
115-
assert(v.check());
116-
m[k()] = v();
117-
++pk;
118-
++pv;
119-
}
120-
// Stash the memory chunk pointer for later use by boost.python
121-
data->convertible = storage;
80+
static void construct(
81+
PyObject* ptr,
82+
boost::python::converter::rvalue_from_python_stage1_data* data) {
83+
using namespace boost::python;
84+
using namespace boost::python::converter;
85+
typedef rvalue_from_python_storage<std::map<K, V>> py_storage;
86+
using std::map;
87+
assert(PyDict_Check(ptr));
88+
handle<> h(borrowed(ptr));
89+
dict d(h);
90+
list keys = d.keys();
91+
list values = d.values();
92+
stl_input_iterator<object> pk(keys);
93+
stl_input_iterator<object> pv(values);
94+
stl_input_iterator<object> pe;
95+
// Grab pointer to memory into which to construct the new map<T>
96+
void* storage = reinterpret_cast<py_storage*>(data)->storage.bytes;
97+
// in-place construct the new map<T> using the character data
98+
// extraced from the python object
99+
new (storage) map<K, V>();
100+
map<K, V>& m = *(static_cast<map<K, V>*>(storage));
101+
while (pk != pe) {
102+
extract<K> k(*pk);
103+
extract<V> v(*pv);
104+
assert(k.check());
105+
assert(v.check());
106+
m[k()] = v();
107+
++pk;
108+
++pv;
109+
}
110+
// Stash the memory chunk pointer for later use by boost.python
111+
data->convertible = storage;
122112
}
123-
124113
};
125114

126-
template<typename K,
127-
typename V>
128-
static void initializeMapConverter()
129-
{
115+
template <typename K, typename V>
116+
static void initializeMapConverter() {
130117
using namespace boost::python;
131118
using std::map;
132119
// register the to-python converter
133-
to_python_converter<map<K,V>,map_to_python_dict<K,V> >();
120+
to_python_converter<map<K, V>, map_to_python_dict<K, V>>();
134121
// register the from-python converter
135-
map_from_python_dict<K,V>();
122+
map_from_python_dict<K, V>();
136123
}
137124

138-
} // end of namespace python
125+
} // end of namespace python
139126

140-
} // end of namespace tfel
127+
} // end of namespace tfel
141128

142129
#endif /* LIB_TFEL_PYTHON_MAPCONVERTER_H_ */

0 commit comments

Comments
 (0)