1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +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

@@ -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: