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

0024947: Redesign OCCT legacy type system

Global static functions instantiating RTTI descriptors for class types (used though STANDARD_TYPE macro) are replaced by template static method Instance() of the class Standard_Type.
Implementation of RTTI is revised accordingly (global registry of type descriptors added to ensure single instance of each type descriptor shared by all dynamic libraries).
Obsolete methods of Standard_Type class (IsInstance(), Ancestors()) are removed; new method Parent() is added returning type descriptor of the parent class.
Class Standard_AncestorIterator is removed; this iteration can be easily done by recursive calls to Standard_Type::Parent().

Definition of macro STANDARD_TYPE() moved from Standard_Macro.hxx to Standard_DefineHandle.hxx.
Inclusion of Standard_Type.hxx and the class header is now necessary for use of method DownCast() and function STANDARD_TYPE() for the class.
In general, Standard_Type.hxx should be included now instead of Standard_DefineHandle.hxx in places where these macros are used.

Macro DEFINE_STANDARD_EXCEPTION changed to define all methods inline; macro IMPLEMENT_STANDARD_EXCEPTION becomes obsolete.
Macros IMPLEMENT_DOWNCAST, IMPLEMENT_STANDARD_* become deprecated, they are still defined (as empty) for compatibility.

Implementation of Handle classes became fully inline.
Method get() is added in Handle classes returning pointer to the contained object.

RTTI removed from NCollection_Handle class.

Standard_Persistent is made empty descendant of Standard_Transient, instead of implementing its own hierarchy with reference counting.

Unused enumerations Standard_InternalType, Standard_WayOfLife, Standard_KindOfType are removed.
Global function HashCode() accepting Handle(Standard_Transient) is removed; HashCode() for Standard_CString with length should be used instead.

DRAW command dtryload is added for testing dynamic load / unload of the specified library.
New test perf fclasses bug24947 uses this command to measure performance of multiple (1000 times) loading / unloading OCCT libs on example of TKSTEP.
This commit is contained in:
abv
2015-05-22 06:40:28 +03:00
parent 4052fe71d9
commit 69ff08ff28
38 changed files with 435 additions and 1226 deletions

View File

@@ -14,21 +14,3 @@
// commercial license or contractual agreement.
#include <NCollection_Handle.hxx>
// NOTE: OCCT type information functions are defined explicitly
// instead of using macros from Standard_DefineHandle.hxx,
// since class NCollection_Handle is template and this is not supported
static Handle(Standard_Type) aTypeNCollection_Handle =
STANDARD_TYPE(NCollection_Handle);
const Handle(Standard_Type)& STANDARD_TYPE(NCollection_Handle)
{
static Handle(Standard_Transient) _Ancestors[] =
{ STANDARD_TYPE(Standard_Transient), NULL, };
static Handle(Standard_Type) _aType =
new Standard_Type("NCollection_Handle",
sizeof(NCollection_Handle<Standard_Transient>),
1, (Standard_Address)_Ancestors, (Standard_Address)NULL);
return _aType;
}

View File

@@ -17,9 +17,6 @@
#define NCollection_Handle_HeaderFile
#include <MMgt_TShared.hxx>
//! Standard type function allowing to check that contained object is Handle
Standard_EXPORT const Handle(Standard_Type)& STANDARD_TYPE(NCollection_Handle);
//! Purpose: This template class is used to define Handle adaptor
//! for allocated dynamically objects of arbitrary type.
@@ -28,20 +25,6 @@ Standard_EXPORT const Handle(Standard_Type)& STANDARD_TYPE(NCollection_Handle);
//! the object when last referred Handle is destroyed (i.e. it is a
//! typical smart pointer), and that it can be handled as
//! Handle(Standard_Transient) in OCCT components.
//!
//! Use it as follows:
//!
//! NCollection_Handle<T> aPtr = new T (...);
//!
//! aPtr->Method(...);
//!
//! Handle(Standard_Transient) aBase = aPtr;
//! if ( aBase->IsKind(STANDARD_TYPE(NCollection_Handle)) )
//! {
//! NCollection_Handle<T> aPtr2 = NCollection_Handle<T>::DownCast (aBase);
//! if ( ! aPtr2.IsNull() )
//! aPtr2->Method2();
//! }
template <class T>
class NCollection_Handle : public Handle(Standard_Transient)
@@ -61,10 +44,6 @@ class NCollection_Handle : public Handle(Standard_Transient)
//! Destructor deletes the object
~Ptr () { if ( myPtr ) delete myPtr; myPtr = 0; }
//! Implementation of DynamicType() method
const Handle(Standard_Type)& DynamicType() const
{ return STANDARD_TYPE(NCollection_Handle); }
protected:
//! Copy constructor
@@ -108,10 +87,11 @@ class NCollection_Handle : public Handle(Standard_Transient)
//! Downcast arbitrary Handle to the argument type if contained
//! object is Handle for this type; returns null otherwise
static NCollection_Handle<T> DownCast (const Handle(Standard_Transient)& theOther)
static NCollection_Handle<T> DownCast (const Handle(Standard_Transient)& theOther)
{
return NCollection_Handle<T> (theOther.IsNull() ? 0 : dynamic_cast<Ptr*> (theOther.operator->()), 0);
return NCollection_Handle<T>(dynamic_cast<Ptr*>(theOther.get()), 0);
}
};
#endif