MantisBT
Mantis Bug Tracker Workflow

View Revisions: Issue #26397 All Revisions ] Back to Issue ]
Summary 0026397: Change method DownCast() of Handle to return a pointer rather than a Handle
Revision 2017-10-09 13:39 by abv
Description Method DownCast() of opencascade::handle<> can be changed to return a pointer instead of constructing a new handle. The benefits would be:

- No overhead for incrementing / decrementing reference counter if result of DownCast() is used to access the object directly

- Possible more efficient code when new Handle() is initialized by result of DownCast()

- Safer code -- compiler may complain if result of DownCast() is assigned to reference to a handle

- Possibility to avoid double type checking in expressions like this:

if (myCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))
{
  Handle(Geom_BSplineCurve) aBSplCurve = Handle(Geom_BSplineCurve)::DownCast (myCurve);
  ... // work with bspline
}

this can be replaced by more compact and faster variant:

if (const Geom_BSplineCurve* aBSplCurve = Handle(Geom_BSplineCurve)::DownCast (myCurve))
{
  ... // work with bspline
}

One drawback of returning a pointer is that it will break compatibility with existing code which now can use method IsNull() to the result of DownCast() to check if the value is of a goo type. Such checks however should be better replaced by equivalent check of IsNull() of original object followed by IsKind().
Revision 2015-07-03 10:37 by abv
Description Method DownCast() of opencascade::handle<> can be changed to return a pointer instead of constructing a new handle. The benefits would be:

- No overhead for incrementing / decrementing reference counter if result of DownCast() is used to access the object directly

- Possible more efficient code when new Handle() is initialized by result of DownCast()

- Safer code -- compiler will complain if result of DownCast() is assigned to something

- Possibility to avoid double type checking in expressions like this:

if (myCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))
{
  Handle(Geom_BSplineCurve) aBSplCurve = Handle(Geom_BSplineCurve)::DownCast (myCurve);
  ... // work with bspline
}

this can be replaced by more compact and faster variant:

if (const Geom_BSplineCurve* aBSplCurve = Handle(Geom_BSplineCurve)::DownCast (myCurve))
{
  ... // work with bspline
}


Copyright © 2000 - 2021 MantisBT Team
Powered by Mantis Bugtracker