Created
November 11, 2019 10:33
-
-
Save taipoxin/6771b9372af6c00f7eee3896638b39d8 to your computer and use it in GitHub Desktop.
Wrapper main files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Entity.h" | |
namespace CLI | |
{ | |
Entity::Entity(String^ name, float xPos, float yPos) | |
: ManagedObject(new Core::Entity(string_to_char_array(name), xPos, yPos)) | |
{ | |
Console::WriteLine("Creating a new Entity-wrapper object!"); | |
} | |
void Entity::Move(float deltaX, float deltaY) | |
{ | |
Console::WriteLine("The Move method from the Wrapper was called!"); | |
m_Instance->Move(deltaX, deltaY); | |
} | |
void Entity::test() | |
{ | |
Console::WriteLine("The test method from the Wrapper was called!"); | |
m_Instance->test(); | |
} | |
String^ Entity::getName() { | |
return char_array_to_string(m_Instance->GETNAME()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include "ManagedObject.h" | |
#include "../test_2_aaa/Core.h" | |
using namespace System; | |
namespace CLI | |
{ | |
public ref class Entity : public ManagedObject<Core::Entity> | |
{ | |
public: | |
Entity(String^ name, float xPos, float yPos); | |
void Move(float deltaX, float deltaY); | |
void test(); | |
String^ getName(); | |
property float XPosition | |
{ | |
public: | |
float get() | |
{ | |
return m_Instance->GetXPosition(); | |
} | |
private: | |
void set(float value) | |
{} | |
} | |
property float YPosition | |
{ | |
public: | |
float get() | |
{ | |
return m_Instance->GetYPosition(); | |
} | |
private: | |
void set(float value) | |
{} | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
using namespace System; | |
namespace CLI { | |
using namespace System::Runtime::InteropServices; | |
static const char* string_to_char_array(String^ string) | |
{ | |
const char* str = (const char*)(Marshal::StringToHGlobalAnsi(string)).ToPointer(); | |
return str; | |
} | |
static String^ char_array_to_string(const char* str) | |
{ | |
String^ res = Marshal::PtrToStringAnsi((IntPtr)(char *)str); | |
return res; | |
} | |
template<class T> | |
public ref class ManagedObject | |
{ | |
protected: | |
T* m_Instance; | |
public: | |
ManagedObject(T* instance) | |
: m_Instance(instance) | |
{ | |
} | |
virtual ~ManagedObject() | |
{ | |
if (m_Instance != nullptr) | |
{ | |
delete m_Instance; | |
} | |
} | |
!ManagedObject() | |
{ | |
if (m_Instance != nullptr) | |
{ | |
delete m_Instance; | |
} | |
} | |
T* GetInstance() | |
{ | |
return m_Instance; | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment