How to define a handled object without CDL

You can create a class manipulated by handle even if you do not use CDL (Open CASCADE Definition Language). To do that you have to use the Define_Standard_Handle macro which is defined in the include file Standard_DefineHandle.hxx.

 

Here is an example which shows how to define a class SamplePoint manipulated by handle.

 

Sample_Point.hxx:

 

  #ifndef _Sample_Point_HeaderFile

  #define _Sample_Point_HeaderFile

  #ifndef _Standard_Macro_HeaderFile

  #include <Standard_Macro.hxx>

  #endif

  #include <MMgt_TShared.hxx>

  #include <Standard_DefineHandle.hxx>

  // Handle definition

  //

  DEFINE_STANDARD_HANDLE(Sample_Point,MMgt_TShared)

  class Sample_Point: public MMgt_TShared {

  public:

  Sample_Point();

  Sample_Point(const Standard_Real, const

  Standard_Real);

  void SetX(const Standard_Real x) {

  myX = x;

  }

  void SetY(const Standard_Real y) {

  myY = y;

  }

  Standard_Real X() const {

  return myX;

  }

  Standard_Real Y() const {

  return myY;

  }

  // some methods like DynamicType() or

  IsKind()

  //

  DEFINE_STANDARD_RTTI(Sample_Point)

  private:

  Standard_Real myX;

  Standard_Real myY;

  };

  #endif

 

Sample_Point.cxx:

 

  #include <Sample_Point.hxx>

  // Implementation of Handle and type mgt

  //

  IMPLEMENT_STANDARD_HANDLE(Sample_Point,MMgt_TShared)

  IMPLEMENT_STANDARD_RTTI(Sample_Point,MMgt_TShared)

  //

  // Foreach ancestors, we add a

  IMPLEMENT_STANDARD_SUPERTYPE and

  // a IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY

  macro.

  // We must respect the order: from the direct ancestor class

  // to the base class.

  //

 

  IMPLEMENT_STANDARD_TYPE(Sample_Point)

  IMPLEMENT_STANDARD_SUPERTYPE(MMgt_TShared)

  IMPLEMENT_STANDARD_SUPERTYPE(Standard_Transient)

  IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()

  IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(MMgt_TShared)

  IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_ENTRY(Standard_Transient)

  IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()

  IMPLEMENT_STANDARD_TYPE_END(Sample_Point)

 // Constructors implementation

  //

  Sample_Point::Sample_Point(const

  Standard_Real x, const Standard_Real y)

 

  {

  myX = x;

  myY = y;

  }

 

  Sample_Point::Sample_Point()

 

  {

  myX = 0.0;

  myY = 0.0;

  }