Added CElement::GetParent.

Creating the GC Handler for new elements.
This commit is contained in:
Kernell 2016-01-07 20:47:23 +03:00
parent 399d7fd307
commit 27e2ee61f7
2 changed files with 26 additions and 0 deletions

View File

@ -45,6 +45,8 @@ CElement::CElement( CElementManager* pManager, MonoObject* pObject, PVOID pUserd
this->m_iType = eElementType::Unknown; this->m_iType = eElementType::Unknown;
this->m_uiGCHandle = mono_gchandle_new( pObject, true );
this->m_pElementManager->AddToList( this ); this->m_pElementManager->AddToList( this );
} }
@ -52,6 +54,13 @@ CElement::~CElement( void )
{ {
this->m_pElementManager->RemoveFromList( this ); this->m_pElementManager->RemoveFromList( this );
if( this->m_uiGCHandle )
{
mono_gchandle_free( this->m_uiGCHandle );
this->m_uiGCHandle = 0;
}
this->m_pMonoObject = nullptr; this->m_pMonoObject = nullptr;
this->m_pLuaUserdata = nullptr; this->m_pLuaUserdata = nullptr;
this->m_pParent = nullptr; this->m_pParent = nullptr;
@ -67,3 +76,15 @@ const string CElement::GetTypeName( void )
{ {
return CElement::GetTypeName( this->m_iType ); return CElement::GetTypeName( this->m_iType );
} }
CElement* CElement::GetParent( void ) const
{
MonoObject* pMonoObject = CMonoFunctions::Element::GetParent( this->ToMonoObject() );
if( pMonoObject )
{
return this->m_pElementManager->GetFromList( pMonoObject );
}
return nullptr;
}

View File

@ -17,6 +17,7 @@ class CElement;
#include "CResource.h" #include "CResource.h"
#include "CElementManager.h" #include "CElementManager.h"
#include "CMonoFunctions.h"
enum class eElementType enum class eElementType
{ {
@ -110,6 +111,8 @@ private:
eElementType m_iType; eElementType m_iType;
uint32_t m_uiGCHandle;
public: public:
CElement ( CElementManager* pManager, MonoObject* pObject, PVOID pUserdata, const CResource* pParent = nullptr ); CElement ( CElementManager* pManager, MonoObject* pObject, PVOID pUserdata, const CResource* pParent = nullptr );
virtual ~CElement ( void ); virtual ~CElement ( void );
@ -119,6 +122,8 @@ public:
void SetTypeName ( const string& strTypeName ); void SetTypeName ( const string& strTypeName );
const string GetTypeName ( void ); const string GetTypeName ( void );
CElement* GetParent ( void ) const;
inline MonoObject* ToMonoObject ( void ) const { return this->m_pMonoObject; } inline MonoObject* ToMonoObject ( void ) const { return this->m_pMonoObject; }
inline PVOID ToLuaUserData ( void ) const { return this->m_pLuaUserdata; } inline PVOID ToLuaUserData ( void ) const { return this->m_pLuaUserdata; }
}; };