[C++/CLI]Nativeの構造体をラッピングする③
ツリー構造体のラッピング(構造体の中に構造体を含む)
※たぶんやり方はもっとスマートなのはあるはず。
/*
*Native(C言語)での構造体定義
*/
typedef struct tagTEST1
{
int i;
} TEST1;
typedef struct tagTEST2
{
unsigned char b;
} TEST2;
typedef struct tagTEST3
{
TEST1 t1;
TEST2 t2[4];
} TEST3;
/*
*C++/CLIでのラッピング
*/
public ref class M_TEST1
{
private:
TEST1 *st;
internal:
M_TEST1(TEST1 *st1)
{
st = st1;
}
~M_TEST1()
{
if (st != NULL)
{
delete st;
st = NULL;
}
}
public:
property int Member
{
int get() { return st->i; }
void set(int value) { st->i = value; }
}
};
public ref calss M_TEST2
{
private:
TEST2 *st;
internal:
M_TEST2(TEST2 *st2)
{
st = st2;
}
~M_TEST2()
{
if (st != NULL)
{
delete st;
st = NULL;
}
}
public:
property System::Byte Member
{
System::Byte get() { return st->b; }
void set(System::Byte value) { st->b = value; }
}
};
public ref class M_TEST3
{
private:
TEST3 *st;
M_TEST1^ m_t1;
array<M_TEST2^>^ m_t2;
public:
M_TEST3()
{
st = new TEST3()
m_t1 = gcnew M_TEST1(&st->t1);
m_t2 = gcnew array<M_TEST2^>(4);
for (int i = 0; i < 4; i++)
{
m_t2[i] = gcnew M_TEST2(&st->t2[i]);
}
}
~M_TEST3()
{
// 同じ
}
property M_TEST1^ mt1
{
M_TEST1^ get() { return m_t1; }
void set(M_TEST1^ value) { m_t1 = value; }
}
property array<M_TEST2^>^ mt2
{
array<M_TEST2^>^ get() { return m_t2; }
void set(array<M_TEST2^>^ value) { m_t2 = value; }
}
};
※たぶんやり方はもっとスマートなのはあるはず。
/*
*Native(C言語)での構造体定義
*/
typedef struct tagTEST1
{
int i;
} TEST1;
typedef struct tagTEST2
{
unsigned char b;
} TEST2;
typedef struct tagTEST3
{
TEST1 t1;
TEST2 t2[4];
} TEST3;
/*
*C++/CLIでのラッピング
*/
public ref class M_TEST1
{
private:
TEST1 *st;
internal:
M_TEST1(TEST1 *st1)
{
st = st1;
}
~M_TEST1()
{
if (st != NULL)
{
delete st;
st = NULL;
}
}
public:
property int Member
{
int get() { return st->i; }
void set(int value) { st->i = value; }
}
};
public ref calss M_TEST2
{
private:
TEST2 *st;
internal:
M_TEST2(TEST2 *st2)
{
st = st2;
}
~M_TEST2()
{
if (st != NULL)
{
delete st;
st = NULL;
}
}
public:
property System::Byte Member
{
System::Byte get() { return st->b; }
void set(System::Byte value) { st->b = value; }
}
};
public ref class M_TEST3
{
private:
TEST3 *st;
M_TEST1^ m_t1;
array<M_TEST2^>^ m_t2;
public:
M_TEST3()
{
st = new TEST3()
m_t1 = gcnew M_TEST1(&st->t1);
m_t2 = gcnew array<M_TEST2^>(4);
for (int i = 0; i < 4; i++)
{
m_t2[i] = gcnew M_TEST2(&st->t2[i]);
}
}
~M_TEST3()
{
// 同じ
}
property M_TEST1^ mt1
{
M_TEST1^ get() { return m_t1; }
void set(M_TEST1^ value) { m_t1 = value; }
}
property array<M_TEST2^>^ mt2
{
array<M_TEST2^>^ get() { return m_t2; }
void set(array<M_TEST2^>^ value) { m_t2 = value; }
}
};