Code cleanup: remove messy spaces before line continuation (\) in macros

This commit is contained in:
Twan van Laarhoven
2020-04-26 00:37:13 +02:00
parent 5d4c3402df
commit 5e92d9455c
19 changed files with 263 additions and 265 deletions
+12 -12
View File
@@ -258,10 +258,10 @@ inline String type_name(const Value&) {
// ----------------------------------------------------------------------------- : Utilities
#define DECLARE_FIELD_TYPE(Type) \
DECLARE_REFLECTION(); public: \
virtual ValueP newValue(const FieldP& thisP) const; \
virtual StyleP newStyle(const FieldP& thisP) const; \
#define DECLARE_FIELD_TYPE(Type) \
DECLARE_REFLECTION(); public: \
virtual ValueP newValue(const FieldP& thisP) const; \
virtual StyleP newStyle(const FieldP& thisP) const; \
virtual String typeName() const
// implement newStyle and newValue
@@ -291,17 +291,17 @@ inline String type_name(const Value&) {
virtual ValueViewerP makeViewer(DataViewer& parent, const StyleP& thisP); \
virtual ValueViewerP makeEditor(DataEditor& parent, const StyleP& thisP)
#define DECLARE_VALUE_TYPE(Type,ValueType_) \
DECLARE_REFLECTION(); public: \
DECLARE_HAS_FIELD(Type) \
virtual ValueP clone() const; \
virtual String toString() const; \
#define DECLARE_VALUE_TYPE(Type,ValueType_) \
DECLARE_REFLECTION(); public: \
DECLARE_HAS_FIELD(Type) \
virtual ValueP clone() const; \
virtual String toString() const; \
typedef ValueType_ ValueType
// implement field() which returns a field with the right (derived) type
#define DECLARE_HAS_FIELD(Type) \
inline Type ## Field& field() const { \
return *static_cast<Type ## Field*>(fieldP.get()); \
#define DECLARE_HAS_FIELD(Type) \
inline Type ## Field& field() const { \
return *static_cast<Type ## Field*>(fieldP.get()); \
}
void mark_dependency_member(const IndexMap<FieldP,ValueP>& value, const String& name, const Dependency& dep);
+24 -24
View File
@@ -50,40 +50,40 @@ template <ImageCombine combine> struct Combine {
};
// Give a combining function for enum value 'combine'
#define COMBINE_FUN(combine,fun) \
#define COMBINE_FUN(combine,fun) \
template <> int Combine<combine>::f(int a, int b) { return fun; }
// Based on
// http://www.pegtop.net/delphi/articles/blendmodes/
COMBINE_FUN(COMBINE_NORMAL, b )
COMBINE_FUN(COMBINE_ADD, top(a + b) )
COMBINE_FUN(COMBINE_SUBTRACT, bot(a - b) )
COMBINE_FUN(COMBINE_STAMP, col(a - 2 * b + 256) )
COMBINE_FUN(COMBINE_DIFFERENCE, abs(a - b) )
COMBINE_FUN(COMBINE_NEGATION, 255 - abs(255 - a - b) )
COMBINE_FUN(COMBINE_MULTIPLY, (a * b) / 255 )
COMBINE_FUN(COMBINE_DARKEN, min(a, b) )
COMBINE_FUN(COMBINE_LIGHTEN, max(a, b) )
COMBINE_FUN(COMBINE_COLOR_DODGE,b == 255 ? 255 : top(a * 255 / (255 - b)) )
COMBINE_FUN(COMBINE_COLOR_BURN, b == 0 ? 0 : bot(255 - (255-a) * 255 / b) )
COMBINE_FUN(COMBINE_SCREEN, 255 - (((255 - a) * (255 - b)) / 255) )
COMBINE_FUN(COMBINE_NORMAL, b)
COMBINE_FUN(COMBINE_ADD, top(a + b))
COMBINE_FUN(COMBINE_SUBTRACT, bot(a - b))
COMBINE_FUN(COMBINE_STAMP, col(a - 2 * b + 256))
COMBINE_FUN(COMBINE_DIFFERENCE, abs(a - b))
COMBINE_FUN(COMBINE_NEGATION, 255 - abs(255 - a - b))
COMBINE_FUN(COMBINE_MULTIPLY, (a * b) / 255)
COMBINE_FUN(COMBINE_DARKEN, min(a, b))
COMBINE_FUN(COMBINE_LIGHTEN, max(a, b))
COMBINE_FUN(COMBINE_COLOR_DODGE, b == 255 ? 255 : top(a * 255 / (255 - b)))
COMBINE_FUN(COMBINE_COLOR_BURN, b == 0 ? 0 : bot(255 - (255-a) * 255 / b))
COMBINE_FUN(COMBINE_SCREEN, 255 - (((255 - a) * (255 - b)) / 255))
COMBINE_FUN(COMBINE_OVERLAY, a < 128
? (a * b) >> 7
: 255 - (((255 - a) * (255 - b)) >> 7) )
: 255 - (((255 - a) * (255 - b)) >> 7))
COMBINE_FUN(COMBINE_HARD_LIGHT, b < 128
? (a * b) >> 7
: 255 - (((255 - a) * (255 - b)) >> 7) )
: 255 - (((255 - a) * (255 - b)) >> 7))
COMBINE_FUN(COMBINE_SOFT_LIGHT, b)
COMBINE_FUN(COMBINE_REFLECT, b == 255 ? 255 : top(a * a / (255 - b)) )
COMBINE_FUN(COMBINE_GLOW, a == 255 ? 255 : top(b * b / (255 - a)) )
COMBINE_FUN(COMBINE_FREEZE, b == 0 ? 0 : bot(255 - (255 - a) * (255 - a) / b) )
COMBINE_FUN(COMBINE_HEAT, a == 0 ? 0 : bot(255 - (255 - b) * (255 - b) / a) )
COMBINE_FUN(COMBINE_AND, a & b )
COMBINE_FUN(COMBINE_OR, a | b )
COMBINE_FUN(COMBINE_XOR, a ^ b )
COMBINE_FUN(COMBINE_SHADOW, (b * a * a) / (255 * 255) )
COMBINE_FUN(COMBINE_SYMMETRIC_OVERLAY, (Combine<COMBINE_OVERLAY>::f(a,b) + Combine<COMBINE_OVERLAY>::f(b,a)) / 2 )
COMBINE_FUN(COMBINE_REFLECT, b == 255 ? 255 : top(a * a / (255 - b)))
COMBINE_FUN(COMBINE_GLOW, a == 255 ? 255 : top(b * b / (255 - a)))
COMBINE_FUN(COMBINE_FREEZE, b == 0 ? 0 : bot(255 - (255 - a) * (255 - a) / b))
COMBINE_FUN(COMBINE_HEAT, a == 0 ? 0 : bot(255 - (255 - b) * (255 - b) / a))
COMBINE_FUN(COMBINE_AND, a & b)
COMBINE_FUN(COMBINE_OR, a | b)
COMBINE_FUN(COMBINE_XOR, a ^ b)
COMBINE_FUN(COMBINE_SHADOW, (b * a * a) / (255 * 255))
COMBINE_FUN(COMBINE_SYMMETRIC_OVERLAY, (Combine<COMBINE_OVERLAY>::f(a,b) + Combine<COMBINE_OVERLAY>::f(b,a)) / 2 )
// ----------------------------------------------------------------------------- : Combining
+4 -4
View File
@@ -142,11 +142,11 @@ typedef DataEditor CardEditor;
// ----------------------------------------------------------------------------- : Utility
#define FOR_EACH_EDITOR \
FOR_EACH(v, viewers) \
#define FOR_EACH_EDITOR \
FOR_EACH(v, viewers) \
if (ValueEditor* e = v->getEditor())
#define FOR_EACH_EDITOR_REVERSE \
FOR_EACH_REVERSE(v, viewers) \
#define FOR_EACH_EDITOR_REVERSE \
FOR_EACH_REVERSE(v, viewers) \
if (ValueEditor* e = v->getEditor())
// ----------------------------------------------------------------------------- : EOF
+6 -6
View File
@@ -24,15 +24,15 @@ DECLARE_LOCAL_EVENT_TYPE(EVENT_CARD_SELECT, <not used>)
DECLARE_LOCAL_EVENT_TYPE(EVENT_CARD_ACTIVATE, <not used>)
/// Handle EVENT_CARD_SELECT events
#define EVT_CARD_SELECT(id, handler) \
DECLARE_EVENT_TABLE_ENTRY(EVENT_CARD_SELECT, id, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
#define EVT_CARD_SELECT(id, handler) \
DECLARE_EVENT_TABLE_ENTRY(EVENT_CARD_SELECT, id, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
(void (wxEvtHandler::*)(CardSelectEvent&)) (&handler), (wxObject*) NULL),
/// Handle EVENT_CARD_ACTIVATE events
#define EVT_CARD_ACTIVATE(id, handler) \
DECLARE_EVENT_TABLE_ENTRY(EVENT_CARD_ACTIVATE, id, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
#define EVT_CARD_ACTIVATE(id, handler) \
DECLARE_EVENT_TABLE_ENTRY(EVENT_CARD_ACTIVATE, id, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
(void (wxEvtHandler::*)(CardSelectEvent&)) (&handler), (wxObject*) NULL),
/// The event of selecting a card
+3 -3
View File
@@ -21,9 +21,9 @@ typedef intrusive_ptr<Filter<Keyword> > KeywordListFilterP;
DECLARE_LOCAL_EVENT_TYPE(EVENT_KEYWORD_SELECT, <not used>)
/// Handle KeywordSelectEvents
#define EVT_KEYWORD_SELECT(id, handler) \
DECLARE_EVENT_TABLE_ENTRY(EVENT_KEYWORD_SELECT, id, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
#define EVT_KEYWORD_SELECT(id, handler) \
DECLARE_EVENT_TABLE_ENTRY(EVENT_KEYWORD_SELECT, id, -1, \
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
(void (wxEvtHandler::*)(KeywordSelectEvent&)) (&handler), (wxObject*) NULL),
/// The event of selecting a keyword
+5 -5
View File
@@ -390,11 +390,11 @@ bool CardsPanel::wantsToHandle(const Action&, bool undone) const {
// ----------------------------------------------------------------------------- : Clipboard
// determine what control to use for clipboard actions
#define CUT_COPY_PASTE(op,return) \
int id = focused_control(this); \
if (id == ID_EDITOR) { return editor->op(); } \
else if (id == ID_CARD_LIST) { return card_list->op(); } \
else if (id == ID_NOTES) { return notes->op(); } \
#define CUT_COPY_PASTE(op,return) \
int id = focused_control(this); \
if (id == ID_EDITOR) { return editor->op(); } \
else if (id == ID_CARD_LIST) { return card_list->op(); } \
else if (id == ID_NOTES) { return notes->op(); } \
else { return false; }
bool CardsPanel::canCut() const { CUT_COPY_PASTE(canCut, return) }
+3 -3
View File
@@ -533,9 +533,9 @@ END_EVENT_TABLE ()
// ----------------------------------------------------------------------------- : Clipboard
// determine what control to use for clipboard actions
#define CUT_COPY_PASTE(op,return) \
int id = focused_control(this); \
if (id == ID_MESSAGE_LIST) { return messages->op(); } \
#define CUT_COPY_PASTE(op,return) \
int id = focused_control(this); \
if (id == ID_MESSAGE_LIST) { return messages->op(); } \
else { return false; }
bool ConsolePanel::canCut() const { return false; }
+8 -8
View File
@@ -260,15 +260,15 @@ String KeywordsPanel::runRefScript(int find_i) {
// ----------------------------------------------------------------------------- : Clipboard
// determine what control to use for clipboard actions
#define CUT_COPY_PASTE(op,return,check) \
if (!isInitialized()) return false; \
int id = focused_control(this); \
if (id == ID_KEYWORD_LIST && keyword ->IsEnabled()) { return list ->op(); } \
#define CUT_COPY_PASTE(op,return,check) \
if (!isInitialized()) return false; \
int id = focused_control(this); \
if (id == ID_KEYWORD_LIST && keyword ->IsEnabled()) { return list ->op(); } \
else if (check) { return false; } \
else if (id == ID_KEYWORD && keyword ->IsEnabled()) { return keyword ->op(); } \
else if (id == ID_MATCH && match ->IsEnabled()) { return match ->op(); } \
else if (id == ID_REMINDER && reminder->IsEnabled()) { return reminder->op(); } \
else if (id == ID_RULES && rules ->IsEnabled()) { return rules ->op(); } \
else if (id == ID_KEYWORD && keyword ->IsEnabled()) { return keyword ->op(); } \
else if (id == ID_MATCH && match ->IsEnabled()) { return match ->op(); } \
else if (id == ID_REMINDER && reminder->IsEnabled()) { return reminder->op(); } \
else if (id == ID_RULES && rules ->IsEnabled()) { return rules ->op(); } \
else { return false; }
bool KeywordsPanel::canCopy() const { CUT_COPY_PASTE(canCopy, return, false) }
+5 -5
View File
@@ -146,11 +146,11 @@ void StylePanel::selectCard(const CardP& card) {
// ----------------------------------------------------------------------------- : Clipboard
// determine what control to use for clipboard actions
#define CUT_COPY_PASTE(op,return) \
if (!isInitialized()) return false; \
int id = focused_control(this); \
if (id == ID_EDITOR) { return editor->op(); } \
else { return false; }
#define CUT_COPY_PASTE(op,return) \
if (!isInitialized()) return false; \
int id = focused_control(this); \
if (id == ID_EDITOR) { return editor->op(); } \
else { return false; }
bool StylePanel::canCopy() const { CUT_COPY_PASTE(canCopy, return) }
bool StylePanel::canCut() const { CUT_COPY_PASTE(canCut, return) }
+14 -14
View File
@@ -135,22 +135,22 @@ class ValueEditor {
// ----------------------------------------------------------------------------- : Utility
#define DECLARE_VALUE_EDITOR(Type) \
Type##ValueEditor(DataEditor& parent, const Type##StyleP& style); \
virtual ValueEditor* getEditor() { return this; } \
private: \
/** Retrieve the parent editor object */ \
inline DataEditor& editor() const { \
return static_cast<DataEditor&>(viewer); \
} \
#define DECLARE_VALUE_EDITOR(Type) \
Type##ValueEditor(DataEditor& parent, const Type##StyleP& style); \
virtual ValueEditor* getEditor() { return this; } \
private: \
/** Retrieve the parent editor object */ \
inline DataEditor& editor() const { \
return static_cast<DataEditor&>(viewer); \
} \
public:
#define IMPLEMENT_VALUE_EDITOR(Type) \
ValueViewerP Type##Style::makeEditor(DataEditor& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueEditor(parent, static_pointer_cast<Type##Style>(thisP))); \
} \
Type##ValueEditor::Type##ValueEditor(DataEditor& parent, const Type##StyleP& style) \
#define IMPLEMENT_VALUE_EDITOR(Type) \
ValueViewerP Type##Style::makeEditor(DataEditor& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueEditor(parent, static_pointer_cast<Type##Style>(thisP))); \
} \
Type##ValueEditor::Type##ValueEditor(DataEditor& parent, const Type##StyleP& style) \
: Type##ValueViewer(parent, style)
// ----------------------------------------------------------------------------- : EOF
+13 -13
View File
@@ -102,21 +102,21 @@ class ValueViewer : public StyleListener {
// ----------------------------------------------------------------------------- : Utility
#define DECLARE_VALUE_VIEWER(Type) \
protected: \
inline Type##Style& style() const { return static_cast< Type##Style&>(*ValueViewer::styleP); } \
inline const Type##Value& value() const { return static_cast<const Type##Value&>(*ValueViewer::valueP); } \
inline const Type##Field& field() const { return style().field(); } \
inline Type##StyleP styleP() const { return static_pointer_cast<Type##Style>(ValueViewer::styleP); } \
inline Type##ValueP valueP() const { return static_pointer_cast<Type##Value>(ValueViewer::valueP); } \
inline Type##FieldP fieldP() const { return static_pointer_cast<Type##Field>(style().fieldP); } \
public: \
#define DECLARE_VALUE_VIEWER(Type) \
protected: \
inline Type##Style& style() const { return static_cast< Type##Style&>(*ValueViewer::styleP); } \
inline const Type##Value& value() const { return static_cast<const Type##Value&>(*ValueViewer::valueP); } \
inline const Type##Field& field() const { return style().field(); } \
inline Type##StyleP styleP() const { return static_pointer_cast<Type##Style>(ValueViewer::styleP); } \
inline Type##ValueP valueP() const { return static_pointer_cast<Type##Value>(ValueViewer::valueP); } \
inline Type##FieldP fieldP() const { return static_pointer_cast<Type##Field>(style().fieldP); } \
public: \
Type##ValueViewer(DataViewer& parent, const Type ## StyleP& style)
#define IMPLEMENT_VALUE_VIEWER(Type) \
ValueViewerP Type##Style::makeViewer(DataViewer& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueViewer(parent, static_pointer_cast<Type##Style>(thisP))); \
#define IMPLEMENT_VALUE_VIEWER(Type) \
ValueViewerP Type##Style::makeViewer(DataViewer& parent, const StyleP& thisP) { \
assert(thisP.get() == this); \
return ValueViewerP(new Type##ValueViewer(parent, static_pointer_cast<Type##Style>(thisP))); \
}
+16 -16
View File
@@ -424,31 +424,31 @@ class ScriptCompose : public ScriptValue {
// ----------------------------------------------------------------------------- : Simple instructions : binary
// operator on ints
#define OPERATOR_I(OP) \
a = to_script((int)*a OP (int)*b); \
#define OPERATOR_I(OP) \
a = to_script((int)*a OP (int)*b); \
break
// operator on bools
#define OPERATOR_B(OP) \
a = to_script((bool)*a OP (bool)*b); \
#define OPERATOR_B(OP) \
a = to_script((bool)*a OP (bool)*b); \
break
// operator on doubles or ints
#define OPERATOR_DI(OP) \
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = to_script((double)*a OP (double)*b); \
} else { \
a = to_script((int)*a OP (int)*b); \
} \
#define OPERATOR_DI(OP) \
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = to_script((double)*a OP (double)*b); \
} else { \
a = to_script((int)*a OP (int)*b); \
} \
break
// operator on doubles or ints, defined as a function
#define OPERATOR_FUN_DI(OP) \
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = to_script(OP((double)*a, (double)*b)); \
} else { \
a = to_script(OP((int)*a, (int)*b)); \
} \
#define OPERATOR_FUN_DI(OP) \
if (at == SCRIPT_DOUBLE || bt == SCRIPT_DOUBLE) { \
a = to_script(OP((double)*a, (double)*b)); \
} else { \
a = to_script(OP((int)*a, (int)*b)); \
} \
break
+43 -43
View File
@@ -38,30 +38,30 @@
#define SCRIPT_FUNCTION(name) SCRIPT_FUNCTION_AUX(name,;)
/// Macro to declare a new script function with custom dependency handling
#define SCRIPT_FUNCTION_WITH_DEP(name) \
#define SCRIPT_FUNCTION_WITH_DEP(name) \
SCRIPT_FUNCTION_AUX(name, virtual ScriptValueP dependencies(Context&, const Dependency&) const;)
#define SCRIPT_FUNCTION_DEPENDENCIES(name) \
#define SCRIPT_FUNCTION_DEPENDENCIES(name) \
ScriptValueP ScriptBuiltIn_##name::dependencies(Context& ctx, const Dependency& dep) const
/// Macro to declare a new script function with custom closure simplification
#define SCRIPT_FUNCTION_WITH_SIMPLIFY(name) \
#define SCRIPT_FUNCTION_WITH_SIMPLIFY(name) \
SCRIPT_FUNCTION_AUX(name, virtual ScriptValueP simplifyClosure(ScriptClosure&) const;)
#define SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(name) \
#define SCRIPT_FUNCTION_SIMPLIFY_CLOSURE(name) \
ScriptValueP ScriptBuiltIn_##name::simplifyClosure(ScriptClosure& closure) const
// helper for SCRIPT_FUNCTION and SCRIPT_FUNCTION_DEP
#define SCRIPT_FUNCTION_AUX(name,dep) \
class ScriptBuiltIn_##name : public ScriptValue { \
dep \
virtual ScriptType type() const \
{ return SCRIPT_FUNCTION; } \
virtual String typeName() const \
{ return _("built-in function '") _(#name) _("'"); } \
virtual ScriptValueP do_eval(Context&, bool) const; \
}; \
ScriptValueP script_##name(new ScriptBuiltIn_##name); \
#define SCRIPT_FUNCTION_AUX(name,dep) \
class ScriptBuiltIn_##name : public ScriptValue { \
dep \
virtual ScriptType type() const \
{ return SCRIPT_FUNCTION; } \
virtual String typeName() const \
{ return _("built-in function '") _(#name) _("'"); } \
virtual ScriptValueP do_eval(Context&, bool) const; \
}; \
ScriptValueP script_##name(new ScriptBuiltIn_##name); \
ScriptValueP ScriptBuiltIn_##name::do_eval(Context& ctx, bool) const
/// Return a value from a SCRIPT_FUNCTION
@@ -96,13 +96,13 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
* @endcode
* Throws an error if the parameter is not found.
*/
#define SCRIPT_PARAM(Type, name) \
#define SCRIPT_PARAM(Type, name) \
SCRIPT_PARAM_N(Type, _(#name), name)
#define SCRIPT_PARAM_N(Type, str, name) \
#define SCRIPT_PARAM_N(Type, str, name) \
Type name = from_script<Type>(ctx.getVariable(str), str)
/// Faster variant of SCRIPT_PARAM when name is a CommonScriptVariable
/** Doesn't require a runtime lookup of the name */
#define SCRIPT_PARAM_C(Type, name) \
#define SCRIPT_PARAM_C(Type, name) \
SCRIPT_PARAM_N(Type, SCRIPT_VAR_ ## name, name)
/// Retrieve an optional parameter
@@ -116,42 +116,42 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
* }
* @endcode
*/
#define SCRIPT_OPTIONAL_PARAM(Type, name) \
#define SCRIPT_OPTIONAL_PARAM(Type, name) \
SCRIPT_OPTIONAL_PARAM_N(Type, _(#name), name)
/// Retrieve a named optional parameter
#define SCRIPT_OPTIONAL_PARAM_N(Type, str, name) \
SCRIPT_OPTIONAL_PARAM_N_(Type, str, name) \
#define SCRIPT_OPTIONAL_PARAM_N(Type, str, name) \
SCRIPT_OPTIONAL_PARAM_N_(Type, str, name) \
if (name##_)
#define SCRIPT_OPTIONAL_PARAM_C(Type, name) \
#define SCRIPT_OPTIONAL_PARAM_C(Type, name) \
SCRIPT_OPTIONAL_PARAM_N(Type, SCRIPT_VAR_ ## name, name)
/// Retrieve an optional parameter, can't be used as an if statement
#define SCRIPT_OPTIONAL_PARAM_(Type, name) \
#define SCRIPT_OPTIONAL_PARAM_(Type, name) \
SCRIPT_OPTIONAL_PARAM_N_(Type, _(#name), name)
/// Retrieve a named optional parameter, can't be used as an if statement
#define SCRIPT_OPTIONAL_PARAM_N_(Type, str, name) \
ScriptValueP name##_ = ctx.getVariableOpt(str); \
Type name = name##_ && name##_ != script_nil \
#define SCRIPT_OPTIONAL_PARAM_N_(Type, str, name) \
ScriptValueP name##_ = ctx.getVariableOpt(str); \
Type name = name##_ && name##_ != script_nil \
? from_script<Type>(name##_, str) : Type();
#define SCRIPT_OPTIONAL_PARAM_C_(Type, name) \
#define SCRIPT_OPTIONAL_PARAM_C_(Type, name) \
SCRIPT_OPTIONAL_PARAM_N_(Type, SCRIPT_VAR_ ## name, name)
/// Retrieve an optional parameter with a default value
#define SCRIPT_PARAM_DEFAULT(Type, name, def) \
#define SCRIPT_PARAM_DEFAULT(Type, name, def) \
SCRIPT_PARAM_DEFAULT_N(Type, _(#name), name, def)
/// Retrieve a named optional parameter with a default value
#define SCRIPT_PARAM_DEFAULT_N(Type, str, name, def) \
ScriptValueP name##_ = ctx.getVariableOpt(str); \
#define SCRIPT_PARAM_DEFAULT_N(Type, str, name, def) \
ScriptValueP name##_ = ctx.getVariableOpt(str); \
Type name = name##_ ? from_script<Type>(name##_, str) : def
#define SCRIPT_PARAM_DEFAULT_C(Type, name, def) \
#define SCRIPT_PARAM_DEFAULT_C(Type, name, def) \
SCRIPT_PARAM_DEFAULT_N(Type, SCRIPT_VAR_ ## name, name, def)
// ----------------------------------------------------------------------------- : Rules
/// Utility for defining a script rule with a single parameter
#define SCRIPT_RULE_1(funname, type1, name1) \
#define SCRIPT_RULE_1(funname, type1, name1) \
SCRIPT_RULE_1_N(funname, type1, _(#name1), name1)
#define SCRIPT_RULE_1_C(funname, type1, name1) \
#define SCRIPT_RULE_1_C(funname, type1, name1) \
SCRIPT_RULE_1_N(funname, type1, SCRIPT_VAR_ ## name1, name1)
/// Utility for defining a script rule with a single named parameter
#define SCRIPT_RULE_1_N(funname, type1, str1, name1) \
@@ -176,21 +176,21 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
ScriptValueP ScriptRule_##funname::do_eval(Context& ctx, bool) const
/// Utility for defining a script rule with two parameters
#define SCRIPT_RULE_2(funname, type1, name1, type2, name2) \
#define SCRIPT_RULE_2(funname, type1, name1, type2, name2) \
SCRIPT_RULE_2_N(funname, type1, _(#name1), name1, type2, _(#name2), name2)
#define SCRIPT_RULE_2_C(funname, type1, name1, type2, name2) \
#define SCRIPT_RULE_2_C(funname, type1, name1, type2, name2) \
SCRIPT_RULE_2_N(funname, type1, SCRIPT_VAR_ ## name1, name1, type2, SCRIPT_VAR_ ## name2, name2)
/// Utility for defining a script rule with two named parameters
#define SCRIPT_RULE_2_N(funname, type1, str1, name1, type2, str2, name2) \
#define SCRIPT_RULE_2_N(funname, type1, str1, name1, type2, str2, name2) \
SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, ;, ;)
/// Utility for defining a script rule with two named parameters, with dependencies
#define SCRIPT_RULE_2_N_DEP(funname, type1, str1, name1, type2, str2, name2) \
SCRIPT_RULE_2_N_AUX( funname, type1, str1, name1, type2, str2, name2, \
virtual ScriptValueP dependencies(Context&, const Dependency&) const;, \
SCRIPT_FUNCTION_DEPENDENCIES(funname) { \
SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \
return ScriptRule_##funname(name1, name2).dependencies(ctx, dep); \
#define SCRIPT_RULE_2_N_DEP(funname, type1, str1, name1, type2, str2, name2) \
SCRIPT_RULE_2_N_AUX( funname, type1, str1, name1, type2, str2, name2, \
virtual ScriptValueP dependencies(Context&, const Dependency&) const; \
SCRIPT_FUNCTION_DEPENDENCIES(funname) { \
SCRIPT_PARAM_N(type1, str1, name1); \
SCRIPT_PARAM_N(type2, str2, name2); \
return ScriptRule_##funname(name1, name2).dependencies(ctx, dep); \
})
#define SCRIPT_RULE_2_N_AUX(funname, type1, str1, name1, type2, str2, name2, dep, more) \
@@ -220,7 +220,7 @@ inline Type from_script(const ScriptValueP& v, Variable var) {
more \
ScriptValueP ScriptRule_##funname::do_eval(Context& ctx, bool) const
#define SCRIPT_RULE_2_DEPENDENCIES(name) \
#define SCRIPT_RULE_2_DEPENDENCIES(name) \
ScriptValueP ScriptRule_##name::dependencies(Context& ctx, const Dependency& dep) const
+7 -7
View File
@@ -123,7 +123,7 @@ class ActionStack {
/// Tests if variable has the type Type.
/** Uses dynamic cast, so Type must have a virtual function.
*/
#define TYPE_CASE_(variable, Type) \
#define TYPE_CASE_(variable, Type) \
if (dynamic_cast<const Type*>(&variable))
/// Tests if variable has the type Type.
@@ -131,12 +131,12 @@ class ActionStack {
*
* Uses dynamic cast, so Type must have a virtual function.
*/
#define TYPE_CASE(variable, Type) \
pair<const Type*,bool> Type##variable \
(dynamic_cast<const Type*>(&variable), true); \
if (Type##variable.first) \
for (const Type& variable = *Type##variable.first ; \
Type##variable.second ; \
#define TYPE_CASE(variable, Type) \
pair<const Type*,bool> Type##variable \
(dynamic_cast<const Type*>(&variable), true); \
if (Type##variable.first) \
for (const Type& variable = *Type##variable.first ; \
Type##variable.second ; \
Type##variable.second = false)
+19 -19
View File
@@ -37,24 +37,24 @@
* To change the value use WITH_DYNAMIC_ARG(name, newValue)
* To be used in a header file. Use IMPLEMENT_DYN_ARG in a source file
*/
#define DECLARE_DYNAMIC_ARG(Type, name) \
extern THREAD_LOCAL Type name##_private; \
inline Type name() { return name##_private; } \
class name##_changer { \
public: \
inline name##_changer(Type const& newValue) \
: oldValue(name##_private) { \
name##_private = newValue; \
} \
inline ~name##_changer() { \
name##_private = oldValue; \
} \
private: \
Type oldValue; \
#define DECLARE_DYNAMIC_ARG(Type, name) \
extern THREAD_LOCAL Type name##_private; \
inline Type name() { return name##_private; } \
class name##_changer { \
public: \
inline name##_changer(Type const& newValue) \
: oldValue(name##_private) { \
name##_private = newValue; \
} \
inline ~name##_changer() { \
name##_private = oldValue; \
} \
private: \
Type oldValue; \
}
/// Implementation of a dynamic argument
#define IMPLEMENT_DYNAMIC_ARG(Type, name, initial) \
#define IMPLEMENT_DYNAMIC_ARG(Type, name, initial) \
THREAD_LOCAL Type name##_private = initial;
/// Locally change the value of a dynamic argument
@@ -68,7 +68,7 @@
* // here name() == old value
* @endcode
*/
#define WITH_DYNAMIC_ARG(name, value) \
#define WITH_DYNAMIC_ARG(name, value) \
name##_changer name##_dummmy(value)
#else
@@ -107,13 +107,13 @@
}
};
#define DECLARE_DYNAMIC_ARG(Type, name) \
#define DECLARE_DYNAMIC_ARG(Type, name) \
extern ThreadLocalObject<Type> name;
#define IMPLEMENT_DYNAMIC_ARG(Type, name, initial) \
#define IMPLEMENT_DYNAMIC_ARG(Type, name, initial) \
ThreadLocalObject<Type> name (initial);
#define WITH_DYNAMIC_ARG(name, value) \
#define WITH_DYNAMIC_ARG(name, value) \
name.store(value);
#endif
+43 -45
View File
@@ -45,33 +45,33 @@
/// Iterate over a collection, using an iterator it of type Type
/** Usage: FOR_EACH_IT_T(Type,it,collect) { body-of-loop }
*/
#define FOR_EACH_IT_T(Type,Iterator,Collection) \
for(Type Iterator = (Collection).begin() ; \
Iterator != (Collection).end() ; \
++Iterator)
#define FOR_EACH_IT_T(Type,Iterator,Collection) \
for(Type Iterator = (Collection).begin() ; \
Iterator != (Collection).end() ; \
++Iterator)
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
/** Usage: FOR_EACH_IT(it,collect) { body-of-loop }
*/
#define FOR_EACH_IT(Iterator,Collection) \
FOR_EACH_IT_T(TYPEOF_IT(Collection), Iterator, Collection)
#define FOR_EACH_IT(Iterator,Collection) \
FOR_EACH_IT_T(TYPEOF_IT(Collection), Iterator, Collection)
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
/** Uses a const_iterator
* Usage: FOR_EACH_IT(it,collect) { body-of-loop }
*/
#define FOR_EACH_CONST_IT(Iterator,Collection) \
FOR_EACH_IT_T(TYPEOF_CIT(Collection), Iterator, Collection)
#define FOR_EACH_CONST_IT(Iterator,Collection) \
FOR_EACH_IT_T(TYPEOF_CIT(Collection), Iterator, Collection)
/// Iterate over a collection in whos type must be declared with DECLARE_TYPEOF
/** Iterates using a reverse_iterator
* Usage: FOR_EACH_REVERSE_IT(it,collect) { body-of-loop }
*/
#define FOR_EACH_REVERSE_IT(Iterator,Collection) \
for(TYPEOF_RIT(Collection) \
Iterator = (Collection).rbegin() ; \
Iterator != (Collection).rend() ; \
++Iterator)
#define FOR_EACH_REVERSE_IT(Iterator,Collection) \
for(TYPEOF_RIT(Collection) \
Iterator = (Collection).rbegin() ; \
Iterator != (Collection).rend() ; \
++Iterator)
// ----------------------------------------------------------------------------- : Looping macros
@@ -82,13 +82,13 @@
* To do this we use a nested for loop that is only executed once, and which is optimized away.
* To terminate this loop we need an extra bool, which we set to false after the first iteration.
*/
#define FOR_EACH_T(TypeIt,TypeElem,Elem,Collection, begin, end) \
for(std::pair<TypeIt,bool> Elem##_IT((Collection).begin(), true) ; \
Elem##_IT.second && Elem##_IT.first != (Collection).end() ; \
++Elem##_IT.first, Elem##_IT.second = !Elem##_IT.second) \
for(TypeElem Elem = *Elem##_IT.first ; \
Elem##_IT.second ; \
Elem##_IT.second = false)
#define FOR_EACH_T(TypeIt,TypeElem,Elem,Collection, begin, end) \
for(std::pair<TypeIt,bool> Elem##_IT((Collection).begin(), true) ; \
Elem##_IT.second && Elem##_IT.first != (Collection).end() ; \
++Elem##_IT.first, Elem##_IT.second = !Elem##_IT.second) \
for(TypeElem Elem = *Elem##_IT.first ; \
Elem##_IT.second ; \
Elem##_IT.second = false)
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
/** Usage: FOR_EACH(e,collect) { body-of-loop }
@@ -102,8 +102,6 @@
/** Uses a const iterator
* Usage: FOR_EACH_CONST(e,collect) { body-of-loop }
*/
//#define FOR_EACH_CONST(Elem,Collection) \
// FOR_EACH_T(TYPEOF_CIT(Collection), TYPEOF_CREF(Collection), Elem, Collection, begin, end)
#define FOR_EACH_CONST(Elem,Collection) \
for (auto const& Elem : Collection)
@@ -111,15 +109,15 @@
/** Iterates using a reverse_iterator
* Usage: FOR_EACH_REVERSE(e,collect) { body-of-loop }
*/
#define FOR_EACH_REVERSE(Elem,Collection) \
FOR_EACH_T(TYPEOF_RIT(Collection), TYPEOF_REF(Collection), Elem, Collection, rbegin, rend)
#define FOR_EACH_REVERSE(Elem,Collection) \
FOR_EACH_T(TYPEOF_RIT(Collection), TYPEOF_REF(Collection), Elem, Collection, rbegin, rend)
/// Iterate over a collection whos type must be declared with DECLARE_TYPEOF
/** Iterates using a const_reverse_iterator
* Usage: FOR_EACH_CONST_REVERSE(e,collect) { body-of-loop }
*/
#define FOR_EACH_CONST_REVERSE(Elem,Collection) \
FOR_EACH_T(TYPEOF_CRIT(Collection), TYPEOF_CREF(Collection), Elem, Collection, rbegin, rend)
#define FOR_EACH_CONST_REVERSE(Elem,Collection) \
FOR_EACH_T(TYPEOF_CRIT(Collection), TYPEOF_CREF(Collection), Elem, Collection, rbegin, rend)
/// Iterate over two collection in parallel
/** Usage: FOR_EACH_2_T(TypeIt1,TypeElem1,e1,collect1,TypeIt2,TypeElem2,e2,collect2) { body-of-loop }
@@ -127,33 +125,33 @@
* Note: This has got to be one of the craziest pieces of code I have ever written :)
* It is just an extension of the idea of FOR_EACH_T.
*/
#define FOR_EACH_2_T(TypeIt1,TypeElem1,Elem1,Coll1,TypeIt2,TypeElem2,Elem2,Coll2) \
for(std::pair<std::pair<TypeIt1,TypeIt2>, bool> \
Elem1##_IT(make_pair((Coll1).begin(), (Coll2).begin()), true) ; \
Elem1##_IT.first.first != (Coll1).end() && \
Elem1##_IT.first.second != (Coll2).end() ; \
++Elem1##_IT.first.first, ++Elem1##_IT.first.second, \
Elem1##_IT.second = true) \
for(TypeElem1 Elem1 = *Elem1##_IT.first.first ; \
Elem1##_IT.second ; \
Elem1##_IT.second = false) \
for(TypeElem2 Elem2 = *Elem1##_IT.first.second ; \
Elem1##_IT.second ; \
Elem1##_IT.second = false)
#define FOR_EACH_2_T(TypeIt1,TypeElem1,Elem1,Coll1,TypeIt2,TypeElem2,Elem2,Coll2) \
for(std::pair<std::pair<TypeIt1,TypeIt2>, bool> \
Elem1##_IT(make_pair((Coll1).begin(), (Coll2).begin()), true) ; \
Elem1##_IT.first.first != (Coll1).end() && \
Elem1##_IT.first.second != (Coll2).end() ; \
++Elem1##_IT.first.first, ++Elem1##_IT.first.second, \
Elem1##_IT.second = true) \
for(TypeElem1 Elem1 = *Elem1##_IT.first.first ; \
Elem1##_IT.second ; \
Elem1##_IT.second = false) \
for(TypeElem2 Elem2 = *Elem1##_IT.first.second ; \
Elem1##_IT.second ; \
Elem1##_IT.second = false)
/// Iterate over two collections in parallel, their type must be declared with DECLARE_TYPEOF.
/** Usage: FOR_EACH_2(e1,collect1, e2,collect2) { body-of-loop }
*/
#define FOR_EACH_2(Elem1,Collection1, Elem2,Collection2) \
FOR_EACH_2_T(TYPEOF_IT(Collection1), TYPEOF_REF(Collection1), Elem1, Collection1, \
TYPEOF_IT(Collection2), TYPEOF_REF(Collection2), Elem2, Collection2)
#define FOR_EACH_2(Elem1,Collection1, Elem2,Collection2) \
FOR_EACH_2_T(TYPEOF_IT(Collection1), TYPEOF_REF(Collection1), Elem1, Collection1, \
TYPEOF_IT(Collection2), TYPEOF_REF(Collection2), Elem2, Collection2)
/// Iterate over two constants collections in parallel, their type must be declared with DECLARE_TYPEOF.
/** Usage: FOR_EACH_2_CONST(e1,collect1, e2,collect2) { body-of-loop }
*/
#define FOR_EACH_2_CONST(Elem1,Collection1, Elem2,Collection2) \
FOR_EACH_2_T(TYPEOF_CIT(Collection1), TYPEOF_CREF(Collection1), Elem1, Collection1, \
TYPEOF_CIT(Collection2), TYPEOF_CREF(Collection2), Elem2, Collection2)
#define FOR_EACH_2_CONST(Elem1,Collection1, Elem2,Collection2) \
FOR_EACH_2_T(TYPEOF_CIT(Collection1), TYPEOF_CREF(Collection1), Elem1, Collection1, \
TYPEOF_CIT(Collection2), TYPEOF_CREF(Collection2), Elem2, Collection2)
// ----------------------------------------------------------------------------- : EOF
+12 -12
View File
@@ -121,25 +121,25 @@ class GetMember : private GetDefaultMember {
#define REFLECT_OBJECT_GET_DEFAULT_MEMBER_NOT(Cls) REFLECT_WRITE_NO(Cls,GetDefaultMember)
#define REFLECT_OBJECT_GET_MEMBER_NOT(Cls) REFLECT_WRITE_NO(Cls,GetMember)
#define REFLECT_WRITE_YES(Cls, Tag) \
template<> void Tag::handle<Cls>(const Cls& object) { \
const_cast<Cls&>(object).reflect(*this); \
} \
void Cls::reflect(Tag& tag) { \
reflect_impl(tag); \
#define REFLECT_WRITE_YES(Cls, Tag) \
template<> void Tag::handle<Cls>(const Cls& object) { \
const_cast<Cls&>(object).reflect(*this); \
} \
void Cls::reflect(Tag& tag) { \
reflect_impl(tag); \
}
#define REFLECT_WRITE_NO(Cls, Tag) \
template<> void Tag::handle<Cls>(const Cls& object) {} \
#define REFLECT_WRITE_NO(Cls, Tag) \
template<> void Tag::handle<Cls>(const Cls& object) {} \
void Cls::reflect(Tag& tag) {}
// ----------------------------------------------------------------------------- : Reflection for enumerations
/// Implement enum reflection as used by GetMember
#define REFLECT_ENUM_GET_MEMBER(Enum) \
template<> void GetDefaultMember::handle<Enum>(const Enum& enum_) { \
EnumGetMember egm(*this); \
reflect_ ## Enum(const_cast<Enum&>(enum_), egm); \
#define REFLECT_ENUM_GET_MEMBER(Enum) \
template<> void GetDefaultMember::handle<Enum>(const Enum& enum_) { \
EnumGetMember egm(*this); \
reflect_ ## Enum(const_cast<Enum&>(enum_), egm); \
}
/// 'Tag' to be used when reflecting enumerations for GetMember
+16 -16
View File
@@ -244,27 +244,27 @@ void Reader::handle(IndexMap<K,V>& m) {
// ----------------------------------------------------------------------------- : Reflection
/// Implement reflection as used by Reader
#define REFLECT_OBJECT_READER(Cls) \
template<> void Reader::handle<Cls>(Cls& object) { \
object.reflect(*this); \
} \
void Cls::reflect(Reader& reader) { \
reflect_impl(reader); \
#define REFLECT_OBJECT_READER(Cls) \
template<> void Reader::handle<Cls>(Cls& object) { \
object.reflect(*this); \
} \
void Cls::reflect(Reader& reader) { \
reflect_impl(reader); \
}
// ----------------------------------------------------------------------------- : Reflection for enumerations
/// Implement enum reflection as used by Reader
#define REFLECT_ENUM_READER(Enum) \
template<> void Reader::handle<Enum>(Enum& enum_) { \
EnumReader reader(getValue()); \
reflect_ ## Enum(enum_, reader); \
reader.warnIfNotDone(this); \
} \
void parse_enum(const String& value, Enum& out) { \
EnumReader reader(value); \
reflect_ ## Enum(out, reader); \
reader.errorIfNotDone(); \
#define REFLECT_ENUM_READER(Enum) \
template<> void Reader::handle<Enum>(Enum& enum_) { \
EnumReader reader(getValue()); \
reflect_ ## Enum(enum_, reader); \
reader.warnIfNotDone(this); \
} \
void parse_enum(const String& value, Enum& out) { \
EnumReader reader(value); \
reflect_ ## Enum(out, reader); \
reader.errorIfNotDone(); \
}
/// 'Tag' to be used when reflecting enumerations for Reader
+10 -10
View File
@@ -129,21 +129,21 @@ void Writer::handle(const IndexMap<K,V>& m) {
// ----------------------------------------------------------------------------- : Reflection
/// Implement reflection as used by Writer
#define REFLECT_OBJECT_WRITER(Cls) \
template<> void Writer::handle<Cls>(const Cls& object) { \
const_cast<Cls&>(object).reflect(*this); \
} \
void Cls::reflect(Writer& writer) { \
reflect_impl(writer); \
#define REFLECT_OBJECT_WRITER(Cls) \
template<> void Writer::handle<Cls>(const Cls& object) { \
const_cast<Cls&>(object).reflect(*this); \
} \
void Cls::reflect(Writer& writer) { \
reflect_impl(writer); \
}
// ----------------------------------------------------------------------------- : Reflection for enumerations
/// Implement enum reflection as used by Writer
#define REFLECT_ENUM_WRITER(Enum) \
template<> void Writer::handle<Enum>(const Enum& enum_) { \
EnumWriter writer(*this); \
reflect_ ## Enum(const_cast<Enum&>(enum_), writer); \
#define REFLECT_ENUM_WRITER(Enum) \
template<> void Writer::handle<Enum>(const Enum& enum_) { \
EnumWriter writer(*this); \
reflect_ ## Enum(const_cast<Enum&>(enum_), writer); \
}
/// 'Tag' to be used when reflecting enumerations for Writer