How to use Handle in a managed ref class

mach22's picture

Hi, I need to have a reference to an Handle in a managed ref class and set it from a derived class, with a derived Handle type. with an old OCC version I could do this as shown in the sample code below.
Now how it's possible to do this with the new implementation of Handle ?

public ref class MyBaseClass
{
protected:
Handle(Standard_Transient)* _handle;

public:
MyBaseClass() {}

MyBaseClass(const Handle(Standard_Transient)& handle)
{
_handle = new Handle_Standard_Transient(handle);
}
}

public ref class MyDerivedClass : public MyBaseClass
{
public:
MyDerivedClass(const Handle(Standard_Type)& handle) : MyBaseClass()
{
_handle = new Handle_Standard_Type(handle);
}
}

abv's picture

Use NCollection_Haft

Hello,

Consider using NCollection_Haft class. This should do the job:

#include <NCollection_Haft.h>

public ref class MyBaseClass
{
protected:
NCollection_Haft<Handle(Standard_Transient)> _handle;

public:
MyBaseClass() {}

MyBaseClass(const Handle(Standard_Transient)& handle)
{
_handle() = handle;
}
}

public ref class MyDerivedClass : public MyBaseClass
{
public:
MyDerivedClass(const Handle(Standard_Type)& handle) : MyBaseClass()
{
_handle() = handle;
}
}

www.opencascade.com

Copyright 2011-2017
OPEN CASCADE SAS
Contact us