summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-02-22 20:54:39 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-02-22 20:54:39 +0000
commit320e5cc574f0c8f83def034e36f6d0c57b1f75ac (patch)
tree3b85a2f1247069d34472a3561f3488f912491f57
parentMove Appender in Persistence NS and simplify types (diff)
downloadilt-320e5cc574f0c8f83def034e36f6d0c57b1f75ac.tar.bz2
ilt-320e5cc574f0c8f83def034e36f6d0c57b1f75ac.tar.xz
ilt-320e5cc574f0c8f83def034e36f6d0c57b1f75ac.zip
Fixup MapByMember to work with shared or unique ptr
-rw-r--r--assetFactory/assetFactory.cpp2
-rw-r--r--lib/persistence.h12
2 files changed, 7 insertions, 7 deletions
diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp
index 0ee1f94..470eacf 100644
--- a/assetFactory/assetFactory.cpp
+++ b/assetFactory/assetFactory.cpp
@@ -26,6 +26,6 @@ AssetFactory::loadXML(const std::filesystem::path & filename)
bool
AssetFactory::persist(Persistence::PersistenceStore & store)
{
- using MapObjects = Persistence::MapByMember<Shapes, Object>;
+ using MapObjects = Persistence::MapByMember<Shapes, std::shared_ptr<Object>>;
return STORE_TYPE && STORE_NAME_HELPER("object", shapes, MapObjects);
}
diff --git a/lib/persistence.h b/lib/persistence.h
index 5c8454c..0fc0200 100644
--- a/lib/persistence.h
+++ b/lib/persistence.h
@@ -256,20 +256,20 @@ namespace Persistence {
}
};
- template<typename Map, typename Type = typename Map::mapped_type, auto Key = &Type::id>
- struct MapByMember : public Persistence::SelectionT<std::shared_ptr<Type>> {
- MapByMember(Map & m) : Persistence::SelectionT<std::shared_ptr<Type>> {s}, map {m} { }
+ template<typename Map, typename Type = typename Map::mapped_type, auto Key = &Type::element_type::id>
+ struct MapByMember : public Persistence::SelectionT<Type> {
+ MapByMember(Map & m) : Persistence::SelectionT<Type> {s}, map {m} { }
- using Persistence::SelectionT<std::shared_ptr<Type>>::SelectionT;
+ using Persistence::SelectionT<Type>::SelectionT;
void
endObject(Persistence::Stack & stk) override
{
- map.emplace(std::invoke(Key, s), s);
+ map.emplace(std::invoke(Key, s), std::move(s));
stk.pop();
}
private:
- std::shared_ptr<Type> s;
+ Type s;
Map & map;
};