20 #include <tbb/concurrent_hash_map.h>
21 #include <tbb/concurrent_unordered_set.h>
22 #include <tbb/concurrent_vector.h>
23 #include <tbb/concurrent_queue.h>
24 #include <tbb/parallel_for.h>
29 #include <vlutil/vlUtil.h>
47 template<
typename KeyType,
typename KeyTypeHasher>
82 virtual void keyedDatas(std::vector<DtKeyedData*>& vecKeyedDatas);
92 template<
class ClassToCreate,
class ...ConstructorArgs>
98 if (tcsData ==
nullptr)
100 myDe.DT_LOG_WARN <<
"tcsData == nullptr" << std::endl;
104 auto resultUserData = tcsData->
getOrCreateUserData(userPointer, creator, std::forward<ConstructorArgs>(constructorArgs)...);
105 ClassToCreate* userData =
static_cast<ClassToCreate*
>(resultUserData.myTcsUserData);
106 if (userData ==
nullptr)
108 myDe.DT_LOG_WARN <<
"userData == nullptr" << std::endl;
115 T*
findUserData(
const KeyType& key,
const void* userPointer,
bool log =
true)
const
118 if (tcsData ==
nullptr)
122 myDe.DT_LOG_WARN <<
"tcsData == nullptr" << std::endl;
126 T* userData =
static_cast<T*
>(tcsData->
findUserData(userPointer));
127 if (userData ==
nullptr)
131 myDe.DT_LOG_WARN <<
"userData == nullptr" << std::endl;
149 if (tcsData ==
nullptr)
153 myDe.DT_LOG_WARN <<
"tcsData == nullptr" << std::endl;
155 return {
nullptr,
nullptr };
157 T* userData =
static_cast<T*
>(tcsData->
findUserData(userPointer));
158 if (userData ==
nullptr)
162 myDe.DT_LOG_WARN <<
"userData == nullptr" << std::endl;
165 return { tcsData, userData };
182 typedef tbb::concurrent_hash_map< KeyType, DtKeyedData*, KeyTypeHasher>
HashTable;
193 template<
typename KeyType,
typename KeyTypeHasher>
209 else if (flushLocation ==
NONE)
215 myDe.DT_LOG_WARN <<
"Unknown flush location: " << flushLocation << std::endl;
219 template<
typename KeyType,
typename KeyTypeHasher>
222 tbb::parallel_for(myHashTable.range(), [](
const typename HashTable::range_type& r) {
223 for (
auto i = r.begin(); i != r.end(); i++)
230 template<
typename KeyType,
typename KeyTypeHasher>
233 tbb::parallel_for(myHashTable.range(), [=](
const typename HashTable::range_type& r) {
234 for (
auto i = r.begin(); i != r.end(); i++)
241 template<
typename KeyType,
typename KeyTypeHasher>
244 tbb::concurrent_queue<DtKeyedData*> queueKeyedDatas;
245 tbb::parallel_for(myHashTable.range(), [&](
const typename HashTable::range_type& r) {
246 for (
auto i = r.begin(); i != r.end(); i++)
248 queueKeyedDatas.push(i->second);
253 while (queueKeyedDatas.try_pop(keyedData))
255 vecKeyedDatas.push_back(keyedData);
259 template<
typename KeyType,
typename KeyTypeHasher>
263 typename HashTable::accessor accessor;
264 const bool inserted = myHashTable.insert(accessor, key);
267 auto& entry = accessor->second;
272 if (tcsData ==
nullptr)
274 myDe.DT_LOG_WARN <<
"tcsData == nullptr" << std::endl;
276 return { tcsData, inserted };
279 template<
typename KeyType,
typename KeyTypeHasher>
282 typename HashTable::const_accessor accessor;
283 const bool found = myHashTable.find(accessor, key);
288 return accessor->second;
291 template<
typename KeyType,
typename KeyTypeHasher>
294 if (tcsData ==
nullptr)
296 myDe.DT_LOG_WARN <<
"tcsData == nullptr" << std::endl;
301 std::atomic<bool> found{
false };
302 tbb::parallel_for(myHashTable.range(), [&](
const typename HashTable::range_type& r) {
303 for (
auto i = r.begin(); i != r.end(); i++)
305 if (i->second == tcsData)
308 keyToErase = i->first;
315 myDe.DT_LOG_WARN <<
"found == false" << std::endl;
319 myHashTable.erase(keyToErase);
323 template<
typename KeyType,
typename KeyTypeHasher>
326 myKeysToEraseScratchPad.clear();
327 tbb::parallel_for(myHashTable.range(), [&](
const typename HashTable::range_type& r) {
328 for (
auto i = r.begin(); i != r.end(); i++)
330 if (!i->first.valid())
332 myKeysToEraseScratchPad.push(i->first);
338 bool atleastOneDeleted =
false;
340 while (myKeysToEraseScratchPad.try_pop(key))
342 typename HashTable::accessor accessor;
343 bool found = myHashTable.find(accessor, key);
346 myDe.DT_LOG_WARN <<
"found == false" << std::endl;
349 DtDELETE(accessor->second);
350 myHashTable.erase(accessor);
351 atleastOneDeleted =
true;
354 if (atleastOneDeleted)
356 signal_KeysDeleted();
360 template<
typename KeyType,
typename KeyTypeHasher>
366 template<
typename KeyType,
typename KeyTypeHasher>
T * myTcsUserData
Definition: DtKeyedDataManagerTemplate.h:141
FlushKeysLocation
Definition: DtKeyedDataManagerTemplate.h:51
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
T * findUserData(const KeyType &key, const void *userPointer, bool log=true) const
find user data for a class T
Definition: DtKeyedDataManagerTemplate.h:115
boost::signalslib::signal< void(DtDe &)> signal_preTick
Signal emitted at the beginning of the tick function. This is useful for executing code before the Di...
Definition: DtDe.h:489
DtDe & myDe
Definition: DtKeyedDataManagerTemplate.h:185
virtual DtKeyedDataUserData * findUserData(const void *userPointer) const
find tc user data
virtual void keyedDatas(std::vector< DtKeyedData * > &vecKeyedDatas)
Get the keyed datas.
Definition: DtKeyedDataManagerTemplate.h:242
DtKeyedData * myTcsData
Definition: DtKeyedDataManagerTemplate.h:140
DtKeyedData * myTcsData
Definition: DtKeyedDataManagerTemplate.h:38
bool myCreated
Definition: DtKeyedDataManagerTemplate.h:39
boost::signalslib::signal< void()> signal_postTick
Signal emitted at the end of the tick function. This is useful for executing code after the Display E...
Definition: DtDe.h:496
tbb::concurrent_hash_map< KeyType, DtKeyedData *, KeyTypeHasher > HashTable
Definition: DtKeyedDataManagerTemplate.h:182
Definition: DtKeyedDataManagerTemplate.h:138
This class is used in conjunction with DtKeyedDataManagerTemplate. It represents data associated with...
Definition: DtKeyedData.h:30
virtual void slot_preTick()
pre tick function
Definition: DtKeyedDataManagerTemplate.h:361
virtual void flushInvalidKeys()
flush cameras that go out of the system
Definition: DtKeyedDataManagerTemplate.h:324
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:22
FindResult< T > findTcsDataAndUserData(const KeyType &key, const void *userPointer, bool log=true) const
find tcs data and user data for a class T
Definition: DtKeyedDataManagerTemplate.h:146
Contains makVrv::DtVirtualBaseClass class.
virtual CreationResult getOrCreate(const KeyType &key)
get or create the keyed data
Definition: DtKeyedDataManagerTemplate.h:260
Definition: DtKeyedDataManagerTemplate.h:85
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
Definition: DtKeyedDataManagerTemplate.h:53
Definition: DtKeyedDataManagerTemplate.h:36
virtual ~DtKeyedDataManagerTemplate()
destructor
Definition: DtKeyedDataManagerTemplate.h:220
boost::signalslib::signal< void()> signal_KeysDeleted
Definition: DtKeyedDataManagerTemplate.h:56
HashTable myHashTable
Definition: DtKeyedDataManagerTemplate.h:183
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
UserDataCreationResult getOrCreateUserData(const void *userPointer, DtVirtualBaseClassCreator< ClassToCreate, ConstructorArgs...> *creator, ConstructorArgs &&...constructorArgs)
get or create the tcs user data
Definition: DtKeyedData.h:74
Manager for DtKeyedData Used to create/manage DtKeyedData Each entry of DtKeyedData is associated wit...
Definition: DtKeyedDataManagerTemplate.h:48
T * myTcsUserData
Definition: DtKeyedDataManagerTemplate.h:87
Base class to provide boost signal/slot management.
virtual void deleteTcsData(DtKeyedData *tcsData)
Delete tcs data, if it exists. Will also delete the user datas, if any.
Definition: DtKeyedDataManagerTemplate.h:292
virtual DtKeyedData * find(const KeyType &key) const
find tcs data
Definition: DtKeyedDataManagerTemplate.h:280
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:72
DtKeyedDataManagerTemplate()=delete
not allowed
bool myCreated
Definition: DtKeyedDataManagerTemplate.h:88
virtual void slot_postTick()
post tick function
Definition: DtKeyedDataManagerTemplate.h:367
Definition: DtKeyedDataManagerTemplate.h:53
TemplatedCreationResult< ClassToCreate > getOrCreateUserData(const KeyType &key, const void *userPointer, DtVirtualBaseClassCreator< ClassToCreate, ConstructorArgs...> *creator, ConstructorArgs &&...constructorArgs)
get or create user data for a class T
Definition: DtKeyedDataManagerTemplate.h:93
DtSignalConnectionManager myConnections
manager for connections
Definition: DtKeyedDataManagerTemplate.h:188
DtKeyedDataManagerTemplate & operator=(const DtKeyedDataManagerTemplate &rhs)=delete
not allowed
tbb::concurrent_queue< KeyType > myKeysToEraseScratchPad
Definition: DtKeyedDataManagerTemplate.h:190
Definition: DtKeyedDataManagerTemplate.h:53
virtual void forEachKeyedData(const std::function< void(DtKeyedData *)> &func)
call a function on each keyed data. Note: the call may happen in a different thread than the thread t...
Definition: DtKeyedDataManagerTemplate.h:231
Contains DLL export macros.