Cleaned up the reflection code a bit

* Renamed 'tag' variable to 'handler'
* Removed addAlias stuff, instead check for matching names with if statements
* Added after_reading function that is called by Reader after reading a complete object. This generalizes Packaged::validate, which is now also called via this mechanism.
* Removed some backwards compatibility with <0.3.0 for templates
This commit is contained in:
Twan van Laarhoven
2020-04-26 15:33:59 +02:00
parent 4bebd48786
commit 40d78edf0f
32 changed files with 248 additions and 281 deletions
+19 -23
View File
@@ -27,10 +27,10 @@ IMPLEMENT_REFLECTION(ControlPoint) {
REFLECT_N("position", pos);
REFLECT_N("lock", lock);
REFLECT_N("line_after", segment_after);
if (tag.reading() || segment_before == SEGMENT_CURVE) {
if (Handler::isReading || segment_before == SEGMENT_CURVE) {
REFLECT_N("handle_before", delta_before);
}
if (tag.reading() || segment_after == SEGMENT_CURVE) {
if (Handler::isReading || segment_after == SEGMENT_CURVE) {
REFLECT_N("handle_after", delta_after);
}
}
@@ -155,32 +155,28 @@ IMPLEMENT_REFLECTION_ENUM(SymbolShapeCombine) {
VALUE_N("border", SYMBOL_COMBINE_BORDER);
}
template<typename T> void fix(const T&,SymbolShape&) {}
void fix(const Reader& reader, SymbolShape& shape) {
if (reader.file_app_version != Version()) return;
shape.updateBounds();
if (shape.bounds.max.x < 100 || shape.bounds.max.y < 100) return;
// this is a <= 0.1.2 symbol, points range [0...500] instead of [0...1]
// adjust it
FOR_EACH(p, shape.points) {
p->pos /= 500.0;
p->delta_before /= 500.0;
p->delta_after /= 500.0;
}
if (shape.name.empty()) shape.name = _("Shape");
shape.updateBounds();
}
IMPLEMENT_REFLECTION(SymbolShape) {
REFLECT_BASE(SymbolPart);
REFLECT(combine);
REFLECT(points);
}
void after_reading(SymbolShape& shape, Version version) {
// Fixes after reading
REFLECT_IF_READING {
// enforce constraints
enforceConstraints();
fix(tag,*this);
// enforce constraints
shape.enforceConstraints();
if (version == Version()) {
// this is a <= 0.1.2 symbol, points range [0...500] instead of [0...1]
shape.updateBounds();
if (shape.bounds.max.x < 100 || shape.bounds.max.y < 100) return;
// adjust it
FOR_EACH(p, shape.points) {
p->pos /= 500.0;
p->delta_before /= 500.0;
p->delta_after /= 500.0;
}
if (shape.name.empty()) shape.name = _("Shape");
shape.updateBounds();
}
}