Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54ca5f1

Browse files
committed
remove _ prefix for all named arguments. added a define which can be used to place them in a separate namespace if the user doesn't want them in the global namespace.
removed the requirement for constexpr.
1 parent 4f4965a commit 54ca5f1

File tree

2 files changed

+38
-39
lines changed

2 files changed

+38
-39
lines changed

Madplotlib.h

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@
2626

2727
#pragma once
2828

29+
#ifndef PLT_ARG_NAMESPACE
30+
#define PLT_ARG_NAMESPACE
31+
#endif
32+
33+
#ifdef _MSC_VER
34+
#if _MSC_VER >= 1900
35+
#define PLT_CONSTEXPR constexpr
36+
#else
37+
#define PLT_CONSTEXPR
38+
#endif
39+
#else
40+
#define PLT_CONSTEXPR constexpr
41+
#endif
42+
2943
#define MO_KEYWORD_INPUT(name, type) \
3044
namespace tag{ \
3145
struct name { \
@@ -46,7 +60,9 @@ namespace tag{
4660
} \
4761
}; \
4862
} \
49-
static kwargs::TKeyword<tag::name>& _##name = kwargs::TKeyword<tag::name>::instance;
63+
namespace PLT_ARG_NAMESPACE { \
64+
static kwargs::TKeyword<tag::name>& name = kwargs::TKeyword<tag::name>::instance; \
65+
}
5066

5167

5268
#define MO_KEYWORD_OUTPUT(name, type) \
@@ -69,7 +85,9 @@ namespace tag{
6985
} \
7086
}; \
7187
} \
72-
static kwargs::TKeyword<name>& _##name = kwargs::TKeyword<name>::instance;
88+
namespace PLT_ARG_NAMESPACE { \
89+
static kwargs::TKeyword<name>& name = kwargs::TKeyword<name>::instance; \
90+
}
7391

7492
namespace kwargs {
7593
struct TaggedBase {};
@@ -117,17 +135,17 @@ typename Tag::VoidType GetKeyImpl() {
117135
}
118136

119137
template <class T, class U>
120-
constexpr int CountTypeImpl(const U& value) {
138+
PLT_CONSTEXPR int CountTypeImpl(const U& value) {
121139
return std::is_same<T, U>::value ? 1 : 0;
122140
}
123141

124142
template <class T, class U, class... Args>
125-
constexpr int CountTypeImpl(const U& value, const Args&... args) {
143+
PLT_CONSTEXPR int CountTypeImpl(const U& value, const Args&... args) {
126144
return CountTypeImpl<T, Args...>(args...) + (std::is_same<T, U>::value ? 1 : 0);
127145
}
128146

129147
template <class T, class... Args>
130-
constexpr int CountType(const Args&... args) {
148+
PLT_CONSTEXPR int CountType(const Args&... args) {
131149
return CountTypeImpl<T, Args...>(args...);
132150
}
133151

@@ -208,25 +226,6 @@ struct is_matrix_expression : std::false_type {};
208226
template<typename T>
209227
struct is_matrix_expression<T, decltype(std::declval<Eigen::ArrayXf>() = std::declval<T>(), void())> : std::true_type {};
210228

211-
template<class Arg>
212-
constexpr bool detectExpressionArg(const Arg& arg) {
213-
return is_matrix_expression<Arg>::value;
214-
}
215-
template<class Arg, class ... Args>
216-
constexpr bool detectExpressionArg(const Arg& arg, const Args&... args) {
217-
return is_matrix_expression<Arg>::value ? true : detectExpressionArg(args...);
218-
}
219-
220-
template<class Arg> typename std::enable_if<is_matrix_expression<Arg>::value>::type applyExpression(Eigen::ArrayXf& X, const Arg& Y)
221-
{
222-
X = Y;
223-
}
224-
225-
template<class Arg> typename std::enable_if<!is_matrix_expression<Arg>::value>::type applyExpression(Eigen::ArrayXf& X, const Arg& Y)
226-
{
227-
228-
}
229-
230229
/* Debug control */
231230

232231
#define DEBUG 0 // level 0: debug msgs are disabled

eigen_tests.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ void test3()
8484
Madplotlib plt;
8585
plt.title("Test 3: Multiple Data Series");
8686
plt.axis(0, 25, 0, 14);
87-
plt.plot(x, y, _marker=QString("--"), _label=QString("label=Dashed Line"));
88-
plt.plot(x, y+5, _label=QString("label=Default Line"), (quint32)4);
89-
plt.plot(x, y+10, QString("."), _label=QString("label=Dotted Line"));
87+
plt.plot(x, y, marker=QString("--"), label=QString("label=Dashed Line"));
88+
plt.plot(x, y+5, label=QString("label=Default Line"), (quint32)4);
89+
plt.plot(x, y+10, QString("."), label=QString("label=Dotted Line"));
9090
plt.legend(); // default position is "lower center"
9191
plt.show();
9292

@@ -125,8 +125,8 @@ void test4()
125125
plt.title("Test 4: Random Scatter Plot");
126126
plt.locator_params("x", 10);
127127
plt.axis(-25, 100, -25, 100);
128-
plt.plot(x, y, _marker=QString("o"), 0.7f, QColor(255, 0, 0), 8.0f); // red, 30% transparent, markersize 8
129-
plt.plot(x2, y2, _marker=QString("o"), 0.5f, QColor(0, 0, 255)); // blue, 50% transparent
128+
plt.plot(x, y, marker=QString("o"), 0.7f, QColor(255, 0, 0), 8.0f); // red, 30% transparent, markersize 8
129+
plt.plot(x2, y2, marker=QString("o"), 0.5f, QColor(0, 0, 255)); // blue, 50% transparent
130130
plt.show();
131131

132132
#ifdef SCRSHOT
@@ -191,10 +191,10 @@ void test6()
191191
105, 111, 120, 126, 120, 104, 85, 92;
192192

193193
Madplotlib plt;
194-
plt.plot(x, y, _color=QColor(0xFF2700)); // red
195-
plt.plot(x, y, _marker=QString("o"), _color=QColor(0xFF2700));
196-
plt.plot(x, y-40, _color=QColor(0x008FD5)); // blue
197-
plt.plot(x, y-40, _marker=QString("o"), _color=QColor(0x008FD5));
194+
plt.plot(x, y, color=QColor(0xFF2700)); // red
195+
plt.plot(x, y, marker=QString("o"), color=QColor(0xFF2700));
196+
plt.plot(x, y-40, color=QColor(0x008FD5)); // blue
197+
plt.plot(x, y-40, marker=QString("o"), color=QColor(0x008FD5));
198198

199199
plt.title("Test 6: Line + Scatter");
200200
plt.xlabel("X values");
@@ -240,7 +240,7 @@ void test7()
240240
// On Qt 7.5, Qt Charts has a bug spacing correctly categories on negative Y axis (-1, 1).
241241
// For now, drawing (y+1) will bypass that since the values will fall between (0, 2).
242242
plt.ylim(0, 2);
243-
plt.plot(x, y+1, _marker=QString("o"), _alpha=1.f, _linewidth=2, _markersize=7.0f); // alpha=1.f, linewidth=2, markersize=7.f
243+
plt.plot(x, y+1, marker=QString("o"), alpha=1.f, linewidth=2, markersize=7.0f); // alpha=1.f, linewidth=2, markersize=7.f
244244
plt.grid(true);
245245

246246
plt.show();
@@ -265,13 +265,13 @@ void test8()
265265
Madplotlib plt;
266266
plt.title("Test 8: Line + Square Markers + Hidden Ticks");
267267
plt.axis("off");
268-
plt.plot(x, x.sqrt(), _color=QColor(0, 0, 0));
269-
plt.plot(x, -x.sqrt(), _color = QColor(0, 0, 0));
268+
plt.plot(x, x.sqrt(), color=QColor(0, 0, 0));
269+
plt.plot(x, -x.sqrt(), color = QColor(0, 0, 0));
270270

271271
Eigen::ArrayXf noise = Eigen::ArrayXf::Random(50) * 2;
272272

273-
plt.plot(x, x.sqrt() - noise, _marker=QString("s"), _markersize = 0.7f, _color=QColor(19, 154, 255), _edgecolor=QColor(19, 154, 255)); // red squares without black edges
274-
plt.plot(x, -x.sqrt() - noise, _marker = QString("s"), _markersize = 0.7f, _color=QColor(255, 41, 5), _edgecolor=QColor(255, 41, 5)); // blue squares without black edges
273+
plt.plot(x, x.sqrt() - noise, marker=QString("s"), markersize = 0.7f, color=QColor(19, 154, 255), edgecolor=QColor(19, 154, 255)); // red squares without black edges
274+
plt.plot(x, -x.sqrt() - noise, marker = QString("s"), markersize = 0.7f, color=QColor(255, 41, 5), edgecolor=QColor(255, 41, 5)); // blue squares without black edges
275275
plt.show();
276276

277277
#ifdef SCRSHOT
@@ -345,7 +345,7 @@ void test10()
345345
// On Qt 7.5, Qt Charts has a bug spacing correctly categories on negative X axis (-3.1, 3.1).
346346
// For now, make sure you are using only positive X values to bypass that problem.
347347
plt.plot(X, C);
348-
plt.plot(X, S, _marker=QString("--"));
348+
plt.plot(X, S, marker=QString("--"));
349349
plt.xlim(0, 2*pi);
350350
plt.xticks(x_ticks, x_labels);
351351
plt.show();

0 commit comments

Comments
 (0)