[commit] r1280 - trunk/GME/Core

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Mon Apr 25 14:41:45 CDT 2011


Author: ksmyth
Date: Mon Apr 25 14:41:45 2011
New Revision: 1280

Log:
Dont needlessy create and populate a list

Modified:
   trunk/GME/Core/CoreObject.cpp
   trunk/GME/Core/CoreObject.h

Modified: trunk/GME/Core/CoreObject.cpp
==============================================================================
--- trunk/GME/Core/CoreObject.cpp	Mon Apr 25 14:41:08 2011	(r1279)
+++ trunk/GME/Core/CoreObject.cpp	Mon Apr 25 14:41:45 2011	(r1280)
@@ -437,8 +437,8 @@
 	attributes.erase(i);
 }
 
-void CCoreObject::GetAttributes(CCoreLockAttribute *lockattribute, 
-	std::list<CCoreAttribute*> &controlled)
+template<class Functor, class UnwindFunctor>
+void CCoreObject::GetAttributes(CCoreLockAttribute *lockattribute, Functor& f, UnwindFunctor& uf)
 {
 	ASSERT( lockattribute != NULL );
 	ASSERT( controlled.empty() );
@@ -449,51 +449,36 @@
 
 	attributes_iterator i = attributes.begin();
 	attributes_iterator e = attributes.end();
-	while( i != e )
+	try
 	{
+		while( i != e )
+		{
 
 #ifdef _DEBUG
-		attrid_type lockattrid = ATTRID_NONE;
-		ASSERT( (*i)->GetMetaAttribute()->get_LockAttrID(&lockattrid) == S_OK );
+			attrid_type lockattrid = ATTRID_NONE;
+			ASSERT( (*i)->GetMetaAttribute()->get_LockAttrID(&lockattrid) == S_OK );
 #endif
 
-		if( (*i)->GetLockAttr() == lockattribute )
-		{
-			ASSERT( lockattrid == attrid );
-			controlled.push_back( *i );
-		}
-
-		++i;
-	}
-}
-
-void CCoreObject::LoadAttributes(CCoreLockAttribute *lockattribute)
-{
-	ASSERT( lockattribute != NULL );
-
-
-	std::list<CCoreAttribute*> controlled;
-	GetAttributes(lockattribute, controlled);
-
-	attributes_iterator i = controlled.begin();
-	attributes_iterator e = controlled.end();
-
-	try
-	{
-		while( i != e )
-		{
-			(*i)->Load();
+			if( (*i)->GetLockAttr() == lockattribute )
+			{
+				ASSERT( lockattrid == attrid );
+				f(*i);
+			}
 
 			++i;
 		}
 	}
-	catch(hresult_exception &)
+	catch(hresult_exception&)
 	{
 		e = i;
-		i = controlled.begin();
+		i = attributes.begin();
 		while( i != e )
 		{
-			(*i)->Unload();
+			if( (*i)->GetLockAttr() == lockattribute )
+			{
+				ASSERT( lockattrid == attrid );
+				uf(*i);
+			}
 
 			++i;
 		}
@@ -502,21 +487,20 @@
 	}
 }
 
-void CCoreObject::UnloadAttributes(CCoreLockAttribute *lockattribute)
+void CCoreObject::LoadAttributes(CCoreLockAttribute *lockattribute)
 {
 	ASSERT( lockattribute != NULL );
 
-	std::list<CCoreAttribute*> controlled;
-	GetAttributes(lockattribute, controlled);
+	GetAttributes(lockattribute, [](CCoreAttribute* i){ i->Load(); },
+		[](CCoreAttribute* i){ i->Unload(); }
+	);
+}
 
-	attributes_iterator i = controlled.begin();
-	attributes_iterator e = controlled.end();
-	while( i != e )
-	{
-		(*i)->Unload();
+void CCoreObject::UnloadAttributes(CCoreLockAttribute *lockattribute)
+{
+	ASSERT( lockattribute != NULL );
 
-		++i;
-	}
+	GetAttributes(lockattribute, [](CCoreAttribute* i){ i->Unload(); }, [](CCoreAttribute* i){});
 }
 
 // ------- Status

Modified: trunk/GME/Core/CoreObject.h
==============================================================================
--- trunk/GME/Core/CoreObject.h	Mon Apr 25 14:41:08 2011	(r1279)
+++ trunk/GME/Core/CoreObject.h	Mon Apr 25 14:41:45 2011	(r1280)
@@ -110,8 +110,8 @@
 	void RegisterAttribute(CCoreAttribute *attribute) NOTHROW;
 	void UnregisterAttribute(CCoreAttribute *attribute) NOTHROW;
 
-	void GetAttributes(CCoreLockAttribute *lockattribute,
-		std::list<CCoreAttribute*> &controlled) NOTHROW;
+	template<class Functor, class UnwindFunctor>
+	void GetAttributes(CCoreLockAttribute *lockattribute, Functor& f, UnwindFunctor& uf);
 
 	void LoadAttributes(CCoreLockAttribute *lockattribute);
 	void UnloadAttributes(CCoreLockAttribute *lockattribute) NOTHROW;


More information about the gme-commit mailing list