OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
ObjectManagerTemplate.h
Go to the documentation of this file.
1
4// ###########################################################################################################################################################################################################################################################################################################################
5
6#pragma once
7
8// std header
9#include <map>
10
11//#pragma warning(disable:4251)
12
13namespace ot {
14
17 template <class K, class V>
19 public:
21
26 bool insert(const K& _key, V* _object);
27
31 void replace(const K& _key, V* _object);
32
35 bool contains(const K& _key) { return (bool)this->find(_key); };
36
41 V* const find(const K& _key);
42
47 V* grab(const K& _key);
48
53 V* const operator [](const K& _key);
54
55 private:
56 std::map<K, V *> m_objects;
57 };
58}
59
60template <class K, class V>
61bool ot::ObjectManagerTemplate<K, V>::insert(const K& _key, V* _object) {
62 if (m_objects.find(_key) != m_objects.end()) { return false; }
63 else { m_objects.insert_or_assign(_key, _object); return true; }
64}
65
66template <class K, class V>
67void ot::ObjectManagerTemplate<K, V>::replace(const K& _key, V* _object) {
68 if (m_objects.find(_key) != m_objects.end()) { delete m_objects.find(_key)->second; };
69 m_objects.insert_or_assign(_key, _object);
70}
71
72template <class K, class V>
74 auto it = m_objects.find(_key);
75 if (it == m_objects.end()) { return (V*)nullptr; }
76 else { return it->second; }
77}
78
79template <class K, class V>
81 auto it = m_objects.find(_key);
82 V* ret = (it != m_objects.end() ? it->second : (V*)nullptr);
83 m_objects.erase(_key);
84 return ret;
85}
86
87template <class K, class V>
89 auto it = m_objects.find(_key);
90 if (it == m_objects.end()) { return (V*)nullptr; }
91 else { return it->second; }
92}
CGAL::Exact_predicates_inexact_constructions_kernel K
Definition SelfIntersectionCheck.cpp:21
Definition ObjectManagerTemplate.h:18
bool insert(const K &_key, V *_object)
Store the provided object for the given key. If there exists an entry for the given key the function ...
Definition ObjectManagerTemplate.h:61
bool contains(const K &_key)
Returns true if an entry exits for the given key.
Definition ObjectManagerTemplate.h:35
void replace(const K &_key, V *_object)
Store the provided object for the given key. If there exists an entry for the given key the entry wil...
Definition ObjectManagerTemplate.h:67
V *const operator[](const K &_key)
Return stored pointer to object for the given key. Note that the Object Manager keeps the ownership.
Definition ObjectManagerTemplate.h:88
V * grab(const K &_key)
Return stored pointer to object for the given key and remove from object manager. Note that the calle...
Definition ObjectManagerTemplate.h:80
virtual ~ObjectManagerTemplate()
Definition ObjectManagerTemplate.h:20
V *const find(const K &_key)
Return stored pointer to object for the given key. Note that the Object Manager keeps the ownership.
Definition ObjectManagerTemplate.h:73
Definition Connector.h:8