[commit] r1864 - in trunk/GME: ConstraintManager Mga
GMESRC Repository Notifications
gme-commit at list.isis.vanderbilt.edu
Thu Mar 22 15:20:48 CDT 2012
Author: ksmyth
Date: Thu Mar 22 15:20:47 2012
New Revision: 1864
Log:
Fix some memory leaks
Modified:
trunk/GME/ConstraintManager/OCLTree.cpp
trunk/GME/ConstraintManager/OCLType.cpp
trunk/GME/ConstraintManager/OCLType.h
trunk/GME/ConstraintManager/OclViolation.h
trunk/GME/Mga/MgaProject.cpp
Modified: trunk/GME/ConstraintManager/OCLTree.cpp
==============================================================================
--- trunk/GME/ConstraintManager/OCLTree.cpp Tue Mar 13 15:28:39 2012 (r1863)
+++ trunk/GME/ConstraintManager/OCLTree.cpp Thu Mar 22 15:20:47 2012 (r1864)
@@ -98,7 +98,7 @@
bool bValid = true;
for ( unsigned int i = 0 ; i < vecType.size() ; i++ ) {
try {
- OclMeta::Type* pType = m_pManager->GetTypeManager()->GetType( vecType[ i ], context.m_namespace);
+ std::shared_ptr<OclMeta::Type> pType = m_pManager->GetTypeManager()->GetType( vecType[ i ], context.m_namespace);
if ( i != vecType.size() - 1 ) {
if ( ! pType->IsCompound() ) {
ADDEX( EXCEPTION1( EX_TYPE_ISNT_COMPOUND, vecType[ i ], position ) );
@@ -1183,7 +1183,7 @@
bool IteratorNode::CheckIterator( TypeContext& context )
{
- OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 0 ], context.m_namespace );
+ std::shared_ptr<OclMeta::Type> pType = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 0 ], context.m_namespace );
// Not compound Type cannot have iterators
@@ -1260,7 +1260,7 @@
// It is predefined iterator
try {
- OclMeta::CompoundType* pCType = (OclMeta::CompoundType*) pType;
+ OclMeta::CompoundType* pCType = (OclMeta::CompoundType*) pType.get();
OclMeta::Iterator* pIterator = pCType->GetIterator(0, OclSignature::Iterator( m_strName, m_pThisNode->m_vecType[ 0 ], m_pArgumentNode->m_vecType[ 0 ] ) );
GetParametralTypeSeq( m_pThisNode->m_vecType, m_pArgumentNode->m_vecType, pIterator->GetReturnTypeSeq() );
}
@@ -1316,7 +1316,7 @@
EVALTRY {
OclImplementation::Iterator* pIIterator = NULL;
if ( ! m_pAccuNode ) {
- OclMeta::CompoundType* pCType = (OclMeta::CompoundType*) GetTreeManager()->GetTypeManager()->GetType( objectThis.GetStaticTypeName(), NILNAMESPACE );
+ OclMeta::CompoundType* pCType = (OclMeta::CompoundType*) GetTreeManager()->GetTypeManager()->GetType( objectThis.GetStaticTypeName(), NILNAMESPACE ).get();
OclMeta::Iterator* pIterator = pCType->GetIterator(m_iteratorLevel, signature );
pIIterator = pIterator->GetImplementation();
if ( ! pIIterator )
@@ -1467,7 +1467,7 @@
if ( bThisValid ) {
- OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 0 ], context.m_namespace );
+ OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 0 ], context.m_namespace ).get();
// Check if Object Node is callable
@@ -1695,7 +1695,7 @@
return OclMeta::Object::UNDEFINED;
EVALTRY {
- OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( objectThis.GetStaticTypeName(), NILNAMESPACE );
+ OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( objectThis.GetStaticTypeName(), NILNAMESPACE ).get();
OclMeta::Method* pMethod = pType->GetMethod( signature );
OclImplementation::Method* pIMethod = pMethod->GetImplementation();
if ( ! pIMethod )
@@ -1991,7 +1991,7 @@
bool AssociationNode::CheckAssociation( TypeContext& context )
{
- OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 0 ], context.m_namespace );
+ OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 0 ], context.m_namespace ).get();
// Check static object can be called
@@ -2032,7 +2032,7 @@
return objectThis;
EVALTRY {
- OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( objectThis.GetStaticTypeName(), NILNAMESPACE );
+ OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( objectThis.GetStaticTypeName(), NILNAMESPACE ).get();
OclMeta::Association* pAssociation = pType->GetAssociation( signature );
OclImplementation::Association* pIAssociation = pAssociation->GetImplementation();
if ( ! pIAssociation )
@@ -2119,7 +2119,7 @@
if ( bThisValid ) {
- OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 0 ], context.m_namespace );
+ OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 0 ], context.m_namespace ).get();
// Type is not compound
@@ -2187,7 +2187,7 @@
// Create Feature Call Check
- OclMeta::Type* pTypeInner = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 1 ], context.m_namespace );
+ OclMeta::Type* pTypeInner = GetTreeManager()->GetTypeManager()->GetType( m_pThisNode->m_vecType[ 1 ], context.m_namespace ).get();
std::vector<OclMeta::Type*> vecTypes( 2, pType ); vecTypes[ 1 ] = pTypeInner;
@@ -2269,7 +2269,7 @@
return objectThis;
EVALTRY {
- OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( objectThis.GetStaticTypeName(), NILNAMESPACE );
+ OclMeta::Type* pType = GetTreeManager()->GetTypeManager()->GetType( objectThis.GetStaticTypeName(), NILNAMESPACE ).get();
OclMeta::Attribute* pAttribute = pType->GetAttribute( signature );
OclImplementation::Attribute* pIAttribute = pAttribute->GetImplementation();
if ( ! pIAttribute )
@@ -2700,7 +2700,7 @@
// Check if this object is Compound
if ( bValid ) {
- OclMeta::Type* pType = pNode->GetTreeManager()->GetTypeManager()->GetType( pNode->m_vecType[ 0 ], context.m_namespace );
+ OclMeta::Type* pType = pNode->GetTreeManager()->GetTypeManager()->GetType( pNode->m_vecType[ 0 ], context.m_namespace ).get();
if ( ! pType->IsCompound() ) {
ADDEX( EXCEPTION1( EX_TYPE_ISNT_COMPOUND, pNode->m_vecType[ 0 ], pNode->m_mapPositions[ LID_NODE_START ] ) );
bValid = false;
Modified: trunk/GME/ConstraintManager/OCLType.cpp
==============================================================================
--- trunk/GME/ConstraintManager/OCLType.cpp Tue Mar 13 15:28:39 2012 (r1863)
+++ trunk/GME/ConstraintManager/OCLType.cpp Thu Mar 22 15:20:47 2012 (r1864)
@@ -145,7 +145,7 @@
{
for ( unsigned int i = 0 ; i < vecSuperTypes.size() ; i++ ) {
try {
- Type* pType = pManager->GetType( vecSuperTypes[ i ], NILNAMESPACE );
+ std::shared_ptr<Type> pType = pManager->GetType( vecSuperTypes[ i ], NILNAMESPACE );
callResult = pType->GetResults( signature );
if ( callResult.bIsValid )
vecArg.push_back( (TFeature*) callResult.uResult.pFeature );
@@ -197,11 +197,6 @@
void TypeManager::ClearTypes()
{
- for ( TypeResultMap::iterator i = m_mapTypes.begin() ; i != m_mapTypes.end() ; ++i )
- if ( (*i).second.bIsValid )
- delete (*i).second.uResult.pType;
- else
- delete (*i).second.uResult.pException;
m_mapTypes.clear();
}
@@ -211,12 +206,12 @@
m_mapTypes.clear();
for ( TypeResultMap::iterator i = mapTypes.begin() ; i != mapTypes.end() ; ++i )
if ( ! (*i).second.bIsValid )
- delete (*i).second.uResult.pException;
+ i->second.pException.reset();
else
- if ( (*i).second.uResult.pType->IsDynamic() )
- delete (*i).second.uResult.pType;
+ if ( (*i).second.pType->IsDynamic() )
+ i->second.pType.reset();
else
- m_mapTypes.insert( TypeResultMap::value_type( (*i).first, (*i).second ) );
+ m_mapTypes.insert( TypeResultMap::value_type( std::move((*i).first), std::move((*i).second) ) );
}
void TypeManager::ClearGlobals()
@@ -231,15 +226,15 @@
ClearGlobals();
}
- Type* TypeManager::GetType( const std::string& strName, const std::string& strNSpace )
+ std::shared_ptr<Type> TypeManager::GetType( const std::string& strName, const std::string& strNSpace )
{
std::string nameResult;
TypeResultMap::iterator i = m_mapTypes.find( strName );
if ( i != m_mapTypes.end() ) {
if ( (*i).second.bIsValid )
- return (*i).second.uResult.pType;
+ return (*i).second.pType;
else
- throw OclCommon::Exception( *(*i).second.uResult.pException );
+ throw OclCommon::Exception( *(*i).second.pException );
}
TypeVector vecTypes;
TypeResult typeResult;
@@ -247,34 +242,35 @@
m_pTypeFactory->GetTypes( strName, strNSpace, vecTypes, nameResult );
if ( vecTypes.empty() ) {
typeResult.bIsValid = false;
- typeResult.uResult.pException = new OclCommon::Exception( OclCommon::Exception::ET_SEMANTIC, EX_TYPE_DOESNT_EXIST, strName );
+ typeResult.pException = std::shared_ptr<OclCommon::Exception>(new OclCommon::Exception( OclCommon::Exception::ET_SEMANTIC, EX_TYPE_DOESNT_EXIST, strName ));
}
else {
if ( vecTypes.size() > 1 ) {
typeResult.bIsValid = false;
- typeResult.uResult.pException = new OclCommon::Exception( OclCommon::Exception::ET_SEMANTIC, EX_TYPE_AMBIGUOUS, strName );
+ typeResult.pException = std::shared_ptr<OclCommon::Exception>(new OclCommon::Exception( OclCommon::Exception::ET_SEMANTIC, EX_TYPE_AMBIGUOUS, strName ));
}
else {
typeResult.bIsValid = true;
- typeResult.uResult.pType = vecTypes[ 0 ].release();
+ typeResult.pType = std::shared_ptr<Type>(vecTypes[ 0 ].release());
}
}
}
catch ( OclCommon::Exception ex ) {
typeResult.bIsValid = false;
- typeResult.uResult.pException = new OclCommon::Exception( ex );
+ typeResult.pException = std::shared_ptr<OclCommon::Exception>(new OclCommon::Exception( ex ));
}
- m_mapTypes.insert( TypeResultMap::value_type( nameResult, typeResult ) ); // WAS: m_mapTypes.insert( TypeResultMap::value_type( strName, typeResult ) );
+ TypeResultMap::iterator it = m_mapTypes.insert( TypeResultMap::value_type( std::move(nameResult), std::move(typeResult) ) ).first;
+ // WAS: m_mapTypes.insert( TypeResultMap::value_type( strName, typeResult ) );
RegisterType( typeResult );
if ( typeResult.bIsValid )
- return typeResult.uResult.pType;
+ return typeResult.pType;
else
- throw OclCommon::Exception( *typeResult.uResult.pException );
+ throw OclCommon::Exception( *typeResult.pException );
}
int TypeManager::IsTypeAR( const std::string& strName1, const std::string& strName2, int iLevel )
{
- Type* pType1 = GetType( strName1, NILNAMESPACE );
+ std::shared_ptr<Type> pType1 = GetType( strName1, NILNAMESPACE );
if ( pType1->GetName() == strName2 )
return iLevel;
const StringVector& vecSuperTypes = pType1->GetSuperTypeNames();
@@ -289,13 +285,13 @@
int TypeManager::IsTypeA( const std::string& strName1, const std::string& strName2 )
{
- Type* pType2 = GetType( strName2, NILNAMESPACE );
+ std::shared_ptr<Type> pType2 = GetType( strName2, NILNAMESPACE );
return IsTypeAR( strName1, pType2->GetName(), 0 );
}
int TypeManager::GetTypeDistance( const std::string& strName )
{
- Type* pType = GetType( ( strName.empty() ) ? "ocl::Any" : strName, NILNAMESPACE );
+ std::shared_ptr<Type> pType = GetType( ( strName.empty() ) ? "ocl::Any" : strName, NILNAMESPACE );
const StringVector& vecSuperTypes = pType->GetSuperTypeNames();
if ( vecSuperTypes.empty() )
return 0;
@@ -469,12 +465,12 @@
void TypeManager::RegisterType( TypeResult& typeResult )
{
if ( typeResult.bIsValid ) {
- typeResult.uResult.pType->m_pTypeManager = this;
- typeResult.uResult.pType->m_pAttributeFactory->m_pTypeManager = this;
- typeResult.uResult.pType->m_pAssociationFactory->m_pTypeManager = this;
- typeResult.uResult.pType->m_pMethodFactory->m_pTypeManager = this;
- if ( typeResult.uResult.pType->IsCompound() )
- ( (CompoundType*) typeResult.uResult.pType )->m_pIteratorFactory->m_pTypeManager = this;
+ typeResult.pType->m_pTypeManager = this;
+ typeResult.pType->m_pAttributeFactory->m_pTypeManager = this;
+ typeResult.pType->m_pAssociationFactory->m_pTypeManager = this;
+ typeResult.pType->m_pMethodFactory->m_pTypeManager = this;
+ if ( typeResult.pType->IsCompound() )
+ ( (CompoundType*) typeResult.pType.get() )->m_pIteratorFactory->m_pTypeManager = this;
}
}
Modified: trunk/GME/ConstraintManager/OCLType.h
==============================================================================
--- trunk/GME/ConstraintManager/OCLType.h Tue Mar 13 15:28:39 2012 (r1863)
+++ trunk/GME/ConstraintManager/OCLType.h Thu Mar 22 15:20:47 2012 (r1864)
@@ -34,16 +34,11 @@
UCallResult uResult;
};
- union UTypeResult
- {
- Type* pType;
- OclCommon::Exception* pException;
- };
-
struct TypeResult
{
bool bIsValid;
- UTypeResult uResult;
+ std::shared_ptr<Type> pType;
+ std::shared_ptr<OclCommon::Exception> pException;
};
typedef std::map< std::string , CallResult > CallResultMap;
@@ -81,7 +76,7 @@
void ClearDynamicTypes();
void ClearGlobals();
- Type* GetType( const std::string& strName, const std::string& strNSpace );
+ std::shared_ptr<Type> GetType( const std::string& strName, const std::string& strNSpace );
int GetTypeDistance( const std::string& strName );
int IsTypeA( const std::string& strName1, const std::string& strName2 );
Modified: trunk/GME/ConstraintManager/OclViolation.h
==============================================================================
--- trunk/GME/ConstraintManager/OclViolation.h Tue Mar 13 15:28:39 2012 (r1863)
+++ trunk/GME/ConstraintManager/OclViolation.h Thu Mar 22 15:20:47 2012 (r1864)
@@ -40,8 +40,8 @@
}
}
clear();
- int lenx = vect.size();
- for (int kk=0; kk<lenx; kk++)
+ size_t lenx = vect.size();
+ for (size_t kk=0; kk<lenx; kk++)
{
IUnknown *ptr = vect[kk];
if (ptr)
Modified: trunk/GME/Mga/MgaProject.cpp
==============================================================================
--- trunk/GME/Mga/MgaProject.cpp Tue Mar 13 15:28:39 2012 (r1863)
+++ trunk/GME/Mga/MgaProject.cpp Thu Mar 22 15:20:47 2012 (r1864)
@@ -304,6 +304,7 @@
}
else {
COMTHROW(OpenParadigm(s,&pGUID));
+ ver.Empty();
COMTHROW(metapr->get_Version(&ver));
}
bool guidchanged = false;
More information about the gme-commit
mailing list