// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 #pragma once #include namespace frantic { namespace max3d { namespace fpwrapper { template class FFMixinInterface; // Gives the FFMixinInterface class access to the load_descriptor function template class FPInterfaceDescWrapper : public FPInterfaceDesc { friend class FFMixinInterface; }; template class FPInterfaceDescWrapperHolder { FPInterfaceDescWrapper* m_descriptor; public: FPInterfaceDescWrapperHolder() { m_descriptor = 0; } void set( FPInterfaceDescWrapper* descriptor ) { assert( m_descriptor == 0 ); m_descriptor = descriptor; } FPInterfaceDescWrapper* get() const { return m_descriptor; } }; // The main class, deriving from FPMixinInterface template class FFMixinInterface : public FPMixinInterface { FFInterfaceWrapper m_FFInterfaceWrapper; static FPInterfaceDescWrapperHolder m_descriptor; public: // This class accesses the m_FFInterfaceWrapper variable and the function FinalizeFFInterfaceWrapper friend class FFCreateDescriptorImpl; // The MainClass class uses FFCreateDescriptor to generate the descriptor typedef typename FFInterfaceWrapper::FFCreateDescriptor FFCreateDescriptor; FFMixinInterface() {} private: // This is called from the destructor of the FFCreateDescriptor, to finish off creation of the interface void FinalizeFFInterfaceWrapper( FFCreateDescriptor& ffcd ) { if( m_descriptor.get() == 0 ) { make_varargs va; m_FFInterfaceWrapper.make_descriptor_varargs( ffcd, va ); m_descriptor.set( new FPInterfaceDescWrapper() ); // FPStaticInterface is derived from FPInterfaceDesc, which has this function for creating the descriptor m_descriptor.get()->load_descriptor( ffcd.GetInterfaceID(), const_cast( ffcd.GetInterfaceName().c_str() ), 0, ffcd.GetClassDesc(), FP_MIXIN, va.get() ); } } FPStatus _dispatch_fn( FunctionID fid, TimeValue t, FPValue& result, FPParams* p ) { return m_FFInterfaceWrapper._dispatch_fn( static_cast( this ), fid, t, result, p ); } FPInterfaceDesc* GetDesc() { return m_descriptor.get(); } }; template FPInterfaceDescWrapperHolder FFMixinInterface::m_descriptor; } // namespace fpwrapper } // namespace max3d } // namespace frantic