VR-Forces 4.10 Class Documentation
 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>
10 
11 namespace makVrv
12 {
21  template<class ClassToCreate, class ...ConstructorArgs>
23  {
24  public:
27 
29  DtVirtualBaseClassCreator() = delete;
34 
35  protected:
38 
39  public:
42 
43  public:
45  virtual ClassToCreate* create(ConstructorArgs&&... constructorArgs);
46 
47 
48  protected:
49 
51 
53  static ClassToCreate* classToCreateType;
54 
55  };
56 
57  //Deleted the general case of this function since it must be correctly specialized by the
58  // class that this templated class is creating. For example:
59  //typedef DtVirtualBaseClassCreator<DtDepthOfFieldDrawable> DtDepthOfFieldDrawableCreator;
60  //
62  //template <>
63  //inline const char* creatorTypeName<DtDepthOfFieldDrawable>(void) { return "DtDepthOfFieldDrawableCreator"; }
64  template <typename ClassToCreate>
65  inline const char* creatorTypeName(void) = delete;
66 
67  template<class ClassToCreate, class ...ConstructorArgs>
69  : myDe(de)
70  {
71  // nop
72  }
73 
74  template<class ClassToCreate, class ...ConstructorArgs>
76  {
77  // nop
78  }
79 
80  template<class ClassToCreate, class ...ConstructorArgs>
82  {
83  std::string creatorType = creatorTypeName<ClassToCreate>();
84  DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>* inst = dynamic_cast<DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>*>(
85  de.findInstance(creatorType));
86  if (!inst)
87  {
88  inst = new DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>(de);
89  de.registerInstance(creatorType, inst);
90  }
91  return *inst;
92  }
93 
94  template<class ClassToCreate, class ...ConstructorArgs>
95  ClassToCreate* DtVirtualBaseClassCreator<ClassToCreate, ConstructorArgs...>::create(ConstructorArgs&&... constructorArgs)
96  {
97  //Perfect forwarding of the ConstructorArgs
98  return new ClassToCreate(myDe, std::forward<ConstructorArgs>(constructorArgs)...);
99  }
100 
101 }
Virtual base class.
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:53
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:81
Contains makVrv::DtDe class.
virtual ClassToCreate * create(ConstructorArgs &&...constructorArgs)
Create a DtVirtualBaseClassCreator object, calls ClassToCreate constructor with myDe and ConstructorA...
Definition: DtVirtualBaseClassCreator.h:95
virtual DtVirtualBaseClass * findInstance(const std::string &instanceName) const
Find an instance with the given name.
DtDe & myDe
Definition: DtVirtualBaseClassCreator.h:50
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:22
virtual void registerInstance(const std::string &instanceName, DtVirtualBaseClass *instance)
Register an instance with a given name for later retrieval.
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
virtual ~DtVirtualBaseClassCreator()
DTOR.
Definition: DtVirtualBaseClassCreator.h:75
Contains DLL export macros.

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)