Skip to content

Commit 4a725eb

Browse files
committed
Make code formatting more consistent
1 parent 1e09ba2 commit 4a725eb

File tree

1 file changed

+85
-70
lines changed

1 file changed

+85
-70
lines changed

matplotlibcpp.h

Lines changed: 85 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -127,29 +127,29 @@ namespace matplotlibcpp {
127127
};
128128
}
129129

130-
bool annotate(std::string annotation, double x, double y)
131-
{
132-
PyObject * xy = PyTuple_New(2);
133-
PyObject * str = PyString_FromString(annotation.c_str());
134-
135-
PyTuple_SetItem(xy,0,PyFloat_FromDouble(x));
136-
PyTuple_SetItem(xy,1,PyFloat_FromDouble(y));
137-
138-
PyObject* kwargs = PyDict_New();
139-
PyDict_SetItemString(kwargs, "xy", xy);
140-
130+
bool annotate(std::string annotation, double x, double y)
131+
{
132+
PyObject * xy = PyTuple_New(2);
133+
PyObject * str = PyString_FromString(annotation.c_str());
134+
135+
PyTuple_SetItem(xy,0,PyFloat_FromDouble(x));
136+
PyTuple_SetItem(xy,1,PyFloat_FromDouble(y));
137+
138+
PyObject* kwargs = PyDict_New();
139+
PyDict_SetItemString(kwargs, "xy", xy);
140+
141141
PyObject* args = PyTuple_New(1);
142142
PyTuple_SetItem(args, 0, str);
143143

144-
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_annotate, args, kwargs);
144+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_annotate, args, kwargs);
145145

146146
Py_DECREF(args);
147147
Py_DECREF(kwargs);
148148

149149
if(res) Py_DECREF(res);
150150

151151
return res;
152-
}
152+
}
153153

154154
template<typename Numeric>
155155
bool plot(const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords)
@@ -187,14 +187,14 @@ namespace matplotlibcpp {
187187
}
188188

189189
template< typename Numeric>
190-
bool hist(const std::vector<Numeric>& y, long bins=10,std::string color="b", double alpha=1.0){
191-
190+
bool hist(const std::vector<Numeric>& y, long bins=10,std::string color="b", double alpha=1.0)
191+
{
192192
PyObject* ylist = PyList_New(y.size());
193193

194194
PyObject* kwargs = PyDict_New();
195195
PyDict_SetItemString(kwargs, "bins", PyLong_FromLong(bins));
196-
PyDict_SetItemString(kwargs, "color", PyString_FromString(color.c_str()));
197-
PyDict_SetItemString(kwargs, "alpha", PyFloat_FromDouble(alpha));
196+
PyDict_SetItemString(kwargs, "color", PyString_FromString(color.c_str()));
197+
PyDict_SetItemString(kwargs, "alpha", PyFloat_FromDouble(alpha));
198198

199199
for(size_t i = 0; i < y.size(); ++i) {
200200
PyList_SetItem(ylist, i, PyFloat_FromDouble(y.at(i)));
@@ -214,9 +214,10 @@ namespace matplotlibcpp {
214214

215215
return res;
216216
}
217-
template< typename Numeric>
218-
bool named_hist(std::string label,const std::vector<Numeric>& y, long bins=10,std::string color="b", double alpha=1.0){
219217

218+
template< typename Numeric>
219+
bool named_hist(std::string label,const std::vector<Numeric>& y, long bins=10, std::string color="b", double alpha=1.0)
220+
{
220221
PyObject* ylist = PyList_New(y.size());
221222
PyObject* kwargs = PyDict_New();
222223
PyDict_SetItemString(kwargs, "label", PyString_FromString(label.c_str()));
@@ -233,7 +234,6 @@ namespace matplotlibcpp {
233234

234235
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_hist, plot_args, kwargs);
235236

236-
237237
Py_DECREF(plot_args);
238238
Py_DECREF(kwargs);
239239
if(res) Py_DECREF(res);
@@ -269,7 +269,8 @@ namespace matplotlibcpp {
269269
}
270270

271271
template<typename NumericX, typename NumericY>
272-
bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::string &s = "") {
272+
bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::string &s = "")
273+
{
273274
assert(x.size() == y.size());
274275

275276
PyObject *kwargs = PyDict_New();
@@ -307,7 +308,8 @@ namespace matplotlibcpp {
307308
}
308309

309310
template<typename Numeric>
310-
bool named_plot(const std::string& name, const std::vector<Numeric>& y, const std::string& format = "") {
311+
bool named_plot(const std::string& name, const std::vector<Numeric>& y, const std::string& format = "")
312+
{
311313
PyObject* kwargs = PyDict_New();
312314
PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str()));
313315

@@ -333,7 +335,8 @@ namespace matplotlibcpp {
333335
}
334336

335337
template<typename Numeric>
336-
bool named_plot(const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = "") {
338+
bool named_plot(const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = "")
339+
{
337340
PyObject* kwargs = PyDict_New();
338341
PyDict_SetItemString(kwargs, "label", PyString_FromString(name.c_str()));
339342

@@ -368,14 +371,16 @@ namespace matplotlibcpp {
368371
return plot(x,y,format);
369372
}
370373

371-
inline void figure(){
374+
inline void figure()
375+
{
372376
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, detail::_interpreter::get().s_python_empty_tuple);
373377
if(!res) throw std::runtime_error("Call to figure() failed.");
374378

375379
Py_DECREF(res);
376-
377-
}
378-
inline void legend() {
380+
}
381+
382+
inline void legend()
383+
{
379384
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_legend, detail::_interpreter::get().s_python_empty_tuple);
380385
if(!res) throw std::runtime_error("Call to legend() failed.");
381386

@@ -417,50 +422,55 @@ namespace matplotlibcpp {
417422
}
418423

419424

420-
double * xlim()
421-
{
422-
PyObject* args = PyTuple_New(0);
425+
inline double* xlim()
426+
{
427+
PyObject* args = PyTuple_New(0);
423428
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_xlim, args);
424-
PyObject * left = PyTuple_GetItem(res,0);
425-
PyObject * right = PyTuple_GetItem(res,1);
426-
double * arr = new double[2];
427-
arr[0] = PyFloat_AsDouble(left);
428-
arr[1] = PyFloat_AsDouble(right);
429+
PyObject* left = PyTuple_GetItem(res,0);
430+
PyObject* right = PyTuple_GetItem(res,1);
431+
432+
double* arr = new double[2];
433+
arr[0] = PyFloat_AsDouble(left);
434+
arr[1] = PyFloat_AsDouble(right);
429435

430-
if(!res) throw std::runtime_error("Call to xlim() failed.");
431-
Py_DECREF(res);
432-
return arr;
433-
}
436+
if(!res) throw std::runtime_error("Call to xlim() failed.");
437+
438+
Py_DECREF(res);
439+
return arr;
440+
}
434441

435442

436-
double * ylim()
437-
{
438-
PyObject* args = PyTuple_New(0);
443+
inline double* ylim()
444+
{
445+
PyObject* args = PyTuple_New(0);
439446
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_ylim, args);
440-
PyObject * left = PyTuple_GetItem(res,0);
441-
PyObject * right = PyTuple_GetItem(res,1);
442-
double * arr = new double[2];
443-
arr[0] = PyFloat_AsDouble(left);
444-
arr[1] = PyFloat_AsDouble(right);
447+
PyObject* left = PyTuple_GetItem(res,0);
448+
PyObject* right = PyTuple_GetItem(res,1);
449+
450+
double* arr = new double[2];
451+
arr[0] = PyFloat_AsDouble(left);
452+
arr[1] = PyFloat_AsDouble(right);
445453

446454
if(!res) throw std::runtime_error("Call to ylim() failed.");
447-
Py_DECREF(res);
448-
return arr;
449-
}
450455

451-
inline void subplot(long nrows, long ncols, long plot_number) {
452-
// construct positional args
453-
PyObject* args = PyTuple_New(3);
454-
PyTuple_SetItem(args, 0, PyFloat_FromDouble(nrows));
455-
PyTuple_SetItem(args, 1, PyFloat_FromDouble(ncols));
456-
PyTuple_SetItem(args, 2, PyFloat_FromDouble(plot_number));
456+
Py_DECREF(res);
457+
return arr;
458+
}
459+
460+
inline void subplot(long nrows, long ncols, long plot_number)
461+
{
462+
// construct positional args
463+
PyObject* args = PyTuple_New(3);
464+
PyTuple_SetItem(args, 0, PyFloat_FromDouble(nrows));
465+
PyTuple_SetItem(args, 1, PyFloat_FromDouble(ncols));
466+
PyTuple_SetItem(args, 2, PyFloat_FromDouble(plot_number));
457467

458-
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_subplot, args);
459-
if(!res) throw std::runtime_error("Call to subplot() failed.");
468+
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_subplot, args);
469+
if(!res) throw std::runtime_error("Call to subplot() failed.");
460470

461-
Py_DECREF(args);
462-
Py_DECREF(res);
463-
}
471+
Py_DECREF(args);
472+
Py_DECREF(res);
473+
}
464474

465475
inline void title(const std::string &titlestr)
466476
{
@@ -474,7 +484,7 @@ namespace matplotlibcpp {
474484
// if PyDeCRFF, the function doesn't work on Mac OS
475485
}
476486

477-
inline void axis(const std::string &axisstr)
487+
inline void axis(const std::string &axisstr)
478488
{
479489
PyObject* str = PyString_FromString(axisstr.c_str());
480490
PyObject* args = PyTuple_New(1);
@@ -486,7 +496,7 @@ namespace matplotlibcpp {
486496
// if PyDeCRFF, the function doesn't work on Mac OS
487497
}
488498

489-
inline void xlabel(const std::string &str)
499+
inline void xlabel(const std::string &str)
490500
{
491501
PyObject* pystr = PyString_FromString(str.c_str());
492502
PyObject* args = PyTuple_New(1);
@@ -498,7 +508,7 @@ namespace matplotlibcpp {
498508
// if PyDeCRFF, the function doesn't work on Mac OS
499509
}
500510

501-
inline void ylabel(const std::string &str)
511+
inline void ylabel(const std::string &str)
502512
{
503513
PyObject* pystr = PyString_FromString(str.c_str());
504514
PyObject* args = PyTuple_New(1);
@@ -510,7 +520,7 @@ namespace matplotlibcpp {
510520
// if PyDeCRFF, the function doesn't work on Mac OS
511521
}
512522

513-
inline void grid(bool flag)
523+
inline void grid(bool flag)
514524
{
515525
PyObject* pyflag = flag ? Py_True : Py_False;
516526

@@ -525,8 +535,11 @@ namespace matplotlibcpp {
525535

526536
inline void show()
527537
{
528-
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_show, detail::_interpreter::get().s_python_empty_tuple);
529-
if(!res) throw std::runtime_error("Call to show() failed.");
538+
PyObject* res = PyObject_CallObject(
539+
detail::_interpreter::get().s_python_function_show,
540+
detail::_interpreter::get().s_python_empty_tuple);
541+
542+
if (!res) throw std::runtime_error("Call to show() failed.");
530543

531544
Py_DECREF(res);
532545
}
@@ -539,15 +552,17 @@ namespace matplotlibcpp {
539552
PyTuple_SetItem(args, 0, pyfilename);
540553

541554
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_save, args);
542-
if(!res) throw std::runtime_error("Call to save() failed.");
555+
if (!res) throw std::runtime_error("Call to save() failed.");
543556

544557
Py_DECREF(args);
545558
Py_DECREF(res);
546559
}
547560

548561
inline void clf() {
549-
PyObject *res = PyObject_CallObject(detail::_interpreter::get().s_python_function_clf,
550-
detail::_interpreter::get().s_python_empty_tuple);
562+
PyObject *res = PyObject_CallObject(
563+
detail::_interpreter::get().s_python_function_clf,
564+
detail::_interpreter::get().s_python_empty_tuple);
565+
551566
if (!res) throw std::runtime_error("Call to clf() failed.");
552567

553568
Py_DECREF(res);

0 commit comments

Comments
 (0)