diff --git a/mta-mono/src/CMonoArguments.cpp b/mta-mono/src/CMonoArguments.cpp new file mode 100644 index 0000000..0bc415c --- /dev/null +++ b/mta-mono/src/CMonoArguments.cpp @@ -0,0 +1,85 @@ +/********************************************************* +* +* Copyright © 2013, Innovation Roleplay Engine. +* +* All Rights Reserved. +* +* Redistribution and use in source and binary forms, +* with or without modification, +* is permitted only for authors. +* +*********************************************************/ + +#include "StdInc.h" +#include "CMonoArguments.h" + +CMonoArguments::CMonoArguments( void ) +{ + this->m_pTmpArgs = nullptr; +} + +CMonoArguments::~CMonoArguments( void ) +{ + for( auto iter : this->m_pArgs ) + { + if( iter.second ) + { + delete iter.first; + } + } + + this->m_pArgs.clear(); + + if( this->m_pTmpArgs ) + { + delete [] this->m_pTmpArgs; + } +} + +bool CMonoArguments::Push( MonoString* pString ) +{ + this->m_pArgs.push_back( make_pair( pString, false ) ); + + return true; +} + +bool CMonoArguments::Push( MonoObject* pObject ) +{ + this->m_pArgs.push_back( make_pair( pObject, false ) ); + + return true; +} + +PVOID* CMonoArguments::GetArgs( void ) +{ + if( this->m_pTmpArgs == nullptr ) + { + this->m_pTmpArgs = new PVOID[ this->Length() ]; + + uint i = 0; + + for( const auto& iter : this->m_pArgs ) + { + this->m_pTmpArgs[ i++ ] = iter.first; + } + } + + return this->m_pTmpArgs; +} + +const size_t CMonoArguments::Length( void ) const +{ + return this->m_pArgs.size(); +} + +PVOID CMonoArguments::operator[]( int index ) +{ + ASSERT( index < this->Length() ); + + return this->GetArgs()[ index ]; +} + +PVOID* CMonoArguments::operator*( void ) +{ + return this->GetArgs(); +} diff --git a/mta-mono/src/CMonoArguments.h b/mta-mono/src/CMonoArguments.h new file mode 100644 index 0000000..09a3d82 --- /dev/null +++ b/mta-mono/src/CMonoArguments.h @@ -0,0 +1,50 @@ +/********************************************************* +* +* Copyright © 2013, Innovation Roleplay Engine. +* +* All Rights Reserved. +* +* Redistribution and use in source and binary forms, +* with or without modification, +* is permitted only for authors. +* +*********************************************************/ + +class CMonoArguments; + +#ifndef __CMONOARGUMENTS_H +#define __CMONOARGUMENTS_H + +class CMonoArguments +{ +private: + PVOID* m_pTmpArgs; + vector< pair< PVOID, bool > > m_pArgs; + +public: + CMonoArguments ( void ); + ~CMonoArguments ( void ); + + template< typename Type > + bool Push ( Type Value ) + { + Type* pValue = new Type; + + *pValue = Value; + + this->m_pArgs.push_back( make_pair( pValue, true ) ); + + return true; + } + + bool Push ( MonoString* pString ); + bool Push ( MonoObject* pObject ); + + PVOID* GetArgs ( void ); + const size_t Length ( void ) const; + + PVOID operator[] ( int index ); + PVOID* operator* ( void ); +}; + +#endif