VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtVirtualBaseClassCreator.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (c) 2021 MAK Technologies, Inc.
3  * All rights reserved.
4  ******************************************************************************/
5 
6 #pragma once
7 
8 #include <vrvCore/vrvCore.h>
9 #include <vrvCore/DtDe.h>
11 
12 namespace makVrv
13 {
22  template<class ClassToCreate, class ...ConstructorArgs>
24  {
25  public:
28 
30  DtVirtualBaseClassCreator() = delete;
35 
36  protected:
39 
40  public:
43 
44  public:
46  virtual ClassToCreate* create(ConstructorArgs&&... constructorArgs);
47 
48 
49  protected:
50 
52 
54  static ClassToCreate* classToCreateType;
55 
56  };
57 
58  //Deleted the general case of this function since it must be correctly specialized by the
59  // class that this templated class is creating. For example:
60  //typedef DtVirtualBaseClassCreator<DtDepthOfFieldDrawable> DtDepthOfFieldDrawableCreator;
61  //
63  //template <>
64  //inline const char* creatorTypeName<DtDepthOfFieldDrawable>(void) { return "DtDepthOfFieldDrawableCreator"; }
65  template <typename ClassToCreate>
66  inline const char* creatorTypeName(void) = delete;
67 
68  template<class ClassToCreate, class ...ConstructorArgs>
70  : myDe(de)
71  {
72  // nop
73  }
74 
75  template<class ClassToCreate, class ...ConstructorArgs>
77  {
78  // nop
79  }
80 
81  template<class ClassToCreate, class ...ConstructorArgs>
83  {
84  const std::string creatorType = creatorTypeName<ClassToCreate>();
85 
86  // Fast path: shared-locked lookup, the common case after first registration.
87  DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>* inst =
88  dynamic_cast<DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>*>(
89  de.findInstance(creatorType));
90  if (!inst)
91  {
92  // Cold start: construct OUTSIDE any lock (the ctor is trivial and may
93  // safely re-enter DtDe), then atomically insert-or-discard. If a
94  // competitor won the race, registerInstanceIfAbsent deletes our loser
95  // and returns theirs.
96  inst = dynamic_cast<DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>*>(
98  creatorType,
100  }
101  return *inst;
102  }
103 
104  template<class ClassToCreate, class ...ConstructorArgs>
105  ClassToCreate* DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>::create(ConstructorArgs&&... constructorArgs)
106  {
107  //Perfect forwarding of the ConstructorArgs
108  return new ClassToCreate(myDe, std::forward<ConstructorArgs>(constructorArgs)...);
109  }
110 
111 }
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
DtVirtualBaseClassCreator()=delete
not allowed
static ClassToCreate * classToCreateType
Should only be used by decltype() calls to get the type of the base class being created.
Definition: DtVirtualBaseClassCreator.h:54
const char * creatorTypeName(void)=delete
static DtVirtualBaseClassCreator & instance(DtDe &de)
Get an instance of the creator, if it does not exist then register it with DtDe.
Definition: DtVirtualBaseClassCreator.h:82
Contains makVrv::DtDe class.
virtual ClassToCreate * create(ConstructorArgs &&...constructorArgs)
Create a DtVirtualBaseClassCreator object, calls ClassToCreate constructor with myDe and ConstructorA...
Definition: DtVirtualBaseClassCreator.h:105
virtual DtVirtualBaseClass * findInstance(const std::string &instanceName) const
Find an instance with the given name. If no instance is found than a null pointer is returned...
DtDe & myDe
Definition: DtVirtualBaseClassCreator.h:51
DtVirtualBaseClassCreator & operator=(const DtVirtualBaseClassCreator &other)=delete
Assignment Operator Not implemented – Assignment Not Allowed.
virtual DtVirtualBaseClass * registerInstanceIfAbsent(const std::string &instanceName, DtVirtualBaseClass *instance)
Atomically register instance under instanceName only if no instance is already registered under that ...
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:23
Contains makVrv::DtVirtualBaseClass class.
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:76
virtual ~DtVirtualBaseClassCreator()
DTOR.
Definition: DtVirtualBaseClassCreator.h:76
Contains DLL export macros.

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)