HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
interfaceFactory.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_PLUG_INTERFACE_FACTORY_H
8 #define PXR_BASE_PLUG_INTERFACE_FACTORY_H
9 
10 /// \file plug/interfaceFactory.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/base/tf/type.h"
14 
16 
17 // For use by \c PLUG_REGISTER_INTERFACE_SINGLETON_TYPE.
19 public:
20  struct Base : public TfType::FactoryBase {
21  public:
22  virtual void* New() = 0;
23  };
24 
25  template <class Interface, class Implementation>
26  struct SingletonFactory : public Base {
27  public:
28  virtual void* New()
29  {
31  "Interface type must be abstract.");
32  static Implementation impl;
33  return static_cast<Interface*>(&impl);
34  }
35  };
36 };
37 
38 /// Defines the \c Interface \c TfType with a factory to return a
39 /// \c Implementation singleton. This is suitable for use with
40 /// \c PlugStaticInterface. \p Interface must be abstract and
41 /// \p Implementation a concrete subclass of \p Interface. Note
42 /// that this is a factory on \c Interface \b not \c Implementation.
43 ///
44 /// The result of the factory is a singleton instance of \c Implementation
45 /// and the client of TfType::GetFactory() must not destroy it.
46 ///
47 /// Clients that want to create instances of types defined in a plugin
48 /// but not added to the TfType system should create a singleton with
49 /// factory methods to create those objects.
50 #define PLUG_REGISTER_INTERFACE_SINGLETON_TYPE(Interface, Implementation) \
51 TF_REGISTRY_FUNCTION(TfType) \
52 { \
53  TfType::Define<Interface>() \
54  .SetFactory<Plug_InterfaceFactory::SingletonFactory< \
55  Interface, Implementation> >(); \
56 }
57 
59 
60 #endif // PXR_BASE_PLUG_INTERFACE_FACTORY_H
GLsizei const GLfloat * value
Definition: glcorearb.h:824
Base class of all factory types.
Definition: type.h:56
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual void * New()=0