format file forcing the left alignment
This commit is contained in:
@@ -40,10 +40,10 @@
|
||||
#ifdef PyString_AsStringAndSize
|
||||
#undef PyString_AsStringAndSize
|
||||
#endif
|
||||
static inline int PyString_AsStringAndSize(PyObject *obj, char **buf,
|
||||
Py_ssize_t *psize) {
|
||||
static inline int PyString_AsStringAndSize(PyObject* obj, char** buf,
|
||||
Py_ssize_t* psize) {
|
||||
if (PyUnicode_Check(obj)) {
|
||||
*buf = const_cast<char *>(PyUnicode_AsUTF8AndSize(obj, psize));
|
||||
*buf = const_cast<char*>(PyUnicode_AsUTF8AndSize(obj, psize));
|
||||
return *buf == NULL ? -1 : 0;
|
||||
} else if (PyBytes_Check(obj)) {
|
||||
return PyBytes_AsStringAndSize(obj, buf, psize);
|
||||
@@ -54,18 +54,18 @@ static inline int PyString_AsStringAndSize(PyObject *obj, char **buf,
|
||||
#endif // Py3.3+
|
||||
|
||||
template <class T>
|
||||
inline bool PyObjAs(PyObject *pystr, T *cstr) {
|
||||
inline bool PyObjAs(PyObject* pystr, T* cstr) {
|
||||
T::undefined; // You need to define specialization PyObjAs<T>
|
||||
}
|
||||
template <class T>
|
||||
inline PyObject *PyObjFrom(const T &c) {
|
||||
inline PyObject* PyObjFrom(const T& c) {
|
||||
T::undefined; // You need to define specialization PyObjFrom<T>
|
||||
}
|
||||
|
||||
#ifdef HAS_GLOBAL_STRING
|
||||
template <>
|
||||
inline bool PyObjAs(PyObject *pystr, ::std::string *cstr) {
|
||||
char *buf;
|
||||
inline bool PyObjAs(PyObject* pystr, ::std::string* cstr) {
|
||||
char* buf;
|
||||
Py_ssize_t len;
|
||||
#if PY_VERSION_HEX >= 0x03030000
|
||||
if (PyUnicode_Check(pystr)) {
|
||||
@@ -80,12 +80,12 @@ inline bool PyObjAs(PyObject *pystr, ::std::string *cstr) {
|
||||
}
|
||||
#endif
|
||||
template <class T>
|
||||
inline bool PyObjAs(PyObject *pystr, std::string *cstr) {
|
||||
char *buf;
|
||||
inline bool PyObjAs(PyObject* pystr, std::string* cstr) {
|
||||
char* buf;
|
||||
Py_ssize_t len;
|
||||
#if PY_VERSION_HEX >= 0x03030000
|
||||
if (PyUnicode_Check(pystr)) {
|
||||
buf = const_cast<char *>(PyUnicode_AsUTF8AndSize(pystr, &len));
|
||||
buf = const_cast<char*>(PyUnicode_AsUTF8AndSize(pystr, &len));
|
||||
if (!buf) return false;
|
||||
} else // NOLINT
|
||||
#endif
|
||||
@@ -96,12 +96,12 @@ inline bool PyObjAs(PyObject *pystr, std::string *cstr) {
|
||||
}
|
||||
#ifdef HAS_GLOBAL_STRING
|
||||
template <>
|
||||
inline PyObject *PyObjFrom(const ::std::string &c) {
|
||||
inline PyObject* PyObjFrom(const ::std::string& c) {
|
||||
return PyString_FromStringAndSize(c.data(), c.size());
|
||||
}
|
||||
#endif
|
||||
template <>
|
||||
inline PyObject *PyObjFrom(const std::string &c) {
|
||||
inline PyObject* PyObjFrom(const std::string& c) {
|
||||
return PyString_FromStringAndSize(c.data(), c.size());
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ inline PyObject *PyObjFrom(const std::string &c) {
|
||||
#include <limits>
|
||||
|
||||
template <>
|
||||
inline bool PyObjAs(PyObject *py, int *c) {
|
||||
inline bool PyObjAs(PyObject* py, int* c) {
|
||||
long i = PyInt_AsLong(py); // NOLINT
|
||||
if (i == -1 && PyErr_Occurred()) // TypeError or OverflowError.
|
||||
return false; // Not a Python int.
|
||||
@@ -122,7 +122,7 @@ inline bool PyObjAs(PyObject *py, int *c) {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool PyObjAs(PyObject *py, unsigned int *c) {
|
||||
inline bool PyObjAs(PyObject* py, unsigned int* c) {
|
||||
long i = PyInt_AsLong(py); // NOLINT
|
||||
if (i == -1 && PyErr_Occurred()) return false; // Not a Python int.
|
||||
if (i < 0 || i > std::numeric_limits<unsigned int>::max()) return false;
|
||||
@@ -131,7 +131,7 @@ inline bool PyObjAs(PyObject *py, unsigned int *c) {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool PyObjAs(PyObject *py, int64 *c) { // NOLINT
|
||||
inline bool PyObjAs(PyObject* py, int64* c) { // NOLINT
|
||||
int64 i; // NOLINT
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (PyInt_Check(py)) {
|
||||
@@ -149,7 +149,7 @@ inline bool PyObjAs(PyObject *py, int64 *c) { // NOLINT
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool PyObjAs(PyObject *py, uint64 *c) { // NOLINT
|
||||
inline bool PyObjAs(PyObject* py, uint64* c) { // NOLINT
|
||||
uint64 i; // NOLINT
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (PyInt_Check(py)) {
|
||||
@@ -167,7 +167,7 @@ inline bool PyObjAs(PyObject *py, uint64 *c) { // NOLINT
|
||||
}
|
||||
|
||||
template <>
|
||||
inline bool PyObjAs(PyObject *py, double *c) {
|
||||
inline bool PyObjAs(PyObject* py, double* c) {
|
||||
double d;
|
||||
if (PyFloat_Check(py)) {
|
||||
d = PyFloat_AsDouble(py);
|
||||
@@ -188,11 +188,11 @@ inline bool PyObjAs(PyObject *py, double *c) {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline PyObject *PyObjFrom(const double &c) {
|
||||
inline PyObject* PyObjFrom(const double& c) {
|
||||
return PyFloat_FromDouble(c);
|
||||
}
|
||||
template <>
|
||||
inline bool PyObjAs(PyObject *py, float *c) {
|
||||
inline bool PyObjAs(PyObject* py, float* c) {
|
||||
double d;
|
||||
if (!PyObjAs(py, &d)) return false;
|
||||
if (c) *c = static_cast<float>(d);
|
||||
@@ -200,17 +200,17 @@ inline bool PyObjAs(PyObject *py, float *c) {
|
||||
}
|
||||
|
||||
template <>
|
||||
inline PyObject *PyObjFrom(const float &c) {
|
||||
inline PyObject* PyObjFrom(const float& c) {
|
||||
return PyFloat_FromDouble(c);
|
||||
}
|
||||
template <>
|
||||
inline bool PyObjAs(PyObject *py, bool *c) {
|
||||
inline bool PyObjAs(PyObject* py, bool* c) {
|
||||
if (!PyBool_Check(py)) return false; // Not a Python bool.
|
||||
if (c) *c = PyObject_Not(py) ? false : true;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline int SwigPyIntOrLong_Check(PyObject *o) {
|
||||
inline int SwigPyIntOrLong_Check(PyObject* o) {
|
||||
return (PyLong_Check(o)
|
||||
#if PY_MAJOR_VERSION <= 2
|
||||
|| PyInt_Check(o)
|
||||
@@ -218,11 +218,11 @@ inline int SwigPyIntOrLong_Check(PyObject *o) {
|
||||
); // NOLINT
|
||||
}
|
||||
|
||||
inline PyObject *SwigString_FromString(const std::string &s) {
|
||||
inline PyObject* SwigString_FromString(const std::string& s) {
|
||||
return PyString_FromStringAndSize(s.data(), s.size());
|
||||
}
|
||||
|
||||
inline std::string SwigString_AsString(PyObject *o) {
|
||||
inline std::string SwigString_AsString(PyObject* o) {
|
||||
return std::string(PyString_AsString(o));
|
||||
}
|
||||
|
||||
@@ -232,21 +232,21 @@ namespace { // NOLINT
|
||||
|
||||
template <typename T>
|
||||
struct vector_pusher {
|
||||
typedef T *ptr;
|
||||
static void push(std::vector<T> *o, ptr e) { o->push_back(*e); }
|
||||
typedef T* ptr;
|
||||
static void push(std::vector<T>* o, ptr e) { o->push_back(*e); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct vector_pusher<T *> {
|
||||
typedef T *ptr;
|
||||
static void push(std::vector<T *> *o, ptr e) { o->push_back(e); }
|
||||
struct vector_pusher<T*> {
|
||||
typedef T* ptr;
|
||||
static void push(std::vector<T*>* o, ptr e) { o->push_back(e); }
|
||||
};
|
||||
|
||||
}; // namespace
|
||||
|
||||
template <class T>
|
||||
inline bool vector_input_helper(PyObject *seq, std::vector<T> *out,
|
||||
bool (*convert)(PyObject *, T *const)) {
|
||||
inline bool vector_input_helper(PyObject* seq, std::vector<T>* out,
|
||||
bool (*convert)(PyObject*, T* const)) {
|
||||
PyObject *item, *it = PyObject_GetIter(seq);
|
||||
if (!it) return false;
|
||||
T elem;
|
||||
@@ -264,8 +264,8 @@ inline bool vector_input_helper(PyObject *seq, std::vector<T> *out,
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline bool vector_input_wrap_helper(PyObject *seq, std::vector<T> *out,
|
||||
swig_type_info *swig_Tp_type) {
|
||||
inline bool vector_input_wrap_helper(PyObject* seq, std::vector<T>* out,
|
||||
swig_type_info* swig_Tp_type) {
|
||||
PyObject *item, *it = PyObject_GetIter(seq);
|
||||
if (!it) {
|
||||
PyErr_SetString(PyExc_TypeError, "sequence expected");
|
||||
@@ -273,12 +273,12 @@ inline bool vector_input_wrap_helper(PyObject *seq, std::vector<T> *out,
|
||||
}
|
||||
typename vector_pusher<T>::ptr elem;
|
||||
while ((item = PyIter_Next(it))) {
|
||||
if (SWIG_ConvertPtr(item, reinterpret_cast<void **>(&elem), swig_Tp_type,
|
||||
if (SWIG_ConvertPtr(item, reinterpret_cast<void**>(&elem), swig_Tp_type,
|
||||
0) == -1) {
|
||||
Py_DECREF(it);
|
||||
it = PyObject_Repr(item);
|
||||
Py_DECREF(item);
|
||||
const char *repr = it ? PyString_AsString(it) : "not";
|
||||
const char* repr = it ? PyString_AsString(it) : "not";
|
||||
PyErr_Format(PyExc_TypeError, "'%s' expected, %s found",
|
||||
SWIG_TypePrettyName(swig_Tp_type), repr);
|
||||
Py_XDECREF(it);
|
||||
@@ -297,13 +297,13 @@ inline bool vector_input_wrap_helper(PyObject *seq, std::vector<T> *out,
|
||||
// The converter function converts a C++ object of type const T or const T&
|
||||
// into the corresponding Python object.
|
||||
template <class T, class Converter>
|
||||
inline PyObject *list_output_helper(const T *vec, Converter converter) {
|
||||
inline PyObject* list_output_helper(const T* vec, Converter converter) {
|
||||
if (vec == NULL) Py_RETURN_NONE; // Return a nice out-of-band value.
|
||||
PyObject *lst = PyList_New(vec->size());
|
||||
PyObject* lst = PyList_New(vec->size());
|
||||
if (lst == NULL) return NULL;
|
||||
int i = 0;
|
||||
for (typename T::const_reference pt : *vec) {
|
||||
PyObject *obj = converter(pt);
|
||||
PyObject* obj = converter(pt);
|
||||
if (!obj) {
|
||||
Py_DECREF(lst);
|
||||
return NULL;
|
||||
@@ -315,37 +315,37 @@ inline PyObject *list_output_helper(const T *vec, Converter converter) {
|
||||
|
||||
template <class T>
|
||||
struct OutConverter {
|
||||
PyObject *operator()(const T x) const {
|
||||
return SWIG_NewPointerObj((void *)x, type_, new_); // NOLINT
|
||||
PyObject* operator()(const T x) const {
|
||||
return SWIG_NewPointerObj((void*)x, type_, new_); // NOLINT
|
||||
}
|
||||
swig_type_info *type_;
|
||||
swig_type_info* type_;
|
||||
int new_;
|
||||
OutConverter(swig_type_info *type, int new_object)
|
||||
OutConverter(swig_type_info* type, int new_object)
|
||||
: type_(type), new_(new_object) {}
|
||||
};
|
||||
|
||||
template <class T, class TR>
|
||||
inline PyObject *vector_output_helper(const std::vector<T> *vec,
|
||||
PyObject *(*converter)(const TR x)) {
|
||||
inline PyObject* vector_output_helper(const std::vector<T>* vec,
|
||||
PyObject* (*converter)(const TR x)) {
|
||||
return list_output_helper(vec, converter);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline PyObject *vector_output_helper(const std::vector<T *> *vec,
|
||||
const OutConverter<T *> &converter) {
|
||||
inline PyObject* vector_output_helper(const std::vector<T*>* vec,
|
||||
const OutConverter<T*>& converter) {
|
||||
return list_output_helper(vec, converter);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline PyObject *vector_output_wrap_helper(const std::vector<T *> *vec,
|
||||
swig_type_info *swig_Tp_type,
|
||||
inline PyObject* vector_output_wrap_helper(const std::vector<T*>* vec,
|
||||
swig_type_info* swig_Tp_type,
|
||||
bool newobj = false) {
|
||||
#if 1
|
||||
OutConverter<T *> converter(swig_Tp_type, newobj);
|
||||
OutConverter<T*> converter(swig_Tp_type, newobj);
|
||||
return vector_output_helper(vec, converter);
|
||||
#else // Lambda version
|
||||
auto converter = [](const T *x) {
|
||||
return SWIG_NewPointerObj((void *)x, swig_Tp_type, newobj); // NOLINT
|
||||
auto converter = [](const T* x) {
|
||||
return SWIG_NewPointerObj((void*)x, swig_Tp_type, newobj); // NOLINT
|
||||
} return list_output_helper(vec, converter);
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user