//+----------------------------------------------------------------------------+ //| Description: Magic Set Editor - Program to make Magic (tm) cards | //| Copyright: (C) 2001 - 2010 Twan van Laarhoven and Sean Hunt | //| License: GNU General Public License 2 or later (see file COPYING) | //+----------------------------------------------------------------------------+ #ifndef HEADER_UTIL_DELAYED_INDEX_MAPS #define HEADER_UTIL_DELAYED_INDEX_MAPS // ----------------------------------------------------------------------------- : Includes #include #include #include #include #include // ----------------------------------------------------------------------------- : DelayedIndexMaps template IndexMap& DelayedIndexMaps::get(const String& name, const vector& init_with) { intrusive_ptr >& item = data[name]; if (!item) { // no item, make a new one item = intrusive(new DelayedIndexMapsData); item->read_data.init(init_with); } else if (!item->unread_data.empty()) { // not read, read now item->read_data.init(init_with); Reader reader(shared(new wxStringInputStream(item->unread_data)), nullptr, _("delayed data for ") + name); reader.handle_greedy(item->read_data); item->unread_data.clear(); } return item->read_data; } template void DelayedIndexMaps::clear() { data.clear(); } // ----------------------------------------------------------------------------- : Reflection // custom reflection : it's a template class template void Reader::handle(DelayedIndexMaps& dim) { handle(dim.data); } template void Writer::handle(const DelayedIndexMaps& dim) { handle(dim.data); } template void GetMember::handle(const DelayedIndexMaps& dim) { handle(dim.data); } // custom reflection : read into unread_data template void Reader::handle(DelayedIndexMapsData& d) { handle(d.unread_data); if (d.unread_data.empty()) d.unread_data = _("\n"); // never empty (invariant) } template void Writer::handle(const DelayedIndexMapsData& d) { if (!d.unread_data.empty()) { if (d.unread_data == _("\n")) { // this is not interesting, it is only used to make unread_data nonempty (see above) // we don't need to write it } else { handle(d.unread_data); // TODO: how to handle filenames } } else { handle(d.read_data); } } template void GetMember::handle(const DelayedIndexMapsData& d) { handle(d.read_data); } template void GetDefaultMember::handle(const DelayedIndexMapsData& d) { handle(d.read_data); } // ----------------------------------------------------------------------------- : EOF #endif