Loading...
Searching...
No Matches
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
11
12#include "pxr/pxr.h"
13#include "pxr/base/tf/type.h"
14
15PXR_NAMESPACE_OPEN_SCOPE
16
17// For use by \c PLUG_REGISTER_INTERFACE_SINGLETON_TYPE.
18class Plug_InterfaceFactory {
19public:
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 {
30 static_assert(std::is_abstract<Interface>::value,
31 "Interface type must be abstract.");
32 static Implementation impl;
33 return static_cast<Interface*>(&impl);
34 }
35 };
36};
37
50#define PLUG_REGISTER_INTERFACE_SINGLETON_TYPE(Interface, Implementation) \
51TF_REGISTRY_FUNCTION(TfType) \
52{ \
53 TfType::Define<Interface>() \
54 .SetFactory<Plug_InterfaceFactory::SingletonFactory< \
55 Interface, Implementation> >(); \
56}
57
58PXR_NAMESPACE_CLOSE_SCOPE
59
60#endif // PXR_BASE_PLUG_INTERFACE_FACTORY_H
Base class of all factory types.
Definition: type.h:56