From 89ae4a6ff9df4ce56c9c55e6aebf56fc956ff848 Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Fri, 27 Dec 2024 15:54:44 +0000 Subject: [PATCH] Foundation Classes - Reorganize of OCCT RTTI #215 Implement functionality to avoid mutex operation and keeping unload data Making Standard_Type own specialized handle to avoid sharing and atomic operations TODO: Simplify the base type for type. Create extended type type. Simple will have ONLY reference to std::type_info and parent type. Extended will have a name and size of the object. --- src/BOPTest/BOPTest.cxx | 2 +- .../BinLDrivers_DocumentStorageDriver.hxx | 4 +- src/BinMDF/BinMDF_ADriverTable.cxx | 7 +- src/BinMDF/BinMDF_ADriverTable.hxx | 2 +- .../BinMDataStd_GenericEmptyDriver.cxx | 2 +- .../BinMDataStd_GenericExtStringDriver.cxx | 2 +- src/BinObjMgt/BinObjMgt_Position.hxx | 1 + src/BndLib/BndLib_Add2dCurve.cxx | 7 +- src/CDF/CDF_MetaDataDriver.hxx | 1 + src/DBRep/DBRep_DrawableShape.hxx | 3 +- src/Draw/Draw_Drawable3D.hxx | 5 +- src/Draw/Draw_Number.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_BSplineCurve.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_BSplineCurve2d.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_BSplineSurface.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_BezierCurve.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_BezierCurve2d.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_BezierSurface.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_Curve.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_Curve2d.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_Point.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_Polygon2D.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_Polygon3D.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_Surface.hxx | 3 +- src/DrawTrSurf/DrawTrSurf_Triangulation.hxx | 3 +- src/Express/Express.hxx | 1 + src/Express/Express_Field.hxx | 1 + src/Express/Express_Type.hxx | 1 + src/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx | 2 +- src/HLRTest/HLRTest_Projector.hxx | 3 +- src/IFSelect/IFSelect_SignAncestor.cxx | 4 +- src/IFSelect/IFSelect_SignType.cxx | 3 +- src/Interface/Interface_FileReaderTool.cxx | 2 +- src/Interface/Interface_GTool.hxx | 4 +- src/Message/Message_Alert.hxx | 1 + src/Message/Message_Algorithm.cxx | 6 +- src/OSD/OSD_ThreadPool.cxx | 2 +- src/OpenGl/OpenGl_Element.hxx | 1 + src/OpenGl/OpenGl_Resource.hxx | 1 + .../STEPSelections_SelectDerived.cxx | 3 +- src/SelectMgr/SelectMgr.hxx | 1 + .../ShapeConstruct_ProjectCurveOnSurface.cxx | 2 +- src/Standard/Standard_ArrayStreamBuffer.cxx | 2 + src/Standard/Standard_DefineHandle.hxx | 2 +- src/Standard/Standard_Persistent.hxx | 1 + src/Standard/Standard_Transient.cxx | 6 +- src/Standard/Standard_Transient.hxx | 2 + src/Standard/Standard_Type.cxx | 97 ++--- src/Standard/Standard_Type.hxx | 369 +++++++----------- src/StepAP214/StepAP214_Protocol.cxx | 2 +- src/StepData/StepData_FileProtocol.cxx | 2 +- src/StepData/StepData_PDescr.cxx | 2 +- src/StepFile/StepFile_Read.hxx | 1 + src/StepVisual/StepVisual_CoordinatesList.cxx | 2 +- .../StepVisual_TessellatedGeometricSet.cxx | 2 +- src/TObj/TObj_Assistant.cxx | 18 +- src/TObj/TObj_Assistant.hxx | 2 +- src/TObj/TObj_Object.cxx | 2 +- src/Transfer/Transfer_TransferIterator.cxx | 9 +- src/XCAFDoc/XCAFDoc_NotesTool.cxx | 2 +- src/XSControl/XSControl_Utils.cxx | 3 +- .../XmlMDataStd_GenericEmptyDriver.cxx | 2 +- .../XmlMDataStd_GenericExtStringDriver.cxx | 2 +- 63 files changed, 252 insertions(+), 394 deletions(-) diff --git a/src/BOPTest/BOPTest.cxx b/src/BOPTest/BOPTest.cxx index 74adcb3b9f..94fccfae05 100644 --- a/src/BOPTest/BOPTest.cxx +++ b/src/BOPTest/BOPTest.cxx @@ -92,7 +92,7 @@ void BOPTest::ReportAlerts(const Handle(Message_Report)& theReport) for (int iGravity = 0; iGravity < 2; iGravity++) { // report shapes for the same type of alert together - NCollection_Map aPassedTypes; + NCollection_Map aPassedTypes; const Message_ListOfAlert& aList = theReport->GetAlerts (anAlertTypes[iGravity]); for (Message_ListOfAlert::Iterator aIt (aList); aIt.More(); aIt.Next()) { diff --git a/src/BinLDrivers/BinLDrivers_DocumentStorageDriver.hxx b/src/BinLDrivers/BinLDrivers_DocumentStorageDriver.hxx index dee195b71c..626f9708ae 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentStorageDriver.hxx +++ b/src/BinLDrivers/BinLDrivers_DocumentStorageDriver.hxx @@ -120,8 +120,8 @@ private: BinObjMgt_Persistent myPAtt; TDF_LabelList myEmptyLabels; - TColStd_MapOfTransient myMapUnsupported; - TColStd_IndexedMapOfTransient myTypesMap; + NCollection_Map myMapUnsupported; + NCollection_IndexedMap myTypesMap; BinLDrivers_VectorOfDocumentSection mySections; TCollection_ExtendedString myFileName; //! Sizes of labels and some attributes that will be stored in the second pass diff --git a/src/BinMDF/BinMDF_ADriverTable.cxx b/src/BinMDF/BinMDF_ADriverTable.cxx index a5fd1184cb..b060beed34 100644 --- a/src/BinMDF/BinMDF_ADriverTable.cxx +++ b/src/BinMDF/BinMDF_ADriverTable.cxx @@ -90,12 +90,12 @@ const Handle(Standard_Type)& BinMDF_ADriverTable::AddDerivedDriver (Standard_CSt //======================================================================= void BinMDF_ADriverTable::AssignIds - (const TColStd_IndexedMapOfTransient& theTypes) + (const NCollection_IndexedMap& theTypes) { myMapId.Clear(); Standard_Integer i; for (i=1; i <= theTypes.Extent(); i++) { - Handle(Standard_Type) aType (Handle(Standard_Type)::DownCast (theTypes(i))); + const Handle(Standard_Type)& aType = theTypes(i); if (myMap.IsBound (aType)) { myMapId.Bind (aType, i); } @@ -141,7 +141,8 @@ void BinMDF_ADriverTable::AssignIds { if (!myMapId.IsBound2 (aStrId.Value())) { - if (Handle(Standard_Type) anAdded = AddDerivedDriver (aStrId.Key().ToCString())) + Handle(Standard_Type) anAdded = AddDerivedDriver(aStrId.Key().ToCString()); + if (!anAdded.IsNull()) { myMapId.Bind (anAdded, aStrId.Value()); } diff --git a/src/BinMDF/BinMDF_ADriverTable.hxx b/src/BinMDF/BinMDF_ADriverTable.hxx index 306bc37bdc..eb772da635 100644 --- a/src/BinMDF/BinMDF_ADriverTable.hxx +++ b/src/BinMDF/BinMDF_ADriverTable.hxx @@ -59,7 +59,7 @@ public: //! Assigns the IDs to the drivers of the given Types. //! It uses indices in the map as IDs. //! Useful in storage procedure. - Standard_EXPORT void AssignIds (const TColStd_IndexedMapOfTransient& theTypes); + Standard_EXPORT void AssignIds (const NCollection_IndexedMap& theTypes); //! Assigns the IDs to the drivers of the given Type Names; //! It uses indices in the sequence as IDs. diff --git a/src/BinMDataStd/BinMDataStd_GenericEmptyDriver.cxx b/src/BinMDataStd/BinMDataStd_GenericEmptyDriver.cxx index 1d05de0eb6..66b0c7b883 100644 --- a/src/BinMDataStd/BinMDataStd_GenericEmptyDriver.cxx +++ b/src/BinMDataStd/BinMDataStd_GenericEmptyDriver.cxx @@ -47,7 +47,7 @@ Handle(TDF_Attribute) BinMDataStd_GenericEmptyDriver::NewEmpty() const //======================================================================= const Handle(Standard_Type)& BinMDataStd_GenericEmptyDriver::SourceType() const { - return Standard_Type::Instance(); + return STANDARD_TYPE(TDataStd_GenericEmpty); } //======================================================================= diff --git a/src/BinMDataStd/BinMDataStd_GenericExtStringDriver.cxx b/src/BinMDataStd/BinMDataStd_GenericExtStringDriver.cxx index c6f3ad78f1..145d778730 100644 --- a/src/BinMDataStd/BinMDataStd_GenericExtStringDriver.cxx +++ b/src/BinMDataStd/BinMDataStd_GenericExtStringDriver.cxx @@ -47,7 +47,7 @@ Handle(TDF_Attribute) BinMDataStd_GenericExtStringDriver::NewEmpty() const //======================================================================= Handle(Standard_Type)& BinMDataStd_GenericExtStringDriver::SourceType() const { - static Handle(Standard_Type) aSourceType = Standard_Type::Instance(); + static Handle(Standard_Type) aSourceType = STANDARD_TYPE(TDataStd_GenericExtString); return aSourceType; } diff --git a/src/BinObjMgt/BinObjMgt_Position.hxx b/src/BinObjMgt/BinObjMgt_Position.hxx index 7fdc3f737f..b6fc4d2d2b 100644 --- a/src/BinObjMgt/BinObjMgt_Position.hxx +++ b/src/BinObjMgt/BinObjMgt_Position.hxx @@ -15,6 +15,7 @@ #define _BinObjMgt_Position_HeaderFile #include +#include class BinObjMgt_Position; DEFINE_STANDARD_HANDLE (BinObjMgt_Position, Standard_Transient) diff --git a/src/BndLib/BndLib_Add2dCurve.cxx b/src/BndLib/BndLib_Add2dCurve.cxx index f0ddc2562a..77e4a5e454 100644 --- a/src/BndLib/BndLib_Add2dCurve.cxx +++ b/src/BndLib/BndLib_Add2dCurve.cxx @@ -842,12 +842,9 @@ Standard_Boolean BndLib_Box2dCurve::IsTypeBase (const Handle(Geom2d_Curve)& aC2D, GeomAbs_CurveType& aTypeB) { - Standard_Boolean bRet; - Handle(Standard_Type) aType; + Standard_Boolean bRet=Standard_True; // - bRet=Standard_True; - // - aType=aC2D->DynamicType(); + const Handle(Standard_Type)& aType = aC2D->DynamicType(); if (aType==STANDARD_TYPE(Geom2d_Line)) { aTypeB=GeomAbs_Line; } diff --git a/src/CDF/CDF_MetaDataDriver.hxx b/src/CDF/CDF_MetaDataDriver.hxx index 5a3692dd9b..454df0f48b 100644 --- a/src/CDF/CDF_MetaDataDriver.hxx +++ b/src/CDF/CDF_MetaDataDriver.hxx @@ -18,6 +18,7 @@ #define _CDF_MetaDataDriver_HeaderFile #include +#include class CDM_MetaData; class TCollection_ExtendedString; diff --git a/src/DBRep/DBRep_DrawableShape.hxx b/src/DBRep/DBRep_DrawableShape.hxx index c129ea46ad..c8f0310bdf 100644 --- a/src/DBRep/DBRep_DrawableShape.hxx +++ b/src/DBRep/DBRep_DrawableShape.hxx @@ -36,8 +36,7 @@ class gp_Trsf; //! list of edges and a list of faces. class DBRep_DrawableShape : public Draw_Drawable3D { - DEFINE_STANDARD_RTTIEXT(DBRep_DrawableShape, Draw_Drawable3D) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DBRep_DrawableShape, Draw_Drawable3D) public: Standard_EXPORT DBRep_DrawableShape(const TopoDS_Shape& C, const Draw_Color& FreeCol, const Draw_Color& ConnCol, const Draw_Color& EdgeCol, const Draw_Color& IsosCol, const Standard_Real size, const Standard_Integer nbisos, const Standard_Integer discret); diff --git a/src/Draw/Draw_Drawable3D.hxx b/src/Draw/Draw_Drawable3D.hxx index 6affd43c2c..91c7193c19 100644 --- a/src/Draw/Draw_Drawable3D.hxx +++ b/src/Draw/Draw_Drawable3D.hxx @@ -51,8 +51,9 @@ public: //! @def Draw_Drawable3D_FACTORY //! Auxiliary macros defining Draw_Drawable3D restoration API to sub-class. - #define Draw_Drawable3D_FACTORY \ - static void RegisterFactory() { Draw_Drawable3D::RegisterFactory (get_type_name(), &Restore); } \ + #define Draw_Drawable3D_FACTORY_RTTIEXT(Class,Base) \ + DEFINE_STANDARD_RTTIEXT(Class, Base) \ + static void RegisterFactory() { Draw_Drawable3D::RegisterFactory (#Class, &Restore); } \ Standard_EXPORT static Handle(Draw_Drawable3D) Restore (Standard_IStream& theStream); public: diff --git a/src/Draw/Draw_Number.hxx b/src/Draw/Draw_Number.hxx index 9927258c6b..b58ef70535 100644 --- a/src/Draw/Draw_Number.hxx +++ b/src/Draw/Draw_Number.hxx @@ -24,8 +24,7 @@ DEFINE_STANDARD_HANDLE(Draw_Number, Draw_Drawable3D) //! To store numbers in variables. class Draw_Number : public Draw_Drawable3D { - DEFINE_STANDARD_RTTIEXT(Draw_Number, Draw_Drawable3D) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(Draw_Number, Draw_Drawable3D) public: Standard_EXPORT Draw_Number (const Standard_Real theV); diff --git a/src/DrawTrSurf/DrawTrSurf_BSplineCurve.hxx b/src/DrawTrSurf/DrawTrSurf_BSplineCurve.hxx index 86d0cb4268..e32b0dc39b 100644 --- a/src/DrawTrSurf/DrawTrSurf_BSplineCurve.hxx +++ b/src/DrawTrSurf/DrawTrSurf_BSplineCurve.hxx @@ -27,8 +27,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_BSplineCurve, DrawTrSurf_Curve) class DrawTrSurf_BSplineCurve : public DrawTrSurf_Curve { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_BSplineCurve, DrawTrSurf_Curve) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_BSplineCurve, DrawTrSurf_Curve) public: //! creates a drawable BSpline curve from a BSpline curve of package Geom. diff --git a/src/DrawTrSurf/DrawTrSurf_BSplineCurve2d.hxx b/src/DrawTrSurf/DrawTrSurf_BSplineCurve2d.hxx index 6f325ef004..65b661fc52 100644 --- a/src/DrawTrSurf/DrawTrSurf_BSplineCurve2d.hxx +++ b/src/DrawTrSurf/DrawTrSurf_BSplineCurve2d.hxx @@ -27,8 +27,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_BSplineCurve2d, DrawTrSurf_Curve2d) class DrawTrSurf_BSplineCurve2d : public DrawTrSurf_Curve2d { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_BSplineCurve2d, DrawTrSurf_Curve2d) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_BSplineCurve2d, DrawTrSurf_Curve2d) public: //! creates a drawable BSpline curve from a BSpline curve of package Geom2d. diff --git a/src/DrawTrSurf/DrawTrSurf_BSplineSurface.hxx b/src/DrawTrSurf/DrawTrSurf_BSplineSurface.hxx index f4803c2278..c85a9e686b 100644 --- a/src/DrawTrSurf/DrawTrSurf_BSplineSurface.hxx +++ b/src/DrawTrSurf/DrawTrSurf_BSplineSurface.hxx @@ -32,8 +32,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_BSplineSurface, DrawTrSurf_Surface) //! if you just want to sea boundaries and isoparametric curves. class DrawTrSurf_BSplineSurface : public DrawTrSurf_Surface { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_BSplineSurface, DrawTrSurf_Surface) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_BSplineSurface, DrawTrSurf_Surface) public: //! default drawing mode. diff --git a/src/DrawTrSurf/DrawTrSurf_BezierCurve.hxx b/src/DrawTrSurf/DrawTrSurf_BezierCurve.hxx index 772c664de5..c32d13c4be 100644 --- a/src/DrawTrSurf/DrawTrSurf_BezierCurve.hxx +++ b/src/DrawTrSurf/DrawTrSurf_BezierCurve.hxx @@ -26,8 +26,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_BezierCurve, DrawTrSurf_Curve) class DrawTrSurf_BezierCurve : public DrawTrSurf_Curve { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_BezierCurve, DrawTrSurf_Curve) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_BezierCurve, DrawTrSurf_Curve) public: //! creates a drawable Bezier curve from a Bezier curve of package Geom. diff --git a/src/DrawTrSurf/DrawTrSurf_BezierCurve2d.hxx b/src/DrawTrSurf/DrawTrSurf_BezierCurve2d.hxx index f5e53d7a4e..c24f2249d9 100644 --- a/src/DrawTrSurf/DrawTrSurf_BezierCurve2d.hxx +++ b/src/DrawTrSurf/DrawTrSurf_BezierCurve2d.hxx @@ -26,8 +26,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_BezierCurve2d, DrawTrSurf_Curve2d) class DrawTrSurf_BezierCurve2d : public DrawTrSurf_Curve2d { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_BezierCurve2d, DrawTrSurf_Curve2d) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_BezierCurve2d, DrawTrSurf_Curve2d) public: //! creates a drawable Bezier curve from a Bezier curve of package Geom2d. diff --git a/src/DrawTrSurf/DrawTrSurf_BezierSurface.hxx b/src/DrawTrSurf/DrawTrSurf_BezierSurface.hxx index 758ab3ed32..ebf79ee8bf 100644 --- a/src/DrawTrSurf/DrawTrSurf_BezierSurface.hxx +++ b/src/DrawTrSurf/DrawTrSurf_BezierSurface.hxx @@ -26,8 +26,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_BezierSurface, DrawTrSurf_Surface) class DrawTrSurf_BezierSurface : public DrawTrSurf_Surface { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_BezierSurface, DrawTrSurf_Surface) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_BezierSurface, DrawTrSurf_Surface) public: //! creates a drawable Bezier curve from a Bezier curve of package Geom. diff --git a/src/DrawTrSurf/DrawTrSurf_Curve.hxx b/src/DrawTrSurf/DrawTrSurf_Curve.hxx index 36ed5889e6..b5e618516d 100644 --- a/src/DrawTrSurf/DrawTrSurf_Curve.hxx +++ b/src/DrawTrSurf/DrawTrSurf_Curve.hxx @@ -29,8 +29,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_Curve, DrawTrSurf_Drawable) //! This class defines a drawable curve in 3d space. class DrawTrSurf_Curve : public DrawTrSurf_Drawable { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_Curve, DrawTrSurf_Drawable) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_Curve, DrawTrSurf_Drawable) public: //! creates a drawable curve from a curve of package Geom. diff --git a/src/DrawTrSurf/DrawTrSurf_Curve2d.hxx b/src/DrawTrSurf/DrawTrSurf_Curve2d.hxx index ba56a765b5..fc5ddf3c2b 100644 --- a/src/DrawTrSurf/DrawTrSurf_Curve2d.hxx +++ b/src/DrawTrSurf/DrawTrSurf_Curve2d.hxx @@ -29,8 +29,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_Curve2d, DrawTrSurf_Drawable) //! The curve is drawn in the plane XOY. class DrawTrSurf_Curve2d : public DrawTrSurf_Drawable { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_Curve2d, DrawTrSurf_Drawable) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_Curve2d, DrawTrSurf_Drawable) public: //! creates a drawable curve from a curve of package Geom2d. diff --git a/src/DrawTrSurf/DrawTrSurf_Point.hxx b/src/DrawTrSurf/DrawTrSurf_Point.hxx index e6545f8fc6..41d226e25c 100644 --- a/src/DrawTrSurf/DrawTrSurf_Point.hxx +++ b/src/DrawTrSurf/DrawTrSurf_Point.hxx @@ -29,8 +29,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_Point, Draw_Drawable3D) //! A drawable point. class DrawTrSurf_Point : public Draw_Drawable3D { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_Point, Draw_Drawable3D) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_Point, Draw_Drawable3D) public: Standard_EXPORT DrawTrSurf_Point (const gp_Pnt& P, const Draw_MarkerShape Shape, const Draw_Color& Col); diff --git a/src/DrawTrSurf/DrawTrSurf_Polygon2D.hxx b/src/DrawTrSurf/DrawTrSurf_Polygon2D.hxx index 4239a74d02..240f6b0f20 100644 --- a/src/DrawTrSurf/DrawTrSurf_Polygon2D.hxx +++ b/src/DrawTrSurf/DrawTrSurf_Polygon2D.hxx @@ -28,8 +28,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_Polygon2D, Draw_Drawable2D) //! Optional display of nodes. class DrawTrSurf_Polygon2D : public Draw_Drawable2D { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_Polygon2D, Draw_Drawable2D) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_Polygon2D, Draw_Drawable2D) public: Standard_EXPORT DrawTrSurf_Polygon2D (const Handle(Poly_Polygon2D)& P); diff --git a/src/DrawTrSurf/DrawTrSurf_Polygon3D.hxx b/src/DrawTrSurf/DrawTrSurf_Polygon3D.hxx index 5a24963b5e..28f3d113c9 100644 --- a/src/DrawTrSurf/DrawTrSurf_Polygon3D.hxx +++ b/src/DrawTrSurf/DrawTrSurf_Polygon3D.hxx @@ -28,8 +28,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_Polygon3D, Draw_Drawable3D) //! Optional display of nodes. class DrawTrSurf_Polygon3D : public Draw_Drawable3D { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_Polygon3D, Draw_Drawable3D) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_Polygon3D, Draw_Drawable3D) public: Standard_EXPORT DrawTrSurf_Polygon3D (const Handle(Poly_Polygon3D)& P); diff --git a/src/DrawTrSurf/DrawTrSurf_Surface.hxx b/src/DrawTrSurf/DrawTrSurf_Surface.hxx index 6be800fb86..0c13273caa 100644 --- a/src/DrawTrSurf/DrawTrSurf_Surface.hxx +++ b/src/DrawTrSurf/DrawTrSurf_Surface.hxx @@ -29,8 +29,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_Surface, DrawTrSurf_Drawable) //! With this class you can draw a general surface from package Geom. class DrawTrSurf_Surface : public DrawTrSurf_Drawable { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_Surface, DrawTrSurf_Drawable) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_Surface, DrawTrSurf_Drawable) public: //! default drawing mode diff --git a/src/DrawTrSurf/DrawTrSurf_Triangulation.hxx b/src/DrawTrSurf/DrawTrSurf_Triangulation.hxx index e53dd6451a..2937a32f3d 100644 --- a/src/DrawTrSurf/DrawTrSurf_Triangulation.hxx +++ b/src/DrawTrSurf/DrawTrSurf_Triangulation.hxx @@ -32,8 +32,7 @@ DEFINE_STANDARD_HANDLE(DrawTrSurf_Triangulation, Draw_Drawable3D) //! Optional display of triangles and nodes indices. class DrawTrSurf_Triangulation : public Draw_Drawable3D { - DEFINE_STANDARD_RTTIEXT(DrawTrSurf_Triangulation, Draw_Drawable3D) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(DrawTrSurf_Triangulation, Draw_Drawable3D) public: Standard_EXPORT DrawTrSurf_Triangulation (const Handle(Poly_Triangulation)& T); diff --git a/src/Express/Express.hxx b/src/Express/Express.hxx index 0dcb80ee96..534c37210c 100644 --- a/src/Express/Express.hxx +++ b/src/Express/Express.hxx @@ -17,6 +17,7 @@ #include #include #include +#include class Express_Schema; class TCollection_AsciiString; diff --git a/src/Express/Express_Field.hxx b/src/Express/Express_Field.hxx index f2143fd017..e8473bd8a5 100644 --- a/src/Express/Express_Field.hxx +++ b/src/Express/Express_Field.hxx @@ -15,6 +15,7 @@ #define _Express_Field_HeaderFile #include +#include class Express_Type; class TCollection_HAsciiString; diff --git a/src/Express/Express_Type.hxx b/src/Express/Express_Type.hxx index 62dbe2a36b..a2bbdc93be 100644 --- a/src/Express/Express_Type.hxx +++ b/src/Express/Express_Type.hxx @@ -15,6 +15,7 @@ #define _Express_Type_HeaderFile #include +#include class TCollection_AsciiString; diff --git a/src/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx b/src/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx index 10b014ae43..31225743c6 100644 --- a/src/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx +++ b/src/Geom2dAdaptor/Geom2dAdaptor_Curve.cxx @@ -215,7 +215,7 @@ void Geom2dAdaptor_Curve::load(const Handle(Geom2d_Curve)& C, myNestedEvaluator.Nullify(); myBSplineCurve.Nullify(); - Handle(Standard_Type) TheType = C->DynamicType(); + const Handle(Standard_Type)& TheType = C->DynamicType(); if ( TheType == STANDARD_TYPE(Geom2d_TrimmedCurve)) { Load(Handle(Geom2d_TrimmedCurve)::DownCast (C)->BasisCurve(), UFirst,ULast); diff --git a/src/HLRTest/HLRTest_Projector.hxx b/src/HLRTest/HLRTest_Projector.hxx index 93d75c0184..e72e93443d 100644 --- a/src/HLRTest/HLRTest_Projector.hxx +++ b/src/HLRTest/HLRTest_Projector.hxx @@ -26,8 +26,7 @@ DEFINE_STANDARD_HANDLE(HLRTest_Projector, Draw_Drawable3D) //! Draw Variable Projector to test. class HLRTest_Projector : public Draw_Drawable3D { - DEFINE_STANDARD_RTTIEXT(HLRTest_Projector, Draw_Drawable3D) - Draw_Drawable3D_FACTORY + Draw_Drawable3D_FACTORY_RTTIEXT(HLRTest_Projector, Draw_Drawable3D) public: Standard_EXPORT HLRTest_Projector(const HLRAlgo_Projector& P); diff --git a/src/IFSelect/IFSelect_SignAncestor.cxx b/src/IFSelect/IFSelect_SignAncestor.cxx index 8e11595c3d..192da07966 100644 --- a/src/IFSelect/IFSelect_SignAncestor.cxx +++ b/src/IFSelect/IFSelect_SignAncestor.cxx @@ -32,9 +32,7 @@ Standard_Boolean IFSelect_SignAncestor::Matches(const Handle(Standard_Transient) const TCollection_AsciiString& text, const Standard_Boolean /*exact*/) const { - if (ent.IsNull()) return Standard_False; - DeclareAndCast(Standard_Type,atype,ent); - if (atype.IsNull()) atype = ent->DynamicType(); + Handle(Standard_Type) atype = ent->DynamicType(); return atype->SubType(text.ToCString()); } diff --git a/src/IFSelect/IFSelect_SignType.cxx b/src/IFSelect/IFSelect_SignType.cxx index bf19e04fd2..af3c05bc47 100644 --- a/src/IFSelect/IFSelect_SignType.cxx +++ b/src/IFSelect/IFSelect_SignType.cxx @@ -33,8 +33,7 @@ static Standard_CString nulsign = ""; const Handle(Interface_InterfaceModel)& /*model*/) const { if (ent.IsNull()) return nulsign; - DeclareAndCast(Standard_Type,atype,ent); - if (atype.IsNull()) atype = ent->DynamicType(); + Handle(Standard_Type) atype = ent->DynamicType(); Standard_CString tn = atype->Name(); if (!thenopk) return tn; for (int i = 0; tn[i] != '\0'; i ++) { diff --git a/src/Interface/Interface_FileReaderTool.cxx b/src/Interface/Interface_FileReaderTool.cxx index a2504d05a1..b6cc283453 100644 --- a/src/Interface/Interface_FileReaderTool.cxx +++ b/src/Interface/Interface_FileReaderTool.cxx @@ -250,7 +250,7 @@ Standard_Boolean Interface_FileReaderTool::RecognizeByLib(const Standard_Integer } if (CN <= 0 || proto.IsNull()) return Standard_False; // Se recaler dans GeneralLib : Creation de l entite vide - Handle(Standard_Type) typrot = proto->DynamicType(); + const Handle(Standard_Type)& typrot = proto->DynamicType(); for (glib.Start(); glib.More(); glib.Next()) { proto = glib.Protocol(); if (proto.IsNull()) continue; diff --git a/src/Interface/Interface_GTool.hxx b/src/Interface/Interface_GTool.hxx index 8448a7329a..692d8ab324 100644 --- a/src/Interface/Interface_GTool.hxx +++ b/src/Interface/Interface_GTool.hxx @@ -110,8 +110,8 @@ private: Handle(Interface_Protocol) theproto; Handle(Interface_SignType) thesign; Interface_GeneralLib thelib; - Interface_DataMapOfTransientInteger thentnum; - TColStd_IndexedDataMapOfTransientTransient thentmod; + NCollection_DataMap thentnum; + NCollection_IndexedDataMap thentmod; }; diff --git a/src/Message/Message_Alert.hxx b/src/Message/Message_Alert.hxx index d76e415750..42c0cee4de 100644 --- a/src/Message/Message_Alert.hxx +++ b/src/Message/Message_Alert.hxx @@ -17,6 +17,7 @@ #define _Message_Alert_HeaderFile #include +#include DEFINE_STANDARD_HANDLE(Message_Alert, Standard_Transient) diff --git a/src/Message/Message_Algorithm.cxx b/src/Message/Message_Algorithm.cxx index 8a04ef27cc..4fa8fe7a17 100644 --- a/src/Message/Message_Algorithm.cxx +++ b/src/Message/Message_Algorithm.cxx @@ -223,13 +223,9 @@ void Message_Algorithm::SendStatusMessages (const Message_ExecStatus& theStatus, // find message, prefixed by class type name, iterating by base classes if necessary TCollection_AsciiString aMsgName; - for (Handle(Standard_Type) aType = DynamicType(); ! aType.IsNull(); aType = aType->Parent()) - { + Handle(Standard_Type) aType = DynamicType(); aMsgName = aType->Name(); aMsgName += aSuffix; - if (Message_MsgFile::HasMsg(aMsgName)) - break; - } // create a message Message_Msg aMsg ( aMsgName ); diff --git a/src/OSD/OSD_ThreadPool.cxx b/src/OSD/OSD_ThreadPool.cxx index 04a65bba56..55858c5ba7 100644 --- a/src/OSD/OSD_ThreadPool.cxx +++ b/src/OSD/OSD_ThreadPool.cxx @@ -76,7 +76,7 @@ void OSD_ThreadPool::EnumeratedThread::WaitIdle() myIdleEvent.Reset(); } } - +#include // ======================================================================= // function : DefaultPool // purpose : diff --git a/src/OpenGl/OpenGl_Element.hxx b/src/OpenGl/OpenGl_Element.hxx index 47e99136ce..c26618b034 100644 --- a/src/OpenGl/OpenGl_Element.hxx +++ b/src/OpenGl/OpenGl_Element.hxx @@ -17,6 +17,7 @@ #define OpenGl_Element_HeaderFile #include +#include class Graphic3d_FrameStatsDataTmp; class OpenGl_Workspace; diff --git a/src/OpenGl/OpenGl_Resource.hxx b/src/OpenGl/OpenGl_Resource.hxx index eea4afdc26..76a595ee50 100644 --- a/src/OpenGl/OpenGl_Resource.hxx +++ b/src/OpenGl/OpenGl_Resource.hxx @@ -17,6 +17,7 @@ #define OpenGl_Resource_HeaderFile #include +#include class OpenGl_Context; diff --git a/src/STEPSelections/STEPSelections_SelectDerived.cxx b/src/STEPSelections/STEPSelections_SelectDerived.cxx index 6a39a1f974..6406247d07 100644 --- a/src/STEPSelections/STEPSelections_SelectDerived.cxx +++ b/src/STEPSelections/STEPSelections_SelectDerived.cxx @@ -60,8 +60,7 @@ Standard_Boolean STEPSelections_SelectDerived::Matches(const Handle(Standard_Tra Standard_Boolean plex = module->IsComplex(CN); if (!plex) { - DeclareAndCast(Standard_Type,atype,ent); - if (atype.IsNull()) atype = ent->DynamicType(); + Handle(Standard_Type) atype = ent->DynamicType(); return atype->SubType(checker); } else { TColStd_SequenceOfAsciiString list; diff --git a/src/SelectMgr/SelectMgr.hxx b/src/SelectMgr/SelectMgr.hxx index 72281a9552..87e5c5af18 100644 --- a/src/SelectMgr/SelectMgr.hxx +++ b/src/SelectMgr/SelectMgr.hxx @@ -15,6 +15,7 @@ #define _SelectMgr_HeaderFile #include +#include class Graphic3d_Structure; class Graphic3d_TransformPers; diff --git a/src/ShapeConstruct/ShapeConstruct_ProjectCurveOnSurface.cxx b/src/ShapeConstruct/ShapeConstruct_ProjectCurveOnSurface.cxx index 79e1b1a750..c1bd4358ea 100644 --- a/src/ShapeConstruct/ShapeConstruct_ProjectCurveOnSurface.cxx +++ b/src/ShapeConstruct/ShapeConstruct_ProjectCurveOnSurface.cxx @@ -870,7 +870,7 @@ Standard_Boolean ShapeConstruct_ProjectCurveOnSurface::PerformByProjLib(Handle(G Handle(Geom_Curve) cIso; Standard_Real t1, t2; - Handle(Standard_Type) sType = mySurf->Surface()->DynamicType(); + const Handle(Standard_Type)& sType = mySurf->Surface()->DynamicType(); Standard_Boolean isAnalytic = Standard_True; if (sType == STANDARD_TYPE(Geom_BezierSurface) || sType == STANDARD_TYPE(Geom_BSplineSurface)) isAnalytic = Standard_False; Standard_Real uf, ul, vf, vl; diff --git a/src/Standard/Standard_ArrayStreamBuffer.cxx b/src/Standard/Standard_ArrayStreamBuffer.cxx index 803e3341ce..87074906fa 100644 --- a/src/Standard/Standard_ArrayStreamBuffer.cxx +++ b/src/Standard/Standard_ArrayStreamBuffer.cxx @@ -13,6 +13,8 @@ #include +#include + // ======================================================================= // function : Standard_ArrayStreamBuffer // purpose : diff --git a/src/Standard/Standard_DefineHandle.hxx b/src/Standard/Standard_DefineHandle.hxx index f03415c212..796ebaf745 100644 --- a/src/Standard/Standard_DefineHandle.hxx +++ b/src/Standard/Standard_DefineHandle.hxx @@ -21,10 +21,10 @@ //! Since OCCT 7.0, relevant macros are provided by Standard_Type.hxx and Standard_Handle.hxx. #include +#include class Standard_Transient; class Standard_Persistent; -class Standard_Type; // Obsolete macros kept for compatibility #define IMPLEMENT_DOWNCAST(C1,BC) diff --git a/src/Standard/Standard_Persistent.hxx b/src/Standard/Standard_Persistent.hxx index acfbdd4b87..a34f99d604 100644 --- a/src/Standard/Standard_Persistent.hxx +++ b/src/Standard/Standard_Persistent.hxx @@ -16,6 +16,7 @@ #define _Standard_Persistent_HeaderFile #include +#include //! Root of "persistent" classes, a legacy support of //! object oriented databases, now outdated. diff --git a/src/Standard/Standard_Transient.cxx b/src/Standard/Standard_Transient.cxx index fa71956bfa..72e17844cd 100644 --- a/src/Standard/Standard_Transient.cxx +++ b/src/Standard/Standard_Transient.cxx @@ -18,9 +18,11 @@ #include #include -const Handle(Standard_Type)& Standard_Transient::get_type_descriptor () +const Handle(Standard_Type)& Standard_Transient::get_type_descriptor() { - return opencascade::type_instance::get(); + static const opencascade::handle THE_TYPE_INSTANCE(new Standard_Type(typeid(Standard_Transient), get_type_name(), + sizeof(Standard_Transient), nullptr)); + return THE_TYPE_INSTANCE; } // diff --git a/src/Standard/Standard_Transient.hxx b/src/Standard/Standard_Transient.hxx index 024c631d27..1e62e8855d 100644 --- a/src/Standard/Standard_Transient.hxx +++ b/src/Standard/Standard_Transient.hxx @@ -122,4 +122,6 @@ private: //! Definition of Handle_Standard_Transient as typedef for compatibility typedef opencascade::handle Handle_Standard_Transient; +#include + #endif diff --git a/src/Standard/Standard_Type.cxx b/src/Standard/Standard_Type.cxx index 6321deab29..7d4e16bdc6 100644 --- a/src/Standard/Standard_Type.cxx +++ b/src/Standard/Standard_Type.cxx @@ -1,5 +1,5 @@ // Copyright (c) 1998-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS +// Copyright (c) 1999-2024 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // @@ -12,40 +12,37 @@ // Alternatively, this file may be used under the terms of Open CASCADE // commercial license or contractual agreement. - #include -#include -#include - -#include - -IMPLEMENT_STANDARD_RTTIEXT(Standard_Type,Standard_Transient) - -//============================================================================ - -Standard_Type::Standard_Type (const std::type_info& theInfo, - const char* theName, - Standard_Size theSize, - const Handle(Standard_Type)& theParent) : - myInfo(theInfo), - myName(theName), - mySize(theSize), - myParent(theParent) -{ -} //============================================================================ - Standard_Boolean Standard_Type::SubType (const Handle(Standard_Type)& theOther) const { - return ! theOther.IsNull() && (theOther == this || (! myParent.IsNull() && myParent->SubType (theOther))); + const Standard_Type* aTypeIter = this; + while (aTypeIter != nullptr) + { + if (*theOther == *aTypeIter) + { + return true; + } + aTypeIter = aTypeIter->Parent(); + } + return false; } //============================================================================ Standard_Boolean Standard_Type::SubType (const Standard_CString theName) const { - return theName != 0 && (IsEqual (myName, theName) || (! myParent.IsNull() && myParent->SubType (theName))); + const Standard_Type* aTypeIter = this; + while (aTypeIter != nullptr) + { + if (IsEqual(theName, aTypeIter->Name())) + { + return true; + } + aTypeIter = aTypeIter->Parent(); + } + return false; } // ------------------------------------------------------------------ @@ -54,54 +51,4 @@ Standard_Boolean Standard_Type::SubType (const Standard_CString theName) const void Standard_Type::Print (Standard_OStream& AStream) const { AStream << std::hex << (Standard_Address)this << " : " << std::dec << myName ; -} - -//============================================================================ -// Registry of types -//============================================================================ - -namespace { - // Map of string to type - typedef std::unordered_map registry_type; - - // Registry is made static in the function to ensure that it gets - // initialized by the time of first access - registry_type& GetRegistry() - { - static registry_type theRegistry; - return theRegistry; - } - - // To initialize theRegistry map as soon as possible to be destroyed the latest - Handle(Standard_Type) theType = STANDARD_TYPE(Standard_Transient); -} - -Standard_Type* Standard_Type::Register (const std::type_info& theInfo, const char* theName, - Standard_Size theSize, const Handle(Standard_Type)& theParent) -{ - // Access to registry is protected by mutex; it should not happen often because - // instances are cached by Standard_Type::Instance() (one per binary module) - static Standard_Mutex theMutex; - Standard_Mutex::Sentry aSentry (theMutex); - - // return existing descriptor if already in the registry - registry_type& aRegistry = GetRegistry(); - Standard_Type* aType = 0; - auto anIter = aRegistry.find(theInfo); - if (anIter != aRegistry.end()) - return anIter->second; - - // else create a new descriptor - aType = new Standard_Type (theInfo, theName, theSize, theParent); - - // then add it to registry and return (the reference to the handle stored in the registry) - aRegistry.emplace(theInfo, aType); - return aType; -} - -Standard_Type::~Standard_Type () -{ - // remove descriptor from the registry - registry_type& aRegistry = GetRegistry(); - Standard_ASSERT(aRegistry.erase(myInfo) > 0, "Standard_Type::~Standard_Type() cannot find itself in registry",); -} +} \ No newline at end of file diff --git a/src/Standard/Standard_Type.hxx b/src/Standard/Standard_Type.hxx index 6608b757e9..26bc834127 100644 --- a/src/Standard/Standard_Type.hxx +++ b/src/Standard/Standard_Type.hxx @@ -1,5 +1,5 @@ // Copyright (c) 1991-1999 Matra Datavision -// Copyright (c) 1999-2014 OPEN CASCADE SAS +// Copyright (c) 1999-2024 OPEN CASCADE SAS // // This file is part of Open CASCADE Technology software library. // @@ -16,71 +16,159 @@ #define _Standard_Type_HeaderFile #include -#include -#include #include +#include +#include #include #include -// Auxiliary tools to check at compile time that class declared as base in -// DEFINE_STANDARD_RTTI* macro is actually a base class. -#if ! defined(OCCT_CHECK_BASE_CLASS) - -#if (defined(__GNUC__) && ((__GNUC__ == 4 && __GNUC_MINOR__ >= 7) || (__GNUC__ > 4))) - -// For GCC 4.7+, more strict check is possible -- ensuring that base class -// is direct base -- using non-standard C++ reflection functionality. +namespace opencascade +{ + template class handle; +} -#include -#include +class Standard_Transient; -namespace opencascade +class Standard_Type { - template - struct direct_base_class_as_tuple {}; +public: - template - struct direct_base_class_as_tuple > + Standard_Type(const std::type_info& theInfo, + const Standard_CString theName, + const Standard_Size theSize, + const Standard_Type* theParent) : + myInfo(theInfo), + myName(theName), + mySize(theSize), + myParent(theParent) {} + + Standard_Type(const Standard_Type& theType) : + myInfo(theType.myInfo), + myName(theType.myName), + mySize(theType.mySize), + myParent(theType.myParent) {} + + Standard_Type(Standard_Type&& theType) noexcept : + myInfo(theType.myInfo), + myName(theType.myName), + mySize(theType.mySize), + myParent(theType.myParent) {} + + Standard_Type& operator=(const Standard_Type& theOther) { - typedef std::tuple type; - }; + myInfo = theOther.myInfo; + myName = theOther.myName; + mySize = theOther.mySize; + myParent = theOther.myParent; + return *this; + } - template - struct has_type; + //! Returns the system type name of the class (typeinfo.name) + Standard_CString SystemName() const { return myInfo.get().name(); } - template - struct has_type > : std::false_type {}; + //! Returns the hash code of the class (typeinfo.hash_code) + Standard_Size HashCode() const { return myInfo.get().hash_code(); } - template - struct has_type > : has_type > {}; + //! Returns the given name of the class type (get_type_name) + Standard_CString Name() const { return myName; } - template - struct has_type > : std::true_type {}; -} + //! Returns the size of the class instance in bytes + Standard_Size Size() const { return mySize; } -#define OCCT_CHECK_BASE_CLASS(Class,Base) \ - using direct_base_classes = opencascade::direct_base_class_as_tuple::type>::type; \ - static_assert(opencascade::has_type::type::value, "OCCT RTTI definition is incorrect: " #Base " is not direct base class of " #Class); \ - static_assert(&get_type_name == &Class::get_type_name, "OCCT RTTI definition is misplaced: current class is not " #Class); + //! Returns descriptor of the base class in the hierarchy. Can be null + const Standard_Type* Parent() const { return myParent; } -#elif (defined(_MSC_VER) && (_MSC_VER >= 1900)) + bool operator==(const Standard_Type& theType) const { return myInfo.get() == theType.myInfo.get(); } -// VC14+ allow using address of member functions in static checks, -// that allows checking for the current type being correctly named in the macro -#define OCCT_CHECK_BASE_CLASS(Class,Base) \ - static_assert(opencascade::is_base_but_not_same::value, "OCCT RTTI definition is incorrect: " #Base " is not base class of " #Class); \ - static_assert(&get_type_name == &Class::get_type_name, "OCCT RTTI definition is misplaced: current class is not " #Class); + bool operator==(const std::type_info& theInfo) const { return myInfo.get() == theInfo; } + + //! Returns True if this type is the same as theOther, or inherits from theOther. + //! Note that multiple inheritance is not supported. + Standard_EXPORT Standard_Boolean SubType (const Handle(Standard_Type)& theOther) const; -#else + //! Returns True if this type is the same as theOther, or inherits from theOther. + //! Note that multiple inheritance is not supported. + Standard_EXPORT Standard_Boolean SubType (const Standard_CString theOther) const; + + //! Prints type (address of descriptor + name) to a stream + Standard_EXPORT void Print (Standard_OStream& theStream) const; + +private: + std::reference_wrapper myInfo; //!< STL Type descriptor of current class + Standard_CString myName; //!< Given name of the class + Standard_Size mySize; //!< Size of the class instance, in bytes + const Standard_Type* myParent; //!< Type descriptor of parent class +}; + +namespace opencascade +{ + template <> + class handle + { + public: + //! STL-compliant typedef of contained type + typedef Standard_Type element_type; + public: + //! Empty constructor + handle() : myObject(nullptr) {} + //! Constructor from pointer to new object + handle (const Standard_Type* theType) : myObject(theType) {} + //! Copy constructor + handle (const handle& theHandle) : myObject(theHandle.myObject) {} + //! Assignment operator + handle& operator= (const handle& theHandle) + { + myObject = theHandle.myObject; + return *this; + } + + bool IsNull() const { return myObject == nullptr; } + + bool operator== (const handle& theHandle) const + { + return myObject == theHandle.myObject; + } + + bool operator!= (const handle& theHandle) const + { + return !(myObject == theHandle.myObject); + } + + //! STL-like cast to pointer to referred object (note non-const). + //! @sa std::shared_ptr::get() + const Standard_Type* get() const { return myObject; } + //! Member access operator (note non-const) + const Standard_Type* operator-> () const { return myObject; } + //! Dereferencing operator (note non-const) + const Standard_Type& operator* () const { return *myObject; } + private: + const Standard_Type* myObject; + }; +} + +//! Operator printing type descriptor to stream +inline Standard_OStream& operator << (Standard_OStream& theStream, const opencascade::handle& theType) +{ + theStream << theType->Name(); + return theStream; +} // by default, check only the base class #define OCCT_CHECK_BASE_CLASS(Class,Base) \ static_assert(opencascade::is_base_but_not_same::value, "OCCT RTTI definition is incorrect: " #Base " is not base class of " #Class); -#endif - -#endif /* ! defined(OCCT_CHECK_BASE_CLASS) */ +namespace std +{ + template <> + struct hash + { + size_t operator()(const Standard_Type& theType) const noexcept + { + return theType.HashCode(); + } + }; +} //! Helper macro to get instance of a type descriptor for a class in a legacy way. #define STANDARD_TYPE(theType) theType::get_type_descriptor() @@ -93,8 +181,13 @@ namespace opencascade #define DEFINE_STANDARD_RTTI_INLINE(Class,Base) \ public: \ typedef Base base_type; \ - static const char* get_type_name () { return #Class; OCCT_CHECK_BASE_CLASS(Class,Base) } \ - static const Handle(Standard_Type)& get_type_descriptor () { return Standard_Type::Instance(); } \ + static const char* get_type_name() { return #Class; } \ + static const Handle(Standard_Type)& get_type_descriptor() \ + { \ + static const Handle(Standard_Type) THE_TYPE_INSTANCE(new Standard_Type(typeid(Class), get_type_name(), \ + sizeof(Class), Base::get_type_descriptor().get())); \ + return THE_TYPE_INSTANCE; \ + } \ virtual const Handle(Standard_Type)& DynamicType() const Standard_OVERRIDE { return get_type_descriptor (); } //! Helper macro to be included in definition of the classes inheriting @@ -104,186 +197,18 @@ public: \ #define DEFINE_STANDARD_RTTIEXT(Class,Base) \ public: \ typedef Base base_type; \ - static const char* get_type_name () { return #Class; OCCT_CHECK_BASE_CLASS(Class,Base) } \ - Standard_EXPORT static const Handle(Standard_Type)& get_type_descriptor (); \ + 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(); } \ - const Handle(Standard_Type)& Class::DynamicType() const { return STANDARD_TYPE(Class); } - -// forward declaration of type_instance class -namespace opencascade { - template - class type_instance; -} - -//! This class provides legacy interface (type descriptor) to run-time type -//! information (RTTI) for OCCT classes inheriting from Standard_Transient. -//! -//! In addition to features provided by standard C++ RTTI (type_info), -//! Standard_Type allows passing descriptor as an object and using it for -//! analysis of the type: -//! - get descriptor of a parent class -//! - get user-defined name of the class -//! - get size of the object -//! -//! Use static template method Instance() to get descriptor for a given type. -//! Objects supporting OCCT RTTI return their type descriptor by method DynamicType(). -//! -//! To be usable with OCCT type system, the class should provide: -//! - typedef base_type to its base class in the hierarchy -//! - method get_type_name() returning programmer-defined name of the class -//! (as a statically allocated constant C string or string literal) -//! -//! Note that user-defined name is used since typeid.name() is usually mangled in -//! compiler-dependent way. -//! -//! Only single chain of inheritance is supported, with a root base class Standard_Transient. - -class Standard_Type : public Standard_Transient -{ -public: - - //! Returns the system type name of the class (typeinfo.name) - Standard_CString SystemName() const { return myInfo.name(); } - - //! Returns the given name of the class type (get_type_name) - Standard_CString Name() const { return myName; } - - //! Returns the size of the class instance in bytes - Standard_Size Size() const { return mySize; } - - //! Returns descriptor of the base class in the hierarchy - const Handle(Standard_Type)& Parent () const { return myParent; } - - //! Returns True if this type is the same as theOther, or inherits from theOther. - //! Note that multiple inheritance is not supported. - Standard_EXPORT Standard_Boolean SubType (const Handle(Standard_Type)& theOther) const; - - //! Returns True if this type is the same as theOther, or inherits from theOther. - //! Note that multiple inheritance is not supported. - Standard_EXPORT Standard_Boolean SubType (const Standard_CString theOther) const; - - //! Prints type (address of descriptor + name) to a stream - Standard_EXPORT void Print (Standard_OStream& theStream) const; - - //! Template function returning instance of the type descriptor for an argument class. - //! - //! For optimization, each type is registered only once (due to use of the static variable). - //! - //! See helper macro DEFINE_STANDARD_RTTI for defining these items in the class. - template - static const Handle(Standard_Type)& Instance() - { - return opencascade::type_instance::get(); - } - - //! Register a type; returns either new or existing descriptor. - //! - //! @param theInfo object stores system name of the class - //! @param theName name of the class to be stored in Name field - //! @param theSize size of the class instance - //! @param theParent base class in the Transient hierarchy - //! - //! Note that this function is intended for use by opencascade::type_instance only. - Standard_EXPORT static - Standard_Type* Register (const std::type_info& theInfo, const char* theName, - Standard_Size theSize, const Handle(Standard_Type)& theParent); - - //! Destructor removes the type from the registry - Standard_EXPORT ~Standard_Type (); - - // Define own RTTI - DEFINE_STANDARD_RTTIEXT(Standard_Type,Standard_Transient) - -private: - - //! Constructor is private - Standard_Type (const std::type_info& theInfo, const char* theName, - Standard_Size theSize, const Handle(Standard_Type)& theParent); - -private: - std::type_index myInfo; //!< Object to store system name of the class - Standard_CString myName; //!< Given name of the class - Standard_Size mySize; //!< Size of the class instance, in bytes - Handle(Standard_Type) myParent; //!< Type descriptor of parent class -}; - -namespace opencascade { - - //! Template class providing instantiation of type descriptors as singletons. - //! The descriptors are defined as static variables in function get(), which - //! is essential to ensure that they are initialized in correct sequence. - //! - //! For compilers that do not provide thread-safe initialization of static - //! variables (C++11 feature, N2660), additional global variable is - //! defined for each type to hold its type descriptor. These globals ensure - //! that all types get initialized during the library loading and thus no - //! concurrency occurs when type system is accessed from multiple threads. - template - class type_instance - { - static Handle(Standard_Type) myInstance; - public: - static const Handle(Standard_Type)& get (); - }; - - //! Specialization of type descriptor instance for void; returns null handle - template <> - class type_instance - { - public: - static Handle(Standard_Type) get () { return 0; } - }; - - // Implementation of static function returning instance of the - // type descriptor - template - const Handle(Standard_Type)& type_instance::get () - { -#if (defined(_MSC_VER) && _MSC_VER < 1900) || \ - (defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) && \ - ! defined(__clang__) && ! defined(__INTEL_COMPILER)) - // ensure that myInstance is instantiated - (void)myInstance; -#endif - - // static variable inside function ensures that descriptors - // are initialized in correct sequence - static Handle(Standard_Type) anInstance = - Standard_Type::Register (typeid(T), T::get_type_name(), sizeof(T), - type_instance::get()); - return anInstance; - } - - // Static class field is defined to ensure initialization of all type - // descriptors at load time of the library on compilers not supporting N2660: - // - VC++ below 14 (VS 2015) - // - GCC below 4.3 - // Intel compiler reports itself as GCC on Linux and VC++ on Windows, - // and is claimed to support N2660 on Linux and on Windows "in VS2015 mode". - // CLang should support N2660 since version 2.9, but it is not clear how to - // check its version reliably (on Linux it says it is GCC 4.2). -#if (defined(_MSC_VER) && _MSC_VER < 1900) || \ - (defined(__GNUC__) && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 3)) && \ - ! defined(__clang__) && ! defined(__INTEL_COMPILER)) - - template - Handle(Standard_Type) type_instance::myInstance (get()); - -#endif -} - -//! Operator printing type descriptor to stream -inline Standard_OStream& operator << (Standard_OStream& theStream, const Handle(Standard_Type)& theType) -{ - theType->Print (theStream); - return theStream; -} - -//! Definition of Handle_Standard_Type as typedef for compatibility -DEFINE_STANDARD_HANDLE(Standard_Type,Standard_Transient) + const Handle(Standard_Type)& Class::get_type_descriptor() \ + { \ + static const Handle(Standard_Type) THE_TYPE_INSTANCE(new Standard_Type(typeid(Class), get_type_name(), \ + sizeof(Class), Base::get_type_descriptor().get())); \ + return THE_TYPE_INSTANCE; \ + } \ + const Handle(Standard_Type)& Class::DynamicType() const { return get_type_descriptor(); } #endif // _Standard_Type_HeaderFile diff --git a/src/StepAP214/StepAP214_Protocol.cxx b/src/StepAP214/StepAP214_Protocol.cxx index 20841eb3ec..149f3cbc0a 100644 --- a/src/StepAP214/StepAP214_Protocol.cxx +++ b/src/StepAP214/StepAP214_Protocol.cxx @@ -756,7 +756,7 @@ static Standard_CString schemaAP242DIS = "AP242_MANAGED_MODEL_BASED_3D_ENGINEERI #include static int THE_StepAP214_Protocol_init = 0; -static Interface_DataMapOfTransientInteger types(819); +static NCollection_DataMap types(819); //======================================================================= //function : StepAP214_Protocol diff --git a/src/StepData/StepData_FileProtocol.cxx b/src/StepData/StepData_FileProtocol.cxx index 6a264f7c88..90a990d902 100644 --- a/src/StepData/StepData_FileProtocol.cxx +++ b/src/StepData/StepData_FileProtocol.cxx @@ -31,7 +31,7 @@ static Standard_CString thename = ""; void StepData_FileProtocol::Add (const Handle(StepData_Protocol)& protocol) { if (protocol.IsNull()) return; - Handle(Standard_Type) ptype = protocol->DynamicType(); + const Handle(Standard_Type)& ptype = protocol->DynamicType(); Standard_Integer nb = thecomps.Length(); for (Standard_Integer i = 1; i <= nb; i ++) { if (thecomps.Value(i)->IsInstance(ptype)) return; diff --git a/src/StepData/StepData_PDescr.cxx b/src/StepData/StepData_PDescr.cxx index cd5cb1f67d..68456062b3 100644 --- a/src/StepData/StepData_PDescr.cxx +++ b/src/StepData/StepData_PDescr.cxx @@ -84,7 +84,7 @@ StepData_PDescr::StepData_PDescr () { thekind = KindEntity; thetype = atype; thednam.Clear(); } void StepData_PDescr::SetDescr (const Standard_CString dscnam) - { thekind = KindEntity; thetype.Nullify(); + { thekind = KindEntity; thetype = Handle(Standard_Type)(); thednam.Clear(); thednam.AssignCat(dscnam); } void StepData_PDescr::AddArity (const Standard_Integer arity) diff --git a/src/StepFile/StepFile_Read.hxx b/src/StepFile/StepFile_Read.hxx index 56921cbe6e..2249d4e913 100644 --- a/src/StepFile/StepFile_Read.hxx +++ b/src/StepFile/StepFile_Read.hxx @@ -18,6 +18,7 @@ #define StepFile_Read_HeaderFile #include +#include #include #include diff --git a/src/StepVisual/StepVisual_CoordinatesList.cxx b/src/StepVisual/StepVisual_CoordinatesList.cxx index 7caab6b96c..ac83411114 100644 --- a/src/StepVisual/StepVisual_CoordinatesList.cxx +++ b/src/StepVisual/StepVisual_CoordinatesList.cxx @@ -14,7 +14,7 @@ #include #include -IMPLEMENT_STANDARD_RTTIEXT(StepVisual_CoordinatesList,StepGeom_TessellatedItem) +IMPLEMENT_STANDARD_RTTIEXT(StepVisual_CoordinatesList, StepVisual_TessellatedItem) StepVisual_CoordinatesList::StepVisual_CoordinatesList () {} diff --git a/src/StepVisual/StepVisual_TessellatedGeometricSet.cxx b/src/StepVisual/StepVisual_TessellatedGeometricSet.cxx index da4f391e21..c992bb4e15 100644 --- a/src/StepVisual/StepVisual_TessellatedGeometricSet.cxx +++ b/src/StepVisual/StepVisual_TessellatedGeometricSet.cxx @@ -15,7 +15,7 @@ #include -IMPLEMENT_STANDARD_RTTIEXT(StepVisual_TessellatedGeometricSet,StepGeom_TessellatedItem) +IMPLEMENT_STANDARD_RTTIEXT(StepVisual_TessellatedGeometricSet, StepVisual_TessellatedItem) StepVisual_TessellatedGeometricSet::StepVisual_TessellatedGeometricSet () {} diff --git a/src/TObj/TObj_Assistant.cxx b/src/TObj/TObj_Assistant.cxx index b8565a2c25..057d5d19ff 100644 --- a/src/TObj/TObj_Assistant.cxx +++ b/src/TObj/TObj_Assistant.cxx @@ -39,9 +39,9 @@ TColStd_SequenceOfTransient& TObj_Assistant::getModels() //purpose : //======================================================================= -TColStd_IndexedMapOfTransient& TObj_Assistant::getTypes() +NCollection_IndexedMap& TObj_Assistant::getTypes() { - static TColStd_IndexedMapOfTransient sTypes; + static NCollection_IndexedMap sTypes; return sTypes; } @@ -119,7 +119,7 @@ Handle(Standard_Type) TObj_Assistant::FindType (const Standard_Integer theTypeIndex) { if(theTypeIndex > 0 && theTypeIndex <= getTypes().Extent()) - return Handle(Standard_Type)::DownCast(getTypes().FindKey(theTypeIndex)); + return getTypes().FindKey(theTypeIndex); return 0; } @@ -166,12 +166,12 @@ DEFINE_STANDARD_HANDLE(TObj_Assistant_UnknownType,Standard_Transient) Standard_Integer TObj_Assistant::BindType (const Handle(Standard_Type)& theType) { - if(theType.IsNull()) - { - Handle(Standard_Transient) anUnknownType; - anUnknownType = new TObj_Assistant_UnknownType; - return getTypes().Add(anUnknownType); - } + // if(!theType) + // { + // Handle(Standard_Transient) anUnknownType; + // anUnknownType = new TObj_Assistant_UnknownType; + // return getTypes().Add(anUnknownType); + // } return getTypes().Add(theType); } diff --git a/src/TObj/TObj_Assistant.hxx b/src/TObj/TObj_Assistant.hxx index b26bb7772f..71987cdf5f 100644 --- a/src/TObj/TObj_Assistant.hxx +++ b/src/TObj/TObj_Assistant.hxx @@ -103,7 +103,7 @@ private: static Standard_EXPORT TColStd_SequenceOfTransient& getModels(); //! Method for taking fields for map types - static Standard_EXPORT TColStd_IndexedMapOfTransient& getTypes(); + static Standard_EXPORT NCollection_IndexedMap& getTypes(); //! Method for taking fields for the Current model static Standard_EXPORT Handle(TObj_Model)& getCurrentModel(); diff --git a/src/TObj/TObj_Object.cxx b/src/TObj/TObj_Object.cxx index d754de9620..19d4744866 100644 --- a/src/TObj/TObj_Object.cxx +++ b/src/TObj/TObj_Object.cxx @@ -1220,7 +1220,7 @@ Standard_Boolean TObj_Object::copyData (const Handle(TObj_Object)& theTargetObject) { Standard_Boolean IsDone = Standard_False; - if ( !theTargetObject->DynamicType()->SubType( DynamicType() ) ) + if ( !theTargetObject->IsKind( DynamicType() ) ) return IsDone; // init the copier by labels. TDF_Label aDataLabel = GetDataLabel(); diff --git a/src/Transfer/Transfer_TransferIterator.cxx b/src/Transfer/Transfer_TransferIterator.cxx index 7d81b210d0..062bbe16f4 100644 --- a/src/Transfer/Transfer_TransferIterator.cxx +++ b/src/Transfer/Transfer_TransferIterator.cxx @@ -51,17 +51,13 @@ static Handle(Standard_Transient) nultrans; // pour retour const&(Null) void Transfer_TransferIterator::SelectResult (const Handle(Standard_Type)& atype, const Standard_Boolean keep) { - Standard_Integer casetype = 0; - if (atype->SubType(STANDARD_TYPE(Standard_Transient))) casetype = 2; - for (Standard_Integer i = theitems->Length(); i > 0; i --) { Handle(Transfer_Binder) atr = theitems->Value(i); Handle(Standard_Type) btype = ResultType(); Standard_Boolean matchtype; if (!atr->HasResult()) matchtype = Standard_False; else if (atr->IsMultiple()) matchtype = Standard_False; - else if (casetype == 0) matchtype = (atype == btype); // Type fixe - else matchtype = (btype->SubType(atype)); // Dynamique + else matchtype = (btype->SubType(atype)); if (matchtype != keep) { theselect->SetValue(i,0); if (themaxi == i) themaxi = i-1; @@ -154,8 +150,7 @@ static Handle(Standard_Transient) nultrans; // pour retour const&(Null) Standard_Boolean Transfer_TransferIterator::HasTransientResult () const { Handle(Standard_Type) btype = ResultType(); - if (btype.IsNull()) return Standard_False; - return btype->SubType(STANDARD_TYPE(Standard_Transient)); + return !btype.IsNull(); } const Handle(Standard_Transient)& diff --git a/src/XCAFDoc/XCAFDoc_NotesTool.cxx b/src/XCAFDoc/XCAFDoc_NotesTool.cxx index 28f46daa1a..3ad294c1ca 100644 --- a/src/XCAFDoc/XCAFDoc_NotesTool.cxx +++ b/src/XCAFDoc/XCAFDoc_NotesTool.cxx @@ -36,7 +36,7 @@ namespace { } -IMPLEMENT_DERIVED_ATTRIBUTE(XCAFDoc_NotesTool, XCAFDoc_NoteComment) +IMPLEMENT_DERIVED_ATTRIBUTE(XCAFDoc_NotesTool, TDataStd_GenericEmpty) enum NotesTool_RootLabels { diff --git a/src/XSControl/XSControl_Utils.cxx b/src/XSControl/XSControl_Utils.cxx index 304ec8110d..ba00dd6712 100644 --- a/src/XSControl/XSControl_Utils.cxx +++ b/src/XSControl/XSControl_Utils.cxx @@ -112,8 +112,7 @@ static const Standard_ExtString voidext = { 0 }; (const Handle(Standard_Transient)& item, const Standard_Boolean nopk) const { if (item.IsNull()) return ""; - DeclareAndCast(Standard_Type,atype,item); - if (atype.IsNull()) atype = item->DynamicType(); + Handle(Standard_Type) atype = item->DynamicType(); Standard_CString tn = atype->Name(); if (!nopk) return tn; for (int i = 0; tn[i] != '\0'; i ++) { diff --git a/src/XmlMDataStd/XmlMDataStd_GenericEmptyDriver.cxx b/src/XmlMDataStd/XmlMDataStd_GenericEmptyDriver.cxx index 511a5447c6..f0817540fe 100644 --- a/src/XmlMDataStd/XmlMDataStd_GenericEmptyDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_GenericEmptyDriver.cxx @@ -46,7 +46,7 @@ Handle(TDF_Attribute) XmlMDataStd_GenericEmptyDriver::NewEmpty() const //======================================================================= Handle(Standard_Type) XmlMDataStd_GenericEmptyDriver::SourceType() const { - return Standard_Type::Instance(); + return STANDARD_TYPE(TDataStd_GenericEmpty); } //======================================================================= diff --git a/src/XmlMDataStd/XmlMDataStd_GenericExtStringDriver.cxx b/src/XmlMDataStd/XmlMDataStd_GenericExtStringDriver.cxx index 3b8bf7a597..132ccd6d1e 100644 --- a/src/XmlMDataStd/XmlMDataStd_GenericExtStringDriver.cxx +++ b/src/XmlMDataStd/XmlMDataStd_GenericExtStringDriver.cxx @@ -48,7 +48,7 @@ Handle(TDF_Attribute) XmlMDataStd_GenericExtStringDriver::NewEmpty () const //======================================================================= Handle(Standard_Type) XmlMDataStd_GenericExtStringDriver::SourceType() const { - return Standard_Type::Instance(); + return STANDARD_TYPE(TDataStd_GenericExtString); } //=======================================================================