VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtKeyedData.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2023 VT-MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvCore/vrvCore.h>
14 
15 #include <tbb/concurrent_hash_map.h>
16 
17 #include <thread>
18 
19 namespace makVrv
20 {
21  class DtDe;
22 
23  class DtKeyedDataUserData;
24  class DtTcsUserDataCreator;
25 
31  {
32  public:
33  DtKeyedData(DtDe& de, const std::string& name);
34  virtual ~DtKeyedData();
35  private:
37  DtKeyedData() = delete;
39  DtKeyedData(const DtKeyedData& rhs) = delete;
41  DtKeyedData& operator=(const DtKeyedData& rhs) = delete;
42 
43  public:
44 
46  {
47  DtKeyedDataUserData* myTcsUserData = nullptr;
48  bool myCreated = false;
49  };
50  public:
52  template<class ClassToCreate, class ...ConstructorArgs>
53  UserDataCreationResult getOrCreateUserData(const void* userPointer, DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>* creator
54  , ConstructorArgs&&... constructorArgs);
55 
57  virtual DtKeyedDataUserData* findUserData(const void* userPointer) const;
58 
60  virtual void deleteUserData(const void* userPointer);
61 
62  protected:
64 
65  typedef tbb::concurrent_hash_map< const void*, DtKeyedDataUserData*> UserDataHashTable;
67 
68  const std::string myName;
69 
70  static std::atomic<int> theCount;
71  };
72 
73  template<class ClassToCreate, class ...ConstructorArgs>
75  , ConstructorArgs&&... constructorArgs)
76  {
78  UserDataHashTable::accessor accessor;
79  const bool inserted = myUserDataHashTable.insert(accessor, userPointer);
80  if (inserted)
81  {
82  auto& entry = accessor->second;
83  entry = creator->create(std::forward<ConstructorArgs>(constructorArgs)...);
84  }
85 
86  DtKeyedDataUserData* tcsUserData = accessor->second;
87  if (tcsUserData == nullptr)
88  {
89  myDe.DT_LOG_WARN << "tcsUserData == nullptr" << std::endl << std::endl;
90  }
91  return { tcsUserData, inserted };
92  }
93 
96  {
97  public:
98  DtKeyedDataUserData(DtDe& de, const std::string& name);
99  virtual ~DtKeyedDataUserData();
100  private:
102  DtKeyedDataUserData() = delete;
104  DtKeyedDataUserData(const DtKeyedDataUserData& rhs) = delete;
106  DtKeyedDataUserData& operator=(const DtKeyedDataUserData& rhs) = delete;
107  protected:
109 
110  const std::string myName;
111 
112  static std::atomic<int> theCount;
113  };
114 
115 }
This represents an arbitrary user pointer/data within DtKeyedData.
Definition: DtKeyedData.h:95
static std::atomic< int > theCount
Definition: DtKeyedData.h:112
DtDe & myDe
Definition: DtKeyedData.h:63
virtual ClassToCreate * create(ConstructorArgs &&...constructorArgs)
Create a DtVirtualBaseClassCreator object, calls ClassToCreate constructor with myDe and ConstructorA...
Definition: DtVirtualBaseClassCreator.h:95
This class is used in conjunction with DtKeyedDataManagerTemplate. It represents data associated with...
Definition: DtKeyedData.h:30
UserDataHashTable myUserDataHashTable
Definition: DtKeyedData.h:66
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:22
const std::string myName
Definition: DtKeyedData.h:110
#define DT_DLL_VRVCORE
Definition: vrvCore.h:20
UserDataCreationResult getOrCreateUserData(const void *userPointer, DtVirtualBaseClassCreator< ClassToCreate, ConstructorArgs...> *creator, ConstructorArgs &&...constructorArgs)
get or create the tcs user data
Definition: DtKeyedData.h:74
DtDe & myDe
Definition: DtKeyedData.h:108
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
const std::string myName
Definition: DtKeyedData.h:68
static std::atomic< int > theCount
Definition: DtKeyedData.h:70
tbb::concurrent_hash_map< const void *, DtKeyedDataUserData * > UserDataHashTable
Definition: DtKeyedData.h:65
Contains DLL export macros.

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)