8000 Cleanup · kreturn/matplotlib-cpp@088af33 · GitHub
[go: up one dir, main page]

Skip to content

Commit 088af33

Browse files
committed
Cleanup
Fix typos, whitespace, and reorder functions
1 parent 27ce78e commit 088af33

File tree

1 file changed

+21
-34
lines changed

1 file changed

+21
-34
lines changed

matplotlibcpp.h

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace matplotlibcpp {
3232

3333
/* For now, _interpreter is implemented as a singleton since its currently not possible to have
3434
multiple independent embedded python interpreters without patching the python source code
35-
or starting a seperate process for each.
36-
35+
or starting a separate process for each.
36+
3737
http://bytes.com/topic/python/answers/793370-multiple-independent-python-interpreters-c-c-program
3838
*/
3939

@@ -44,12 +44,12 @@ namespace matplotlibcpp {
4444

4545
private:
4646
_interpreter() {
47-
char name[] = "plotting"; // silence compiler warning abount const strings
47+
char name[] = "plotting"; // silence compiler warning about const strings
4848
Py_SetProgramName(name); // optional but recommended
4949
Py_Initialize();
5050

5151
PyObject* pyplotname = PyString_FromString("matplotlib.pyplot");
52-
PyObject* pylabname = PyString_FromString("pylab");
52+
PyObject* pylabname = PyString_FromString("pylab");
5353
if(!pyplotname || !pylabname) { throw std::runtime_error("couldnt create string"); }
5454

5555
PyObject* pymod = PyImport_Import(pyplotname);
@@ -71,36 +71,35 @@ namespace matplotlibcpp {
7171
s_python_function_ylabel = PyObject_GetAttrString(pymod, "ylabel");
7272
s_python_function_grid = PyObject_GetAttrString(pymod, "grid");
7373
s_python_function_xlim = PyObject_GetAttrString(pymod, "xlim");
74-
7574
s_python_function_save = PyObject_GetAttrString(pylabmod, "savefig");
7675

77-
if(!s_python_function_show
78-
|| !s_python_function_save
79-
|| !s_python_function_figure
80-
|| !s_python_function_plot
81-
|| !s_python_function_legend
82-
|| !s_python_function_xlim
76+
if( !s_python_function_show
77+
|| !s_python_function_figure
78+
|| !s_python_function_plot
79+
|| !s_python_function_legend
8380
|| !s_python_function_ylim
8481
|| !s_python_function_title
8582
|| !s_python_function_axis
8683
|| !s_python_function_xlabel
8784
|| !s_python_function_ylabel
8885
|| !s_python_function_grid
89-
)
90-
{ throw std::runtime_error("Couldnt find required function!"); }
86+
|| !s_python_function_xlim
87+
|| !s_python_function_save
88+
)
89+
{ throw std::runtime_error("Couldn't find required function!"); }
9190

92-
if(!PyFunction_Check(s_python_function_show)
93-
|| !PyFunction_Check(s_python_function_save)
91+
if( !PyFunction_Check(s_python_function_show)
9492
|| !PyFunction_Check(s_python_function_figure)
9593
|| !PyFunction_Check(s_python_function_plot)
96-
|| !PyFunction_Check(s_python_function_legend)
97-
|| !PyFunction_Check(s_python_function_xlim)
98-
|| !PyFunction_Check(s_python_function_ylim)
94+
|| !PyFunction_Check(s_python_function_legend)
95+
|| !PyFunction_Check(s_python_function_ylim)
9996
|| !PyFunction_Check(s_python_function_title)
10097
|| !PyFunction_Check(s_python_function_axis)
10198
|| !PyFunction_Check(s_python_function_xlabel)
10299
|| !PyFunction_Check(s_python_function_ylabel)
103100
|| !PyFunction_Check(s_python_function_grid)
101+
|| !PyFunction_Check(s_python_function_xlim)
102+
|| !PyFunction_Check(s_python_function_save)
104103
)
105104
{ throw std::runtime_error("Python object is unexpectedly not a PyFunction."); }
106105

@@ -113,8 +112,6 @@ namespace matplotlibcpp {
113112
};
114113
}
115114

116-
117-
118115
template<typename Numeric>
119116
bool plot(const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords)
120117
{
@@ -153,7 +150,6 @@ namespace matplotlibcpp {
153150
return res;
154151
}
155152

156-
157153
template<typename NumericX, typename NumericY>
158154
bool plot(const std::vector<NumericX>& x, const std::vector<NumericY>& y, const std::string& s = "")
159155
{
@@ -183,7 +179,6 @@ namespace matplotlibcpp {
183179
return res;
184180
}
185181

186-
187182
template<typename Numeric>
188183
bool named_plot(const std::string& name, const std::vector<Numeric>& x, const std::vector<Numeric>& y, const std::string& format = "") {
189184
PyObject* kwargs = PyDict_New();
@@ -223,7 +218,7 @@ namespace matplotlibcpp {
223218
}
224219

225220

226-
inline void legend() {
221+
inline void legend() {
227222
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_legend, detail::_interpreter::get().s_python_empty_tuple);
228223
if(!res) throw std::runtime_error("Call to legend() failed.");
229224

@@ -266,7 +261,6 @@ namespace matplotlibcpp {
266261
Py_DECREF(res);
267262
}
268263

269-
270264
inline void title(const std::string &titlestr)
271265
{
272266
PyObject* pytitlestr = PyString_FromString(titlestr.c_str());
@@ -291,8 +285,6 @@ namespace matplotlibcpp {
291285
// if PyDeCRFF, the function doesn't work on Mac OS
292286
}
293287

294-
295-
296288
inline void xlabel(const std::string &str)
297289
{
298290
PyObject* pystr = PyString_FromString(str.c_str());
@@ -330,8 +322,6 @@ namespace matplotlibcpp {
330322
// if PyDeCRFF, the function doesn't work on Mac OS
331323
}
332324

333-
334-
335325
inline void show()
336326
{
337327
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_show, detail::_interpreter::get().s_python_empty_tuple);
@@ -368,7 +358,7 @@ namespace matplotlibcpp {
368358
template<typename T>
369359
struct is_callable_impl<false, T>
370360
{
371-
typedef is_function<T> type;
361+
typedef is_function<T> type;
372362
}; // a non-object is callable iff it is a function
373363

374364
template<typename T>
@@ -452,10 +442,10 @@ namespace matplotlibcpp {
452442

453443
if(begin(ticks) == end(ticks)) return true;
454444

455-
// We could use additional meta-programming to deduce the correct element type of y,
445+
// We could use additional meta-programming to deduce the correct element type of y,
456446
// but all values have to be convertible to double anyways
457447
std::vector<double> y;
458-
for(auto x : ticks) y.push_back(f(x));
448+
for(auto x : ticks) y.push_back(f(x));
459449
return plot_impl<std::false_type>()(ticks,y,format);
460450
}
461451
};
@@ -493,7 +483,4 @@ namespace matplotlibcpp {
493483

494484
#endif
495485

496-
497-
498-
499486
}

0 commit comments

Comments
 (0)
0