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  std::string creatorType = creatorTypeName<ClassToCreate>();
85  DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>* inst = dynamic_cast<DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>*>(
86  de.findInstance(creatorType));
87  if (!inst)
88  {
89  inst = new DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>(de);
90  de.registerInstance(creatorType, inst);
91  }
92  return *inst;
93  }
94 
95  template<class ClassToCreate, class ...ConstructorArgs>
96  ClassToCreate* DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>::create(ConstructorArgs&&... constructorArgs)
97  {
98  //Perfect forwarding of the ConstructorArgs
99  return new ClassToCreate(myDe, std::forward<ConstructorArgs>(constructorArgs)...);
100  }
101 
102 }
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:96
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.
Variadic templated creator class for defining a DtVirtualBaseClass creator that is automatically regi...
Definition: DtVirtualBaseClassCreator.h:23
Contains makVrv::DtVirtualBaseClass class.
virtual void registerInstance(const std::string &instanceName, DtVirtualBaseClass *instance)
Register an instance with a given name for later retrieval. Once registered, the DtDe takes ownership...
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 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)