Commit db72df28 authored by twanvl's avatar twanvl

Automatic use of singular names -> even more use of REFLECT instead of REFLECT_N.

This also works better for GetMember, since the plural names (which make sense for scripts) are the default.
parent 88919557
...@@ -32,8 +32,8 @@ IMPLEMENT_REFLECTION(Game) { ...@@ -32,8 +32,8 @@ IMPLEMENT_REFLECTION(Game) {
REFLECT(card_fields); REFLECT(card_fields);
// REFLECT_N("keyword parameter type", keyword_params); // REFLECT_N("keyword parameter type", keyword_params);
// REFLECT_N("keyword separator type", keyword_separators); // REFLECT_N("keyword separator type", keyword_separators);
// REFLECT_N("keyword", keywords); // REFLECT(keywords);
// REFLECT_N("word list", word_lists); // REFLECT(word_lists);
} }
void Game::validate() { void Game::validate() {
......
...@@ -95,7 +95,7 @@ String Settings::settingsFile() { ...@@ -95,7 +95,7 @@ String Settings::settingsFile() {
IMPLEMENT_REFLECTION(Settings) { IMPLEMENT_REFLECTION(Settings) {
// ioMseVersion(io, "settings", file_version); // ioMseVersion(io, "settings", file_version);
REFLECT_N("recent_set", recent_sets); REFLECT(recent_sets);
REFLECT(set_window_maximized); REFLECT(set_window_maximized);
REFLECT(set_window_width); REFLECT(set_window_width);
REFLECT(set_window_height); REFLECT(set_window_height);
......
...@@ -106,7 +106,7 @@ IMPLEMENT_REFLECTION_ENUM(SymbolPartCombine) { ...@@ -106,7 +106,7 @@ IMPLEMENT_REFLECTION_ENUM(SymbolPartCombine) {
IMPLEMENT_REFLECTION(SymbolPart) { IMPLEMENT_REFLECTION(SymbolPart) {
REFLECT(name); REFLECT(name);
REFLECT(combine); REFLECT(combine);
REFLECT_N("point", points); REFLECT(points);
// Fixes after reading // Fixes after reading
if (tag.reading()) { if (tag.reading()) {
// enforce constraints // enforce constraints
...@@ -160,7 +160,7 @@ void SymbolPart::calculateBounds() { ...@@ -160,7 +160,7 @@ void SymbolPart::calculateBounds() {
IMPLEMENT_REFLECTION(Symbol) { IMPLEMENT_REFLECTION(Symbol) {
//%% version? //%% version?
REFLECT_N("part", parts); REFLECT(parts);
} }
// ----------------------------------------------------------------------------- : SymbolView // ----------------------------------------------------------------------------- : SymbolView
......
...@@ -37,8 +37,8 @@ bool MSE::OnInit() { ...@@ -37,8 +37,8 @@ bool MSE::OnInit() {
wxInitAllImageHandlers(); wxInitAllImageHandlers();
initFileFormats(); initFileFormats();
settings.read(); settings.read();
//Window* wnd = new SymbolWindow(nullptr); Window* wnd = new SymbolWindow(nullptr);
Window* wnd = new SetWindow(nullptr, new_shared1<Set>(Game::byName(_("magic")))); //Window* wnd = new SetWindow(nullptr, new_shared1<Set>(Game::byName(_("magic"))));
wnd->Show(); wnd->Show();
return true; return true;
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
// ----------------------------------------------------------------------------- : Includes // ----------------------------------------------------------------------------- : Includes
#include "../prec.hpp" #include <util/prec.hpp>
#include <wx/txtstrm.h> #include <wx/txtstrm.h>
// ----------------------------------------------------------------------------- : Reader // ----------------------------------------------------------------------------- : Reader
...@@ -47,11 +47,12 @@ class Reader { ...@@ -47,11 +47,12 @@ class Reader {
exitBlock(); exitBlock();
} }
} }
/// Reads a vector from the input stream
template <typename T>
void handle(const Char* name, vector<T>& vector);
/// Reads an object of type T from the input stream /// Reads an object of type T from the input stream
template <typename T> void handle(T& object); template <typename T> void handle(T& object);
/// Reads a vector from the input stream
template <typename T> void handle(vector<T>& vector);
/// Reads a shared_ptr from the input stream /// Reads a shared_ptr from the input stream
template <typename T> void handle(shared_ptr<T>& pointer); template <typename T> void handle(shared_ptr<T>& pointer);
/// Reads a map from the input stream /// Reads a map from the input stream
...@@ -109,12 +110,12 @@ shared_ptr<T> read_new(Reader& reader) { ...@@ -109,12 +110,12 @@ shared_ptr<T> read_new(Reader& reader) {
} }
template <typename T> template <typename T>
void Reader::handle(vector<T>& vector) { void Reader::handle(const Char* name, vector<T>& vector) {
String vectorKey = key; String vectorKey = singular_form(name);
while (key == vectorKey) { // TODO : check indent while (enterBlock(vectorKey)) {
moveNext(); // skip key
vector.resize(vector.size() + 1); vector.resize(vector.size() + 1);
handle(vector.back()); handle(vector.back());
exitBlock();
} }
} }
......
...@@ -34,6 +34,9 @@ class Writer { ...@@ -34,6 +34,9 @@ class Writer {
handle(object); handle(object);
exitBlock(); exitBlock();
} }
/// Write a vector to the output stream
template <typename T>
void handle(const Char* name, const vector<T>& vector);
/// Write a string to the output stream /// Write a string to the output stream
void handle(const String& str); void handle(const String& str);
...@@ -41,8 +44,6 @@ class Writer { ...@@ -41,8 +44,6 @@ class Writer {
/// Write an object of type T to the output stream /// Write an object of type T to the output stream
template <typename T> void handle(const T& object); template <typename T> void handle(const T& object);
/// Write a vector to the output stream
template <typename T> void handle(const vector<T>& vector);
/// Write a shared_ptr to the output stream /// Write a shared_ptr to the output stream
template <typename T> void handle(const shared_ptr<T>& pointer); template <typename T> void handle(const shared_ptr<T>& pointer);
/// Write a map to the output stream /// Write a map to the output stream
...@@ -78,13 +79,13 @@ class Writer { ...@@ -78,13 +79,13 @@ class Writer {
// ----------------------------------------------------------------------------- : Container types // ----------------------------------------------------------------------------- : Container types
template <typename T> template <typename T>
void Writer::handle(const vector<T>& vector) { void Writer::handle(const Char* name, const vector<T>& vec) {
/*String vectorKey = key; String vectorKey = singular_form(name);
while (key == vectorKey) { // TODO : check indent for (vector<T>::const_iterator it = vec.begin() ; it != vec.end() ; ++it) {
moveNext(); // skip key enterBlock(vectorKey);
vector.resize(vector.size() + 1); handle(*it);
handle(vector.back()); exitBlock();
}*/ }
} }
template <typename T> template <typename T>
......
...@@ -133,3 +133,9 @@ String cannocial_name_form(const String& str) { ...@@ -133,3 +133,9 @@ String cannocial_name_form(const String& str) {
} }
return ret; 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);
}
...@@ -106,5 +106,10 @@ String capitalize_sentence(const String&); ...@@ -106,5 +106,10 @@ String capitalize_sentence(const String&);
*/ */
String cannocial_name_form(const String&); String cannocial_name_form(const String&);
/// Returns the singular form of a string
/** Used for reflection, for example "vector<T> apples" is written with keys "apple"
*/
String singular_form(const String&);
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
#endif #endif
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