// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 #pragma once namespace frantic { namespace max3d { namespace fpwrapper { class ArrayRefClass : public ValueMetaClass { public: ArrayRefClass( MCHAR* name ) : ValueMetaClass( name ) {} void collect() { delete this; } }; extern ArrayRefClass ArrayRef_class; class ArrayRef : public Value { void* m_tabPtr; int m_tabCount; Value* ( *m_get )( void*, int ); // The get function knows the correct type of the data void ( *m_set )( void*, int, Value* ); // The set function knows the correct type of the data public: template ArrayRef( Tab& t ); template ArrayRef( std::vector& t ); template ArrayRef( T* pData, int count ); #pragma warning( push ) // mute unreferenced formal param warnings from the MAX macro #pragma warning( disable : 4100 ) classof_methods( ArrayRef, Value ); #pragma warning( pop ) ValueMetaClass* local_base_class() { return &ArrayRef_class; } void collect() { delete this; } void sprin1( CharStream* s ); Value* get_count( Value** arg_list, int count ); Value* get_vf( Value** arg_list, int count ); Value* put_vf( Value** arg_list, int count ); }; template struct ArrayRefImpl { static Value* get( void* pData, int index ) { return max_traits::to_value( *( static_cast( pData ) + index ) ); } static void set( void* pData, int index, Value* v ) { *( static_cast( pData ) + index ) = max_traits::from_value( v ); } }; template ArrayRef::ArrayRef( Tab& t ) { m_tabPtr = t.Addr( 0 ); m_tabCount = t.Count(); m_get = &ArrayRefImpl::get; m_set = &ArrayRefImpl::set; } template ArrayRef::ArrayRef( std::vector& v ) { m_tabPtr = &v[0]; m_tabCount = static_cast( v.size() ); m_get = &ArrayRefImpl::get; m_set = &ArrayRefImpl::set; } template ArrayRef::ArrayRef( T* pData, int count ) { m_tabPtr = pData; m_tabCount = count; m_get = &ArrayRefImpl::get; m_set = &ArrayRefImpl::set; } } // namespace fpwrapper } // namespace max3d } // namespace frantic