diff --git a/src/data/game.cpp b/src/data/game.cpp index 45b02105..41b48acc 100644 --- a/src/data/game.cpp +++ b/src/data/game.cpp @@ -32,8 +32,8 @@ IMPLEMENT_REFLECTION(Game) { REFLECT(card_fields); // REFLECT_N("keyword parameter type", keyword_params); // REFLECT_N("keyword separator type", keyword_separators); -// REFLECT_N("keyword", keywords); -// REFLECT_N("word list", word_lists); +// REFLECT(keywords); +// REFLECT(word_lists); } void Game::validate() { diff --git a/src/data/settings.cpp b/src/data/settings.cpp index c9db0708..27d98542 100644 --- a/src/data/settings.cpp +++ b/src/data/settings.cpp @@ -95,7 +95,7 @@ String Settings::settingsFile() { IMPLEMENT_REFLECTION(Settings) { // ioMseVersion(io, "settings", file_version); - REFLECT_N("recent_set", recent_sets); + REFLECT(recent_sets); REFLECT(set_window_maximized); REFLECT(set_window_width); REFLECT(set_window_height); diff --git a/src/data/symbol.cpp b/src/data/symbol.cpp index 0db387d2..a1c6344d 100644 --- a/src/data/symbol.cpp +++ b/src/data/symbol.cpp @@ -106,7 +106,7 @@ IMPLEMENT_REFLECTION_ENUM(SymbolPartCombine) { IMPLEMENT_REFLECTION(SymbolPart) { REFLECT(name); REFLECT(combine); - REFLECT_N("point", points); + REFLECT(points); // Fixes after reading if (tag.reading()) { // enforce constraints @@ -160,7 +160,7 @@ void SymbolPart::calculateBounds() { IMPLEMENT_REFLECTION(Symbol) { //%% version? - REFLECT_N("part", parts); + REFLECT(parts); } // ----------------------------------------------------------------------------- : SymbolView diff --git a/src/main.cpp b/src/main.cpp index 980c7d5b..4359f444 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -37,8 +37,8 @@ bool MSE::OnInit() { wxInitAllImageHandlers(); initFileFormats(); settings.read(); - //Window* wnd = new SymbolWindow(nullptr); - Window* wnd = new SetWindow(nullptr, new_shared1(Game::byName(_("magic")))); + Window* wnd = new SymbolWindow(nullptr); + //Window* wnd = new SetWindow(nullptr, new_shared1(Game::byName(_("magic")))); wnd->Show(); return true; } diff --git a/src/util/io/reader.hpp b/src/util/io/reader.hpp index 212bd9f8..f4ec7933 100644 --- a/src/util/io/reader.hpp +++ b/src/util/io/reader.hpp @@ -9,7 +9,7 @@ // ----------------------------------------------------------------------------- : Includes -#include "../prec.hpp" +#include #include // ----------------------------------------------------------------------------- : Reader @@ -47,11 +47,12 @@ class Reader { exitBlock(); } } + /// Reads a vector from the input stream + template + void handle(const Char* name, vector& vector); /// Reads an object of type T from the input stream template void handle(T& object); - /// Reads a vector from the input stream - template void handle(vector& vector); /// Reads a shared_ptr from the input stream template void handle(shared_ptr& pointer); /// Reads a map from the input stream @@ -109,12 +110,12 @@ shared_ptr read_new(Reader& reader) { } template -void Reader::handle(vector& vector) { - String vectorKey = key; - while (key == vectorKey) { // TODO : check indent - moveNext(); // skip key +void Reader::handle(const Char* name, vector& vector) { + String vectorKey = singular_form(name); + while (enterBlock(vectorKey)) { vector.resize(vector.size() + 1); handle(vector.back()); + exitBlock(); } } diff --git a/src/util/io/writer.hpp b/src/util/io/writer.hpp index 7e223c11..2b4b3805 100644 --- a/src/util/io/writer.hpp +++ b/src/util/io/writer.hpp @@ -34,6 +34,9 @@ class Writer { handle(object); exitBlock(); } + /// Write a vector to the output stream + template + void handle(const Char* name, const vector& vector); /// Write a string to the output stream void handle(const String& str); @@ -41,8 +44,6 @@ class Writer { /// Write an object of type T to the output stream template void handle(const T& object); - /// Write a vector to the output stream - template void handle(const vector& vector); /// Write a shared_ptr to the output stream template void handle(const shared_ptr& pointer); /// Write a map to the output stream @@ -78,13 +79,13 @@ class Writer { // ----------------------------------------------------------------------------- : Container types template -void Writer::handle(const vector& vector) { - /*String vectorKey = key; - while (key == vectorKey) { // TODO : check indent - moveNext(); // skip key - vector.resize(vector.size() + 1); - handle(vector.back()); - }*/ +void Writer::handle(const Char* name, const vector& vec) { + String vectorKey = singular_form(name); + for (vector::const_iterator it = vec.begin() ; it != vec.end() ; ++it) { + enterBlock(vectorKey); + handle(*it); + exitBlock(); + } } template diff --git a/src/util/string.cpp b/src/util/string.cpp index 084172cc..e1e9f8ad 100644 --- a/src/util/string.cpp +++ b/src/util/string.cpp @@ -133,3 +133,9 @@ String cannocial_name_form(const String& str) { } return ret; } + +String singular_form(const String& str) { + assert(str.size() > 1); + assert(str.GetChar(str.size() - 1) == _('s')); // ends in 's' + return str.substr(0, str.size() - 1); +} diff --git a/src/util/string.hpp b/src/util/string.hpp index b78236f8..fd88e6ae 100644 --- a/src/util/string.hpp +++ b/src/util/string.hpp @@ -106,5 +106,10 @@ String capitalize_sentence(const String&); */ String cannocial_name_form(const String&); +/// Returns the singular form of a string +/** Used for reflection, for example "vector apples" is written with keys "apple" + */ +String singular_form(const String&); + // ----------------------------------------------------------------------------- : EOF #endif