7#ifndef PXR_BASE_PLUG_STATIC_INTERFACE_H
8#define PXR_BASE_PLUG_STATIC_INTERFACE_H
13#include "pxr/base/plug/api.h"
19PXR_NAMESPACE_OPEN_SCOPE
22class Plug_StaticInterfaceBase {
27 bool IsInitialized()
const
33 typedef void* Plug_StaticInterfaceBase::*UnspecifiedBoolType;
38 void _LoadAndInstantiate(
const std::type_info& type)
const;
42 mutable std::atomic<bool> _initialized;
142template <
class Interface>
145 static_assert(std::is_abstract<Interface>::value,
146 "Interface type must be abstract.");
150 using Plug_StaticInterfaceBase::IsInitialized;
154 operator UnspecifiedBoolType()
const
156 return _GetPtr() ? &This::_ptr :
nullptr;
189 Interface* _GetPtr()
const
192 _LoadAndInstantiate(
typeid(Interface));
197 return static_cast<Interface*
>(_ptr);
201PXR_NAMESPACE_CLOSE_SCOPE
Provides access to an interface into a plugin.
Interface * Get() const
Returns the interface pointer, loading the plugin if necessary.
bool operator!() const
Load and instantiate then return false if the interface is valid, true otherwise.
Interface & operator*() const
Returns the interface pointer as a reference, loading the plugin if necessary.
Interface * operator->() const
Returns the interface pointer, loading the plugin if necessary.