diff options
author | Andreas Stöckel <astoecke@techfak.uni-bielefeld.de> | 2014-11-21 20:55:18 +0100 |
---|---|---|
committer | Andreas Stöckel <andreas@somweyr.de> | 2014-11-21 20:55:18 +0100 |
commit | 37fadceb4b2e060844bd1c68f22eb71ce362249d (patch) | |
tree | 22226d2ffa543403313bb1113a4b1347ff39425d | |
parent | e21f7f1a6d6cc0ac56ef3a5585f66269275a9133 (diff) |
renamed add and deleteManaged functions, improved NodeVector and NodeMap classes
-rw-r--r-- | src/core/ManagedContainers.hpp | 29 | ||||
-rw-r--r-- | src/core/Node.hpp | 36 |
2 files changed, 47 insertions, 18 deletions
diff --git a/src/core/ManagedContainers.hpp b/src/core/ManagedContainers.hpp index 9d3dc96..9447fff 100644 --- a/src/core/ManagedContainers.hpp +++ b/src/core/ManagedContainers.hpp @@ -59,13 +59,13 @@ protected: * Function which can be overridden by child classes to execute special code * whenever a new element is added to the collection. */ - virtual void addManaged(value_type h) {} + virtual void addElement(value_type h) {} /** * Function which can be overriden by child classes to execute special code * whenever an element is removed from the collection. */ - virtual void deleteManaged(value_type h) {} + virtual void deleteElement(value_type h) {} public: /** @@ -103,7 +103,7 @@ public: void clear() noexcept { for (const_iterator it = cbegin(); it != cend(); it++) { - deleteManaged(*it); + deleteElement(*it); } c.clear(); } @@ -179,7 +179,7 @@ public: iterator insert(const_iterator position, Handle<T> h) { value_type v = Base::owner->acquire(h); - addManaged(v); + addElement(v); return Base::c.insert(position, v); } @@ -223,28 +223,28 @@ public: void push_back(Handle<T> h) { value_type v = Base::owner->acquire(h); - this->addManaged(v); + this->addElement(v); Base::c.push_back(v); } void pop_back() { if (!Base::empty()) { - this->deleteManaged(back()); + this->deleteElement(back()); } Base::c.pop_back(); } iterator erase(iterator position) { - this->deleteManaged(*position); + this->deleteElement(*position); return Base::c.erase(position); } iterator erase(iterator first, iterator last) { for (const_iterator it = first; it != last; it++) { - this->deleteManaged(*it); + this->deleteElement(*it); } return Base::c.erase(first, last); } @@ -262,7 +262,7 @@ public: using Base::ManagedContainer; using collection_type = typename Base::collection_type; using value_type = typename Base::value_type; - using key_type = typename Base::key_type; + using key_type = typename Collection::key_type; using reference = typename Base::reference; using const_reference = typename Base::const_reference; using iterator = typename Base::iterator; @@ -272,8 +272,7 @@ public: private: value_type acquirePair(std::pair<K, Handle<T>> val) { - return std::pair<const K, T>{val->first, - Base::owner->acquire(val->second)}; + return value_type{val.first, Base::owner->acquire(val.second)}; } public: @@ -315,14 +314,14 @@ public: std::pair<iterator, bool> insert(std::pair<K, Handle<T>> val) { value_type v = acquirePair(val); - addManaged(v); + this->addElement(v); return Base::c.insert(v); } iterator insert(const_iterator position, std::pair<K, Handle<T>> val) { value_type v = acquirePair(val); - addManaged(v); + this->addElement(v); return Base::c.insert(position, v); } @@ -336,7 +335,7 @@ public: iterator erase(const_iterator position) { - Base::deleteManaged(*position); + this->deleteElement(*position); return Base::c.erase(position); } @@ -353,7 +352,7 @@ public: iterator erase(const_iterator first, const_iterator last) { for (const_iterator it = first; it != last; it++) { - Base::deleteManaged(*it); + this->deleteElement(*it); } return Base::c.erase(first, last); } diff --git a/src/core/Node.hpp b/src/core/Node.hpp index f32beb7..b7d050d 100644 --- a/src/core/Node.hpp +++ b/src/core/Node.hpp @@ -25,7 +25,8 @@ #include <vector> #include <unordered_set> -#include <core/Managed.hpp> +#include "Managed.hpp" +#include "ManagedContainers.hpp" namespace ousia { @@ -226,12 +227,12 @@ public: * filter tests whether the given node meets the requirements for inclusion * in the result list. * - * @param node is the node which should be tested. + * @param managed is the managed which should be tested. * @param data is user-defined data passed to the filter. * @return true if the node should be included in the result set, false * otherwise. */ - using Filter = bool (*)(Handle<Node> node, void *data); + using Filter = bool (*)(Handle<Managed> managed, void *data); /** * Hash functional used to convert pairs of nodes and int to hashes which @@ -510,6 +511,35 @@ public: */ bool triggerEvent(Event &event, bool fromChild = false); }; + +template <class T, class Collection> +class NodeGenericList : public ManagedGenericList<T, Collection> { +protected: + // TODO: Override addElement, deleteElement once this is necessary +public: + using ManagedGenericList<T, Collection>::ManagedGenericList; +}; + +template <class K, class T, class Collection> +class NodeGenericMap : public ManagedGenericMap<K, T, Collection> { +protected: + // TODO: Override addElement, deleteElement once this is necessary +public: + using ManagedGenericMap<K, T, std::vector<Owned<T>>>::ManagedGenericMap; +}; + +template <class T> +class NodeVector : public NodeGenericList<T, std::vector<Owned<T>>> { +public: + using NodeGenericList<T, std::vector<Owned<T>>>::NodeGenericList; +}; + +template <class K, class T> +class NodeMap : public NodeGenericMap<K, T, std::map<K, Owned<T>>> { +public: + using NodeGenericMap<K, T, std::map<K, Owned<T>>>::NodeGenericMap; +}; + } #endif /* _OUSIA_NODE_HPP_ */ |