24 #ifndef PXR_BASE_PLUG_STATIC_INTERFACE_H 25 #define PXR_BASE_PLUG_STATIC_INTERFACE_H 30 #include "pxr/base/plug/api.h" 33 #include <type_traits> 36 PXR_NAMESPACE_OPEN_SCOPE
39 class Plug_StaticInterfaceBase {
44 bool IsInitialized()
const 50 typedef void* Plug_StaticInterfaceBase::*UnspecifiedBoolType;
55 void _LoadAndInstantiate(
const std::type_info& type)
const;
59 mutable std::atomic<bool> _initialized;
159 template <
class Interface>
162 static_assert(std::is_abstract<Interface>::value,
163 "Interface type must be abstract.");
167 using Plug_StaticInterfaceBase::IsInitialized;
171 operator UnspecifiedBoolType()
const 173 return _GetPtr() ? &This::_ptr :
nullptr;
206 Interface* _GetPtr()
const 209 _LoadAndInstantiate(
typeid(Interface));
214 return static_cast<Interface*>(_ptr);
218 PXR_NAMESPACE_CLOSE_SCOPE
220 #endif // PXR_BASE_PLUG_STATIC_INTERFACE_H 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.
Interface * Get() const
Returns the interface pointer, loading the plugin if necessary.
Provides access to an interface into a plugin.