Commit 2560ae4e authored by twanvl's avatar twanvl

Added some REFLECT_ macros, so the reflection code doesn't have to mess with...

Added some REFLECT_ macros, so the reflection code doesn't have to mess with the internals of reflection.
parent 4e21ca7c
......@@ -36,12 +36,12 @@ Field::Field()
Field::~Field() {}
IMPLEMENT_REFLECTION(Field) {
if (!tag.reading()) {
REFLECT_IF_NOT_READING {
String type = typeName();
REFLECT(type);
}
REFLECT(name);
if (tag.reading()) name = cannocial_name_form(name);
REFLECT_IF_READING name = cannocial_name_form(name);
REFLECT(description);
REFLECT_N("icon", icon_filename);
REFLECT(editable);
......@@ -53,7 +53,7 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(card_list_visible);
REFLECT(card_list_allow);
REFLECT(card_list_name);
if (tag.reading() && card_list_name.empty()) card_list_name = name;
REFLECT_IF_READING if(card_list_name.empty()) card_list_name = name;
REFLECT_N("card_list_alignment", card_list_align);
REFLECT(tab_index);
}
......
......@@ -38,7 +38,7 @@ IMPLEMENT_REFLECTION(ChoiceField) {
REFLECT_N("default", default_script);
REFLECT(initial);
REFLECT(default_name);
if (tag.reading()) {
REFLECT_IF_READING {
choices->initIds();
}
}
......@@ -220,7 +220,7 @@ IMPLEMENT_REFLECTION_ENUM(ChoiceRenderStyle) {
}
IMPLEMENT_REFLECTION(ChoiceStyle) {
tag.addAlias(300, _("card list colors"), _("colors card list"));
REFLECT_ALIAS(300, "card list colors", "colors card list");
REFLECT_BASE(Style);
REFLECT(popup_style);
REFLECT(render_style);
......@@ -230,7 +230,6 @@ IMPLEMENT_REFLECTION(ChoiceStyle) {
REFLECT(colors_card_list);
REFLECT(font);
REFLECT(choice_images);
// if (tag.reading() && choice_colors.empty())
REFLECT(choice_colors);
}
......
......@@ -128,11 +128,11 @@ void Set::validate(Version file_app_version) {
}
IMPLEMENT_REFLECTION(Set) {
tag.addAlias(300, _("style"), _("stylesheet")); // < 0.3.0 used style instead of stylesheet
tag.addAlias(300, _("extra set info"), _("styling"));
REFLECT_ALIAS(300, "style", "stylesheet"); // < 0.3.0 used style instead of stylesheet
REFLECT_ALIAS(300, "extra set info", "styling");
REFLECT(game);
if (game) {
if (tag.reading()) {
REFLECT_IF_READING {
data.init(game->set_fields);
}
WITH_DYNAMIC_ARG(game_for_reading, game.get());
......
......@@ -150,8 +150,8 @@ String Settings::settingsFile() {
}
IMPLEMENT_REFLECTION(Settings) {
tag.addAlias(300, _("style settings"), _("stylesheet settings"));
tag.addAlias(300, _("default style settings"), _("default stylesheet settings"));
REFLECT_ALIAS(300, "style settings", "stylesheet settings");
REFLECT_ALIAS(300, "default style settings", "default stylesheet settings");
REFLECT(locale);
REFLECT(recent_sets);
REFLECT(set_window_maximized);
......
......@@ -51,14 +51,14 @@ StyleP StyleSheet::styleFor(const FieldP& field) {
IMPLEMENT_REFLECTION(StyleSheet) {
// < 0.3.0 didn't use card_ prefix
tag.addAlias(300, _("width"), _("card width"));
tag.addAlias(300, _("height"), _("card height"));
tag.addAlias(300, _("dpi"), _("card dpi"));
tag.addAlias(300, _("background"), _("card background"));
tag.addAlias(300, _("info style"), _("set info style"));
tag.addAlias(300, _("align"), _("alignment"));
tag.addAlias(300, _("extra field"),_("styling field"));
tag.addAlias(300, _("extra style"),_("styling style"));
REFLECT_ALIAS(300, "width", "card width");
REFLECT_ALIAS(300, "height", "card height");
REFLECT_ALIAS(300, "dpi", "card dpi");
REFLECT_ALIAS(300, "background", "card background");
REFLECT_ALIAS(300, "info style", "set info style");
REFLECT_ALIAS(300, "align", "alignment");
REFLECT_ALIAS(300, "extra field", "styling field");
REFLECT_ALIAS(300, "extra style", "styling style");
REFLECT(game);
REFLECT_BASE(Packaged);
......@@ -68,7 +68,7 @@ IMPLEMENT_REFLECTION(StyleSheet) {
REFLECT(card_dpi);
REFLECT(card_background);
if (game) {
if (tag.reading()) {
REFLECT_IF_READING {
card_style .init(game->card_fields);
set_info_style.init(game->set_fields);
}
......@@ -76,7 +76,7 @@ IMPLEMENT_REFLECTION(StyleSheet) {
REFLECT(set_info_style);
}
REFLECT(styling_fields);
if (tag.reading()) styling_style.init(styling_fields);
REFLECT_IF_READING styling_style.init(styling_fields);
REFLECT(styling_style);
}
......
......@@ -108,7 +108,7 @@ IMPLEMENT_REFLECTION(SymbolPart) {
REFLECT(combine);
REFLECT(points);
// Fixes after reading
if (tag.reading()) {
REFLECT_IF_READING {
// enforce constraints
enforceConstraints();
calculateBounds();
......
......@@ -48,7 +48,7 @@ SymbolFontP SymbolFont::byName(const String& name) {
}
IMPLEMENT_REFLECTION(SymbolFont) {
tag.addAlias(300, _("text align"), _("text alignment"));
REFLECT_ALIAS(300, "text align", "text alignment");
REFLECT_N("image font size", img_size);
REFLECT_N("scale down to", min_size);
......
......@@ -54,7 +54,7 @@ Image render_symbol(const SymbolP& symbol, const SymbolFilter& filter, double bo
// ----------------------------------------------------------------------------- : SymbolFilter
IMPLEMENT_REFLECTION(SymbolFilter) {
if (!tag.reading()) {
REFLECT_IF_NOT_READING {
String fill_type = fillType();
REFLECT(fill_type);
}
......
......@@ -27,7 +27,7 @@ String IncludePackage::typeName() const { return _("include"); }
IMPLEMENT_REFLECTION(IncludePackage) {
REFLECT_BASE(Packaged);
if (tag.reading()) {
REFLECT_IF_READING {
// ingore
String version;
REFLECT(version);
......
......@@ -101,6 +101,34 @@
/// Declare that the variables of a base class should also be reflected
#define REFLECT_BASE(Base) Base::reflect_impl(tag)
/// Reflect a group of declarations only when reading
/** Usage:
* @code
* REFLECT_IF_READING {
* // only executed by Reader
* }
* @endcode
*/
#define REFLECT_IF_READING if (tag.reading())
/// Reflect a group of declarations only when *not* reading
/** Usage:
* @code
* REFLECT_IF_NOT_READING {
* // only executed by Writer, GetMember, GetDefaultMember
* }
* @endcode
*/
#define REFLECT_IF_NOT_READING if (!tag.reading())
/// Add an alias for backwards compatability
/** If a key 'old' is encountered in the input file, it is interpreted as 'new' for versions < version
* Example:
* @code
* REFLECT_ALIAS(300, "style", "stylesheet") // prior to 0.3.0 style was used instead of stylesheet
* @encode
*/
#define REFLECT_ALIAS(version, old, new) tag.addAlias(version, _(old), _(new))
// ----------------------------------------------------------------------------- : Reflecting enums
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment