Browse Source

Shorthand for __VA_ARGS__

pull/1/head
Scott Lahteine 5 years ago
parent
commit
dc65788511
  1. 48
      Marlin/src/core/macros.h
  2. 2
      Marlin/src/core/utility.h
  3. 4
      Marlin/src/inc/Conditionals_post.h
  4. 24
      Marlin/src/lcd/menu/menu.h

48
Marlin/src/core/macros.h

@ -295,8 +295,8 @@ typedef float feedRate_t;
#endif
// Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
#define _NUM_ARGS(_0,_24_,_23,_22,_21,_20,_19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,N,...) N
#define NUM_ARGS(V...) _NUM_ARGS(0,V,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
#define NUM_ARGS(V...) _NUM_ARGS(0,V,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
#ifdef __cplusplus
@ -322,29 +322,29 @@ typedef float feedRate_t;
#else
#define MIN_2(a,b) ((a)<(b)?(a):(b))
#define MIN_3(a,...) MIN_2(a,MIN_2(__VA_ARGS__))
#define MIN_4(a,...) MIN_2(a,MIN_3(__VA_ARGS__))
#define MIN_5(a,...) MIN_2(a,MIN_4(__VA_ARGS__))
#define MIN_6(a,...) MIN_2(a,MIN_5(__VA_ARGS__))
#define MIN_7(a,...) MIN_2(a,MIN_6(__VA_ARGS__))
#define MIN_8(a,...) MIN_2(a,MIN_7(__VA_ARGS__))
#define MIN_9(a,...) MIN_2(a,MIN_8(__VA_ARGS__))
#define MIN_10(a,...) MIN_2(a,MIN_9(__VA_ARGS__))
#define __MIN_N(N, ...) MIN_##N(__VA_ARGS__)
#define _MIN_N(N, ...) __MIN_N(N,__VA_ARGS__)
#define _MIN(...) _MIN_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
#define MIN_3(a,V...) MIN_2(a,MIN_2(V))
#define MIN_4(a,V...) MIN_2(a,MIN_3(V))
#define MIN_5(a,V...) MIN_2(a,MIN_4(V))
#define MIN_6(a,V...) MIN_2(a,MIN_5(V))
#define MIN_7(a,V...) MIN_2(a,MIN_6(V))
#define MIN_8(a,V...) MIN_2(a,MIN_7(V))
#define MIN_9(a,V...) MIN_2(a,MIN_8(V))
#define MIN_10(a,V...) MIN_2(a,MIN_9(V))
#define __MIN_N(N,V...) MIN_##N(V)
#define _MIN_N(N,V...) __MIN_N(N,V)
#define _MIN(V...) _MIN_N(NUM_ARGS(V), V)
#define MAX_2(a,b) ((a)>(b)?(a):(b))
#define MAX_3(a,...) MAX_2(a,MAX_2(__VA_ARGS__))
#define MAX_4(a,...) MAX_2(a,MAX_3(__VA_ARGS__))
#define MAX_5(a,...) MAX_2(a,MAX_4(__VA_ARGS__))
#define MAX_6(a,...) MAX_2(a,MAX_5(__VA_ARGS__))
#define MAX_7(a,...) MAX_2(a,MAX_6(__VA_ARGS__))
#define MAX_8(a,...) MAX_2(a,MAX_7(__VA_ARGS__))
#define MAX_9(a,...) MAX_2(a,MAX_8(__VA_ARGS__))
#define MAX_10(a,...) MAX_2(a,MAX_9(__VA_ARGS__))
#define __MAX_N(N, ...) MAX_##N(__VA_ARGS__)
#define _MAX_N(N, ...) __MAX_N(N,__VA_ARGS__)
#define _MAX(...) _MAX_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
#define MAX_3(a,V...) MAX_2(a,MAX_2(V))
#define MAX_4(a,V...) MAX_2(a,MAX_3(V))
#define MAX_5(a,V...) MAX_2(a,MAX_4(V))
#define MAX_6(a,V...) MAX_2(a,MAX_5(V))
#define MAX_7(a,V...) MAX_2(a,MAX_6(V))
#define MAX_8(a,V...) MAX_2(a,MAX_7(V))
#define MAX_9(a,V...) MAX_2(a,MAX_8(V))
#define MAX_10(a,V...) MAX_2(a,MAX_9(V))
#define __MAX_N(N,V...) MAX_##N(V)
#define _MAX_N(N,V...) __MAX_N(N,V)
#define _MAX(V...) _MAX_N(NUM_ARGS(V), V)
#endif

2
Marlin/src/core/utility.h

@ -59,7 +59,7 @@ public:
inline void restore() { ref_ = val_; }
};
#define REMEMBER(N,X, ...) const restorer<typeof(X)> restorer_##N(X, ##__VA_ARGS__)
#define REMEMBER(N,X,V...) const restorer<typeof(X)> restorer_##N(X, ##V)
#define RESTORE(N) restorer_##N.restore()
// Converts from an uint8_t in the range of 0-255 to an uint8_t

4
Marlin/src/inc/Conditionals_post.h

@ -534,13 +534,13 @@
/**
* ARRAY_BY_EXTRUDERS based on EXTRUDERS
*/
#define ARRAY_BY_EXTRUDERS(...) ARRAY_N(EXTRUDERS, __VA_ARGS__)
#define ARRAY_BY_EXTRUDERS(V...) ARRAY_N(EXTRUDERS, V)
#define ARRAY_BY_EXTRUDERS1(v1) ARRAY_BY_EXTRUDERS(v1, v1, v1, v1, v1, v1)
/**
* ARRAY_BY_HOTENDS based on HOTENDS
*/
#define ARRAY_BY_HOTENDS(...) ARRAY_N(HOTENDS, __VA_ARGS__)
#define ARRAY_BY_HOTENDS(V...) ARRAY_N(HOTENDS, V)
#define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1, v1, v1)
/**

24
Marlin/src/lcd/menu/menu.h

@ -306,30 +306,30 @@ class MenuItem_bool {
* MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
*
*/
#define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, ...) do { \
#define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, V...) do { \
_skipStatic = false; \
if (_menuLineNr == _thisItemNr) { \
if (encoderLine == _thisItemNr && ui.use_click()) { \
_MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
MenuItem_##TYPE ::action ## VARIANT(__VA_ARGS__); \
MenuItem_##TYPE ::action ## VARIANT(V); \
if (screen_changed) return; \
} \
if (ui.should_draw()) \
draw_menu_item ## VARIANT ## _ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ## __VA_ARGS__); \
draw_menu_item ## VARIANT ## _ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ##V); \
} \
++_thisItemNr; \
}while(0)
// Used to print static text with no visible cursor.
// Parameters: label [, bool center [, bool invert [, char *value] ] ]
#define STATIC_ITEM_P(PLABEL, ...) do{ \
#define STATIC_ITEM_P(PLABEL, V...) do{ \
if (_menuLineNr == _thisItemNr) { \
if (_skipStatic && encoderLine <= _thisItemNr) { \
ui.encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
++encoderLine; \
} \
if (ui.should_draw()) \
draw_menu_item_static(_lcdLineNr, PLABEL, ## __VA_ARGS__); \
draw_menu_item_static(_lcdLineNr, PLABEL, ##V); \
} \
++_thisItemNr; \
} while(0)
@ -340,16 +340,16 @@ class MenuItem_bool {
#define MENU_ITEM_ADDON_END() } }while(0)
#define STATIC_ITEM(LABEL, ...) STATIC_ITEM_P(PSTR(LABEL), ## __VA_ARGS__)
#define STATIC_ITEM(LABEL, V...) STATIC_ITEM_P(PSTR(LABEL), ##V)
#define MENU_BACK(LABEL) MENU_ITEM(back, LABEL)
#define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
#define MENU_ITEM_P(TYPE, PLABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PLABEL, ## __VA_ARGS__)
#define MENU_ITEM(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, , false, PSTR(LABEL), ## __VA_ARGS__)
#define MENU_ITEM_EDIT(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
#define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
#define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
#define MENU_ITEM_P(TYPE, PLABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, , false, PLABEL, ##V)
#define MENU_ITEM(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, , false, PSTR(LABEL), ##V)
#define MENU_ITEM_EDIT(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ##V)
#define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ##V)
#define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), PSTR(LABEL), ##V)
#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit, true, PSTR(LABEL), PSTR(LABEL), ##V)
////////////////////////////////////////////
/////////////// Menu Screens ///////////////

Loading…
Cancel
Save