Delete STEPattributes from sdaiApplication_instance::attributes.

* The attributes list content from sdaiApplication_instance never got
  deleted, added clean up code to sdaiApplication_instance destructor.
* Added refCount to STEPattribute to prevent multiple deletions of the
  same instance in case an instance is added to attributes more than once.
This commit is contained in:
davyw
2012-04-05 20:40:04 +02:00
parent a9173c8b41
commit c77471a5f8
4 changed files with 23 additions and 10 deletions
+1
View File
@@ -90,6 +90,7 @@ class SCL_CORE_EXPORT STEPattribute {
public:
const AttrDescriptor * aDesc;
int refCount;
/** \union ptr
** You know which of these to use based on the return value of
+10 -10
View File
@@ -18,32 +18,32 @@
/// This is needed so that STEPattribute's can be passed as references to inline functions
STEPattribute::STEPattribute( const STEPattribute & a )
: _derive( 0 ), _redefAttr( 0 ), aDesc( a.aDesc ) {}
: _derive( 0 ), _redefAttr( 0 ), aDesc( a.aDesc ), refCount( 0 ) {}
/// INTEGER
STEPattribute::STEPattribute( const class AttrDescriptor & d, SDAI_Integer * p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.i = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
/// BINARY
STEPattribute::STEPattribute( const class AttrDescriptor & d, SDAI_Binary * p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.b = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
/// STRING
STEPattribute::STEPattribute( const class AttrDescriptor & d, SDAI_String * p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.S = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
/// REAL & NUMBER
STEPattribute::STEPattribute( const class AttrDescriptor & d, SDAI_Real * p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.r = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
@@ -51,21 +51,21 @@ STEPattribute::STEPattribute( const class AttrDescriptor & d, SDAI_Real * p )
/// ENTITY
STEPattribute::STEPattribute( const class AttrDescriptor & d,
SDAI_Application_instance* *p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.c = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
/// AGGREGATE
STEPattribute::STEPattribute( const class AttrDescriptor & d, STEPaggregate * p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.a = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
/// ENUMERATION and Logical
STEPattribute::STEPattribute( const class AttrDescriptor & d, SDAI_Enum * p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.e = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
@@ -73,14 +73,14 @@ STEPattribute::STEPattribute( const class AttrDescriptor & d, SDAI_Enum * p )
/// SELECT
STEPattribute::STEPattribute( const class AttrDescriptor & d,
class SDAI_Select * p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.sh = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
/// UNDEFINED
STEPattribute::STEPattribute( const class AttrDescriptor & d, SCLundefined * p )
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ) {
: _derive( 0 ), _redefAttr( 0 ), aDesc( &d ), refCount( 0 ) {
ptr.u = p;
assert( &d ); //ensure that the AttrDescriptor is not a null pointer
}
+1
View File
@@ -65,6 +65,7 @@ void STEPattributeList::push( STEPattribute * a ) {
}
if( push ) {
a->refCount ++;
AttrListNode * saln = new AttrListNode( a );
AppendNode( saln );
}
@@ -40,7 +40,18 @@ SDAI_Application_instance::SDAI_Application_instance( int fileid, int complex )
}
SDAI_Application_instance::~SDAI_Application_instance() {
STEPattribute *attr;
ResetAttributes();
do {
attr = NextAttribute();
if (attr) {
attr->refCount --;
if (attr->refCount <= 0)
delete attr;
}
} while (attr);
if( MultipleInheritance() ) {
delete nextMiEntity;