1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- manual

Restored possibility to have out-of-line implementation of DynamicCast() and STANDART_TYPE():
- Macro STANDARD_TYPE() now resolves to function get_type_descriptor() of the class
- Macro DEFINE_STANDARD_RTTI is replaced by two variants:
  - DEFINE_STANDARD_RTTI_INLINE works as before, defining DynamicCast() and get_type_descriptor() as inline functions
  - DEFINE_STANDARD_RTTIEXT declares DynamicCast() and get_type_descriptor() as exported
- Macro IMPLEMENT_STANDARD_RTTIEXT provides definition of DynamicCast() and get_type_descriptor() for a class

Upgrade script amended to replace DEFINE_STANDARD_RTTI by pair of DEFINE_STANDARD_RTTIEXT / IMPLEMENT_STANDARD_RTTIEXT if source file with the same name as header is found in the same folder, and by DEFINE_STANDARD_RTTI_INLINE if either source is not found or class is defined in the source (i.e. not in header)

Upgrade tool improved to recognize include statements with path prefix, like #include <occt/gp_Pnt.hxx>
Code corrected to eliminate warnings reported by upgrade tool.
Template of CXX file for testing upgrade tool added.

Documentation of upgrade procedure updated.
This commit is contained in:
abv
2015-11-30 07:49:48 +03:00
parent 6595eee796
commit f5f4ebd07b
23 changed files with 277 additions and 76 deletions

View File

@@ -158,7 +158,7 @@ protected:
public:
DEFINE_STANDARD_RTTI(Cocoa_Window, Aspect_Window)
DEFINE_STANDARD_RTTIEXT(Cocoa_Window,Aspect_Window)
};

View File

@@ -29,6 +29,8 @@
#include <Aspect_Convert.hxx>
#include <Aspect_WindowDefinitionError.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Cocoa_Window,Aspect_Window)
#if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
//
#else

View File

@@ -43,6 +43,7 @@
#include <Standard_RangeError.hxx>
#include <Standard_Type.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Geom_OffsetCurve,Geom_Curve)
static const Standard_Real MyAngularToleranceForG1 = Precision::Angular();

View File

@@ -41,6 +41,7 @@
#include <Standard_RangeError.hxx>
#include <Standard_Type.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Geom2d_OffsetCurve,Geom2d_Curve)
static const Standard_Real MyAngularToleranceForG1 = Precision::Angular();

View File

@@ -31,6 +31,8 @@
#include <fstream>
#include <algorithm>
IMPLEMENT_STANDARD_RTTIEXT(Image_AlienPixMap,Image_PixMap)
#ifdef HAVE_FREEIMAGE
namespace
{

View File

@@ -14,23 +14,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifdef DRAW
#include <Draw_Appli.hxx>
#include <DrawTrSurf_Curve2d.hxx>
#include <Draw_Marker2D.hxx>
#endif
#ifdef OCCT_DEBUG
#include <GCE2d_MakeSegment.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_Parabola.hxx>
#include <Geom2d_Hyperbola.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2d_Circle.hxx>
#endif
#include <Adaptor2d_OffsetCurve.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <Geom2d_Geometry.hxx>
@@ -53,7 +36,23 @@
#include <TColStd_Array1OfInteger.hxx>
#include <TColStd_SequenceOfInteger.hxx>
IMPLEMENT_STANDARD_RTTIEXT(MAT2d_Circuit,MMgt_TShared)
#ifdef OCCT_DEBUG
#include <GCE2d_MakeSegment.hxx>
#include <Geom2d_Curve.hxx>
#include <Geom2d_Parabola.hxx>
#include <Geom2d_Hyperbola.hxx>
#include <Geom2d_TrimmedCurve.hxx>
#include <Geom2d_CartesianPoint.hxx>
#include <Geom2d_Line.hxx>
#include <Geom2d_Circle.hxx>
#endif
#ifdef DRAW
#include <Draw_Appli.hxx>
#include <DrawTrSurf_Curve2d.hxx>
#include <Draw_Marker2D.hxx>
static Handle(DrawTrSurf_Curve2d) draw;
Standard_EXPORT Draw_Viewer dout;
#endif

View File

@@ -37,6 +37,8 @@
#include <Standard_ProgramError.hxx>
IMPLEMENT_STANDARD_RTTIEXT(OpenGl_Context,Standard_Transient)
#if defined(HAVE_EGL)
#include <EGL/egl.h>
#ifdef _MSC_VER

View File

@@ -240,7 +240,7 @@ public:
virtual const char* Name() const { return "Transient_Root"; }
virtual Standard_Transient* CreateParent() const { return new Standard_Transient; }
virtual Standard_Transient* Clone() const { return new Transient_Root; }
DEFINE_STANDARD_RTTI(Transient_Root, Standard_Transient)
DEFINE_STANDARD_RTTI_INLINE(Transient_Root,Standard_Transient)
};
DEFINE_STANDARD_HANDLE(Transient_Root, Standard_Transient)
@@ -252,11 +252,9 @@ public:\
virtual const char* Name() const Standard_OVERRIDE { return #theClass; } \
virtual Standard_Transient* CreateParent() const Standard_OVERRIDE { return new theParent(); } \
virtual Standard_Transient* Clone() const Standard_OVERRIDE { return new theClass(); } \
DEFINE_STANDARD_RTTI(theClass, theParent) \
DEFINE_STANDARD_RTTI_INLINE(theClass,theParent) \
};\
DEFINE_STANDARD_HANDLE (theClass, theParent) \
IMPLEMENT_STANDARD_HANDLE (theClass, theParent) \
IMPLEMENT_STANDARD_RTTIEXT(theClass, theParent)
DEFINE_STANDARD_HANDLE (theClass, theParent)
#define QA_NAME(theNum) qaclass ## theNum ## _ ## 50
#define QA_HANDLE_NAME(theNum) Handle(qaclass ## theNum ## _ ## 50)

View File

@@ -36,6 +36,5 @@ class Standard_Type;
#define IMPLEMENT_STANDARD_SUPERTYPE_ARRAY()
#define IMPLEMENT_STANDARD_SUPERTYPE_ARRAY_END()
#define IMPLEMENT_STANDARD_TYPE_END(C1)
#define IMPLEMENT_STANDARD_RTTIEXT(C1,C2)
#endif

View File

@@ -23,11 +23,16 @@ void Standard_Transient::Delete() const
delete this;
}
const Handle(Standard_Type)& Standard_Transient::get_type_descriptor ()
{
return opencascade::type_instance<Standard_Transient>::get();
}
//
//
const Handle(Standard_Type)& Standard_Transient::DynamicType() const
{
return opencascade::type_instance<Standard_Transient>::get();
return get_type_descriptor();
}
//

View File

@@ -58,7 +58,10 @@ public:
static const char* get_type_name () { return "Standard_Transient"; }
//! Returns a type information object about this object.
//! Returns type descriptor of Standard_Transient class
Standard_EXPORT static const opencascade::handle<Standard_Type>& get_type_descriptor ();
//! Returns a type descriptor about this object.
Standard_EXPORT virtual const opencascade::handle<Standard_Type>& DynamicType() const;
//! Returns a true value if this is an instance of Type.

View File

@@ -19,6 +19,8 @@
#include <NCollection_DataMap.hxx>
IMPLEMENT_STANDARD_RTTIEXT(Standard_Type,Standard_Transient)
//============================================================================
Standard_Boolean Standard_Type::SubType (const Handle(Standard_Type)& theOther) const

View File

@@ -23,17 +23,37 @@
#include <typeinfo>
//! Helper macro to get instance of a type descriptor for a class in a legacy way.
#define STANDARD_TYPE(theType) Standard_Type::Instance<theType>()
#define STANDARD_TYPE(theType) theType::get_type_descriptor()
//! Helper macro to be included in definition of the classes inheriting
//! Standard_Transient to enable use of OCCT RTTI and smart pointers (handles).
#define DEFINE_STANDARD_RTTI(Class,Base) \
//! Standard_Transient to enable use of OCCT RTTI.
//!
//! Inline version, does not require IMPLEMENT_STANDARD_RTTIEXT, but when used
//! for big hierarchies of classes may cause considerable increase of size of binaries.
#define DEFINE_STANDARD_RTTI_INLINE(Class,Base) \
public: \
typedef Base base_type; \
static const char* get_type_name () { return #Class; } \
static const Handle(Standard_Type)& get_type_descriptor () { return Standard_Type::Instance<Class>(); } \
virtual const Handle(Standard_Type)& DynamicType() const Standard_OVERRIDE \
{ return STANDARD_TYPE(Class); }
//! Helper macro to be included in definition of the classes inheriting
//! Standard_Transient to enable use of OCCT RTTI.
//!
//! Out-of-line version, requires IMPLEMENT_STANDARD_RTTIEXT.
#define DEFINE_STANDARD_RTTIEXT(Class,Base) \
public: \
typedef Base base_type; \
static const char* get_type_name () { return #Class; } \
Standard_EXPORT static const Handle(Standard_Type)& get_type_descriptor (); \
Standard_EXPORT virtual const Handle(Standard_Type)& DynamicType() const Standard_OVERRIDE;
//! Defines implementation of type descriptor and DynamicType() function
#define IMPLEMENT_STANDARD_RTTIEXT(Class,Base) \
const Handle(Standard_Type)& Class::get_type_descriptor () { return Standard_Type::Instance<Class>(); } \
const Handle(Standard_Type)& Class::DynamicType() const { return get_type_descriptor(); }
// forward declaration of type_instance class
namespace opencascade {
template <typename T>
@@ -117,7 +137,7 @@ public:
Standard_EXPORT ~Standard_Type ();
// Define own RTTI
DEFINE_STANDARD_RTTI(Standard_Type, Standard_Transient)
DEFINE_STANDARD_RTTIEXT(Standard_Type,Standard_Transient)
private:

View File

@@ -18,6 +18,8 @@
#include <StepRepr_HArray1OfShapeAspect.hxx>
#include <StepDimTol_RunoutZoneOrientation.hxx>
IMPLEMENT_STANDARD_RTTIEXT(StepDimTol_RunoutZoneDefinition,StepDimTol_ToleranceZoneDefinition)
//=======================================================================
//function : StepDimTol_RunoutZoneDefinition
//purpose :

View File

@@ -27,6 +27,7 @@ class StepRepr_HArray1OfShapeAspect;
class StepDimTol_RunoutZoneDefinition;
DEFINE_STANDARD_HANDLE(StepDimTol_RunoutZoneDefinition, StepDimTol_ToleranceZoneDefinition)
//! Representation of STEP entity ToleranceZoneDefinition
class StepDimTol_RunoutZoneDefinition : public StepDimTol_ToleranceZoneDefinition
{
@@ -53,7 +54,7 @@ public:
myOrientation = theOrientation;
}
DEFINE_STANDARD_RTTI(StepDimTol_ToleranceZoneDefinition, StepDimTol_ToleranceZoneDefinition)
DEFINE_STANDARD_RTTIEXT(StepDimTol_RunoutZoneDefinition,StepDimTol_ToleranceZoneDefinition)
private:
Handle(StepDimTol_RunoutZoneOrientation) myOrientation;

View File

@@ -33,12 +33,6 @@
#include <TDF_MapIteratorOfAttributeMap.hxx>
#include <TDF_MapIteratorOfLabelMap.hxx>
//#include <TDF_Reference.hxx>
#define DeclareAndSpeedCast(V,T,Vdown) Handle(T) Vdown = Handle(T)::DownCast (V)
#define DeclareConstAndSpeedCast(V,T,Vdown) const Handle(T)& Vdown = (Handle(T)&) V
#define SpeedCast(V,T,Vdown) Vdown = Handle(T)::DownCast (V)
//=======================================================================
//function : Closure
//purpose : Builds the transitive closure whithout attribute filter.

View File

@@ -38,11 +38,6 @@
#include <TDF_MapIteratorOfLabelMap.hxx>
#include <TDF_RelocationTable.hxx>
#define DeclareAndSpeedCast(V,T,Vdown) Handle(T) Vdown = Handle(T)::DownCast (V)
#define DeclareConstAndSpeedCast(V,T,Vdown) const Handle(T)& Vdown = (Handle(T)&) V
#define SpeedCast(V,T,Vdown) Vdown = Handle(T)::DownCast (V)
//=======================================================================
//function : Copy
//purpose :

View File

@@ -25,6 +25,9 @@
#include <WNT_Window.hxx>
#include <stdio.h>
IMPLEMENT_STANDARD_RTTIEXT(WNT_Window,Aspect_Window)
// =======================================================================
// function : WNT_Window
// purpose :

View File

@@ -29,6 +29,7 @@
#include <XmlObjMgt_GP.hxx>
#include <XmlObjMgt_Persistent.hxx>
IMPLEMENT_STANDARD_RTTIEXT(XmlMXCAFDoc_LocationDriver,XmlMDF_ADriver)
IMPLEMENT_DOMSTRING (DatumString, "datum")
IMPLEMENT_DOMSTRING (LocationString, "location")
IMPLEMENT_DOMSTRING (PowerString, "power")
@@ -176,7 +177,7 @@ Standard_Boolean XmlMXCAFDoc_LocationDriver::Translate
Standard_Integer aDatumID;
aLocElem.getAttribute (::DatumString()).GetInteger (aDatumID);
if (aDatumID > 0 && theMap.IsBound (aDatumID))
aDatum = (Handle(TopLoc_Datum3D)&) theMap.Find (aDatumID);
aDatum = Handle(TopLoc_Datum3D)::DownCast (theMap.Find (aDatumID));
else
return Standard_False;
}else{

View File

@@ -22,6 +22,8 @@
#include <GL/glx.h>
IMPLEMENT_STANDARD_RTTIEXT(Xw_Window,Aspect_Window)
namespace
{