1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-18 14:27:39 +03:00

Avoid recurrence in implicit instantiation of type descriptors

This commit is contained in:
abv
2015-11-29 16:33:05 +03:00
parent 40cf53299e
commit 2411731d34
3 changed files with 20 additions and 9 deletions

View File

@@ -23,11 +23,16 @@ void Standard_Transient::Delete() const
delete this; 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 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"; } 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; Standard_EXPORT virtual const opencascade::handle<Standard_Type>& DynamicType() const;
//! Returns a true value if this is an instance of Type. //! Returns a true value if this is an instance of Type.

View File

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