1616
1717#include < map>
1818
19- using namespace KDBindings ;
20-
2119// TODO: Maybe belongs to ecs?
2220
2321namespace KDFoundation {
@@ -26,22 +24,22 @@ template<typename ContainerType, typename DependencyType>
2624class DestructionHelperManager
2725{
2826public:
29- ConnectionHandle contToDepConnection (std::pair<ContainerType *, DependencyType *> contDepPair)
27+ KDBindings:: ConnectionHandle contToDepConnection (std::pair<ContainerType *, DependencyType *> contDepPair)
3028 {
3129 return m_contToDepMap[contDepPair];
3230 }
3331
34- ConnectionHandle depToContConnection (std::pair<DependencyType *, ContainerType *> depContPair)
32+ KDBindings:: ConnectionHandle depToContConnection (std::pair<DependencyType *, ContainerType *> depContPair)
3533 {
3634 return m_depToContMap[depContPair];
3735 }
3836
39- void addContToDepConnection (std::pair<ContainerType *, DependencyType *> contDepPair, ConnectionHandle handle)
37+ void addContToDepConnection (std::pair<ContainerType *, DependencyType *> contDepPair, KDBindings:: ConnectionHandle handle)
4038 {
4139 m_contToDepMap[contDepPair] = handle;
4240 }
4341
44- void addDepToContConnection (std::pair<DependencyType *, ContainerType *> depContPair, ConnectionHandle handle)
42+ void addDepToContConnection (std::pair<DependencyType *, ContainerType *> depContPair, KDBindings:: ConnectionHandle handle)
4543 {
4644 m_depToContMap[depContPair] = handle;
4745 }
@@ -62,7 +60,7 @@ class DestructionHelperManager
6260 }
6361 }
6462
65- void clearDepToContConnctions ()
63+ void clearDepToContConnections ()
6664 {
6765 for (const auto &depConn : m_depToContMap) {
6866 depConn.first .first ->destroyed .disconnect (depConn.second );
@@ -71,12 +69,14 @@ class DestructionHelperManager
7169 }
7270
7371private:
74- std::map<std::pair<ContainerType *, DependencyType *>, ConnectionHandle> m_contToDepMap;
75- std::map<std::pair<DependencyType *, ContainerType *>, ConnectionHandle> m_depToContMap;
72+ std::map<std::pair<ContainerType *, DependencyType *>, KDBindings:: ConnectionHandle> m_contToDepMap;
73+ std::map<std::pair<DependencyType *, ContainerType *>, KDBindings:: ConnectionHandle> m_depToContMap;
7674};
7775
76+ // Watch object held by property of type KDBinding::Property<DependencyType *> and resets property value if node is destroyed
77+ // Optional property owner can be passed in
7878template <typename DependencyType, typename ContainerType>
79- void registerDestructionHelper (Property<DependencyType *> *property, ConnectionHandle *connectionHandle, ContainerType *owner)
79+ void registerDestructionHelper (KDBindings:: Property<DependencyType *> *property, KDBindings:: ConnectionHandle *connectionHandle, ContainerType *owner)
8080{
8181 std::ignore = property->valueAboutToChange ().connect ([=](DependencyType *oldVal, DependencyType * /* newVal */ ) {
8282 if (!oldVal) {
@@ -101,6 +101,7 @@ void registerDestructionHelper(Property<DependencyType *> *property, ConnectionH
101101 }
102102}
103103
104+ // Triggers dependencyCleanupFunctor when DependencyType instance referenced by Container is destroyed
104105template <typename ContainerType, typename DependencyType, typename OnDepenencyDestructionFunctorType>
105106void registerDestructionHelper (ContainerType *container, DependencyType *dependency, DestructionHelperManager<ContainerType, DependencyType> *manager, OnDepenencyDestructionFunctorType dependencyCleanupFunctor)
106107{
@@ -115,7 +116,7 @@ void registerDestructionHelper(ContainerType *container, DependencyType *depende
115116
116117 if (container) {
117118 auto contToDep = container->destroyed .connect ([=] {
118- manager->clearDepToContConnctions ();
119+ manager->clearDepToContConnections ();
119120 manager->delContToDepConnection ({ container, dependency });
120121 });
121122
0 commit comments