[GME-commit] GMESRC/GME/Mga MgaLibOps.h,1.3,1.4 MgaLibOps.cpp,1.14,1.15 MgaLibRefr.h,1.1,1.2 MgaLibRefr.cpp,1.2,1.3

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Thu Jan 18 16:54:12 CST 2007


Update of /project/gme-repository/GMESRC/GME/Mga
In directory escher:/tmp/cvs-serv803

Modified Files:
	MgaLibOps.h MgaLibOps.cpp MgaLibRefr.h MgaLibRefr.cpp 
Log Message:
Library refresh modified according to 'optimized' library load logic.
Try not to presume that libraries are nested if any relationship exists among them.




CVS User: Zoltan Molnar, ISIS (zolmol)

Index: MgaLibRefr.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Mga/MgaLibRefr.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** MgaLibRefr.cpp	18 Jan 2007 16:47:50 -0000	1.2
--- MgaLibRefr.cpp	18 Jan 2007 16:54:10 -0000	1.3
***************
*** 2219,2222 ****
--- 2219,2263 ----
  }
  
+ void RefreshManager::reapplyLibFlagToChangedLibs()
+ {
+ 	ASSERT( m_mgaproject);
+ 	if( !m_mgaproject) return;
+ 
+ 	CComPtr<IMgaFolder> root_fld;
+ 	COMTHROW( m_mgaproject->get_RootFolder( &root_fld));
+ 	CoreObj root_cor( root_fld);
+ 	ASSERT( root_cor);
+ 
+ 	CComBSTR id; // the refreshed library's id
+ 	COMTHROW( ObjForCore( m_newLib)->get_ID( &id));
+ 
+ 	for( std::vector<BinGuid>::iterator it = m_changedLibs.begin()
+ 		; it != m_changedLibs.end()
+ 		; ++it)
+ 	{
+ 		CoreObj libroot = SearchTool::findLibrary( root_cor, *it);
+ 		ASSERT( libroot);
+ 		if( libroot)
+ 		{
+ 			// this lib may have gotten new elements during refresh
+ 			applyLibFlag( libroot);
+ 
+ 			// add the dependency info to the includes list
+ 			Ozer::addIncludes( libroot, id);
+ 		}
+ 	}
+ }
+ 
+ void RefreshManager::applyLibFlag( CoreObj& p_libObj)
+ {
+ 	// for all children
+ 	CoreObjs kids = p_libObj[ATTRID_FCOPARENT + ATTRID_COLLECTION];
+ 	ITERATE_THROUGH(kids) {
+ 		ITER[ATTRID_PERMISSIONS] = ITER[ATTRID_PERMISSIONS] | LIBRARY_FLAG;
+ 
+ 		if( ITER.IsContainer()) applyLibFlag( ITER);
+ 	}
+ }
+ 
  // obj (with its children, grandchildren) are inner object in a basemodel
  // thus their derivations need relidchange (and are secondary derived)
***************
*** 2726,2731 ****
  			getElemDetails( sub, elem_sub);
  
! 			if( elem_sub.inlib) // if subtype also in library, do not care
! 				continue;
  
  			// collect references, both primary and secondary deriveds 
--- 2767,2780 ----
  			getElemDetails( sub, elem_sub);
  
! 			if( elem_sub.inlib) // which lib? it matters!
! 			{
! 				if( elem_sub.uid.libId == Identifier::getLibRootOf( one_fco))
! 					continue;
! 				else
! 					if( m_changedLibs.end() == std::find( m_changedLibs.begin(), m_changedLibs.end(), elem_sub.uid.libId))
! 						m_changedLibs.push_back( elem_sub.uid.libId);
! 			}
! 			/*if( elem_sub.inlib) // if subtype also in library, do not care
! 				continue;*/
  
  			// collect references, both primary and secondary deriveds 
***************
*** 2811,2816 ****
  			getElemDetails( ref, elem_ref);
  
! 			if( elem_ref.inlib) // ref also in library?
! 				continue;
  
  			// So far we know that:
--- 2860,2873 ----
  			getElemDetails( ref, elem_ref);
  
! 			if( elem_ref.inlib) // which lib? it matters!
! 			{
! 				if( elem_ref.uid.libId == Identifier::getLibRootOf( one_fco))
! 					continue;
! 				else
! 					if( m_changedLibs.end() == std::find( m_changedLibs.begin(), m_changedLibs.end(), elem_ref.uid.libId))
! 						m_changedLibs.push_back( elem_ref.uid.libId);
! 			}
! 			/*if( elem_ref.inlib) // ref also in library?
! 				continue;*/
  
  			// So far we know that:
***************
*** 2888,2893 ****
  			getElemDetails( sub, elem_sub);
  
! 			if( elem_sub.inlib) // subtype also in library
! 				continue;
  
  			// cut the relationship between derd and bs
--- 2945,2958 ----
  			getElemDetails( sub, elem_sub);
  
! 			if( elem_sub.inlib) // which lib? it matters!
! 			{
! 				if( elem_sub.uid.libId == Identifier::getLibRootOf( one_fco))
! 					continue; // subtype also in the same library
! 				else
! 					if( m_changedLibs.end() == std::find( m_changedLibs.begin(), m_changedLibs.end(), elem_sub.uid.libId))
! 						m_changedLibs.push_back( elem_sub.uid.libId);
! 			}
! 			/*if( elem_sub.inlib) // subtype also in library
! 				continue;*/
  
  			// cut the relationship between derd and bs
***************
*** 3077,3080 ****
--- 3142,3148 ----
  	
  	reattachSubtypesInstances();
+ 
+ 	// step 6?
+ 	reapplyLibFlagToChangedLibs();
  
  	m_reporter.show( CComBSTR("[Step 5] Refresh done."), false);

Index: MgaLibRefr.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Mga/MgaLibRefr.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** MgaLibRefr.h	19 May 2006 18:35:31 -0000	1.1
--- MgaLibRefr.h	18 Jan 2007 16:54:10 -0000	1.2
***************
*** 183,187 ****
  	void appendLink( const T& ptr)
  	{
! 		appendLink( ObjForCore( CoreObj(ptr)));
  	}
  
--- 183,188 ----
  	void appendLink( const T& ptr)
  	{
! 		if( ptr) appendLink( ObjForCore( CoreObj(ptr)));
! 		else     Append( L"NullObject");
  	}
  
***************
*** 293,299 ****
  				return BinGuid();
  
- 			cur = cur[ATTRID_PARENT];
  			metaid_type mt = cur.GetMetaID();
  			ASSERT( mt != DTID_ROOT);
  			goon = cur != 0;// && ( mt != DTID_ROOT);
  		}
--- 294,300 ----
  				return BinGuid();
  
  			metaid_type mt = cur.GetMetaID();
  			ASSERT( mt != DTID_ROOT);
+ 			cur = cur[ATTRID_PARENT];
  			goon = cur != 0;// && ( mt != DTID_ROOT);
  		}
***************
*** 471,474 ****
--- 472,504 ----
  			//m_sLibIdStack.pop_back(); // pop the library id when finished with depth first search of this branch
  		}
+ 
+ 		if( folder) // && if optimized libraries are present // TODO
+ 		{
+ 			CoreObj parnt = folder[ATTRID_FCOPARENT];
+ 			if( parnt && parnt.GetMetaID() == DTID_FOLDER)
+ 			{
+ 				// process further down if really the rootfolder is met
+ 				CoreObj grandparnt = parnt[ ATTRID_FCOPARENT];
+ 				if( grandparnt && grandparnt.GetMetaID() == DTID_ROOT) 
+ 				{
+ 					// check other toplevel libraries (some of them might be the virtually included one
+ 					ITERATE_THROUGH( parnt[ ATTRID_FCOPARENT + ATTRID_COLLECTION]) 
+ 					{
+ 						long prm = ITER[ATTRID_PERMISSIONS];
+ 						if( prm & LIBROOT_FLAG)
+ 						{
+ 							BinGuid act_lib_id = Identifier::getPersistentIdOf( ITER);
+ 							if( p_toFind.libId == act_lib_id)
+ 							{
+ 								CComPtr<IMgaFCO> fco = findLibObj( ITER, p_toFind);
+ 								if( fco) return fco; // found
+ 							}
+ 						}
+ 
+ 					}
+ 				}
+ 				//findLibObj( parnt, p_toFind, 
+ 			}
+ 		}
  		return 0;
  	}
***************
*** 507,510 ****
--- 537,563 ----
  	}
  
+ 	static CoreObj findLibrary( CoreObj& p_folder, BinGuid& p_libId)
+ 	{
+ 		long pm = p_folder[ATTRID_PERMISSIONS];
+ 		if( pm & LIBROOT_FLAG)
+ 		{
+ 			BinGuid act_lib_id = Identifier::getPersistentIdOf( p_folder);
+ 			if( act_lib_id == p_libId)
+ 				return p_folder;
+ 		}
+ 
+ 		ITERATE_THROUGH( p_folder[ATTRID_FCOPARENT+ATTRID_COLLECTION]) 
+ 		{
+ 			metaid_type mi = ITER.GetMetaID();
+ 			if( mi == DTID_FOLDER)
+ 			{
+ 				CoreObj lib = findLibrary( ITER, p_libId);
+ 				if( lib) return lib; // found
+ 			}
+ 		}
+ 
+ 		return CoreObj();
+ 	}
+ 
  };
  
***************
*** 719,724 ****
  							// TODO: this project guid changes every time the project
  							// is modified (?)
! 
  	// -----------------------------COLLECTORS & RESTORERS----------------------------
  
  	void DetachObjFromLibBase( const CoreObj& baseObj, CoreObj& derdObj, coreobjpairhash& crealist, unsigned long nextrelid, bool prim);
--- 772,779 ----
  							// TODO: this project guid changes every time the project
  							// is modified (?)
! 	std::vector<BinGuid> m_changedLibs;
  	// -----------------------------COLLECTORS & RESTORERS----------------------------
+ 	void reapplyLibFlagToChangedLibs();
+ 	void applyLibFlag( CoreObj& p_libObj);
  
  	void DetachObjFromLibBase( const CoreObj& baseObj, CoreObj& derdObj, coreobjpairhash& crealist, unsigned long nextrelid, bool prim);

Index: MgaLibOps.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Mga/MgaLibOps.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** MgaLibOps.cpp	16 Jan 2007 19:54:37 -0000	1.14
--- MgaLibOps.cpp	18 Jan 2007 16:54:10 -0000	1.15
***************
*** 737,741 ****
  				// remove from all included libraries the 'dependent on self' info
  				// it does something only in No-optimized refresh case !!!
! 				Ozer::removeDepForAll( mgaproject, corerf, self);
  
  				inDeleteObject();
--- 737,743 ----
  				// remove from all included libraries the 'dependent on self' info
  				// it does something only in No-optimized refresh case !!!
! 				Ozer::copyIncludedBy( self, libimgroot);
! 				Ozer::removeDepForAll( mgaproject, corerf, self, false);
! 				Ozer::removeDepForAll( mgaproject, corerf, self, true);
  
  				inDeleteObject();
***************
*** 771,781 ****
  	CoreObj cur = p_elem;
  
! 	bool goon = true;
  	while( goon)
  	{
! 		//CComBSTR nm;
! 		//ObjForCore(cur)->get_Name( &nm);
! 		//nm.Append(";");
! 
  		long perm = cur[ATTRID_PERMISSIONS];
  		if( perm & LIBROOT_FLAG)
--- 773,790 ----
  	CoreObj cur = p_elem;
  
! 	bool goon = cur != 0;
  	while( goon)
  	{
! #ifdef _DEBUG
! 		CComBSTR nm;
! 		try {
! 			FCO *f = ObjForCore(cur);
! 			if( f)
! 				f->get_Name( &nm);
! 		} catch( hresult_exception& ) {
! 			ASSERT(0);
! 		}
! 		nm.Append(";");
! #endif
  		long perm = cur[ATTRID_PERMISSIONS];
  		if( perm & LIBROOT_FLAG)
***************
*** 787,793 ****
  			return cur;
  
- 		cur = cur[ATTRID_PARENT];
  		metaid_type mt = cur.GetMetaID();
  		ASSERT( mt != DTID_ROOT);
  		goon = cur != 0;
  	}
--- 796,802 ----
  			return cur;
  
  		metaid_type mt = cur.GetMetaID();
  		ASSERT( mt != DTID_ROOT);
+ 		cur = cur[ATTRID_PARENT];
  		goon = cur != 0;
  	}
***************
*** 799,803 ****
  {
  	CoreObj lib = findLibRoot( p_libElem); // the library the element is part of
! 	ASSERT( lib);
  
  	CoreObj cntpart_lib; // the libroot's counterpart (equivalent peer)
--- 808,812 ----
  {
  	CoreObj lib = findLibRoot( p_libElem); // the library the element is part of
! 	//ASSERT( lib);
  
  	CoreObj cntpart_lib; // the libroot's counterpart (equivalent peer)
***************
*** 1005,1016 ****
  }
  
  void Ozer::removeDepForAll( CMgaProject* p_mgaproject
                            , CoreObj&     p_rootfolder
!                           , CoreObj&     p_libimgroot)
  {
! 	CComBSTR includes_valb;
! 	Ozer::StorageMgr::getIncludes( p_libimgroot, includes_valb);
  
! 	// don't have to remove this regnode, because the this is the old
  	// top lib regnode which will be discarded
  
--- 1014,1068 ----
  }
  
+ void Ozer::loserForAll( CMgaProject*               p_mgaproject
+                       , CoreObj&                   p_libimgroot
+ 					  , const std::string&         p_tokenizable
+                       , bool                       p_incOrIncBy)
+ {
+ 	CComBSTR lib_id_to_remove;
+ 	ObjForCore( p_libimgroot)->get_ID( &lib_id_to_remove);
+ 	
+ 	const std::string& includes_vals = p_tokenizable;
+ 
+ 	// skip parsing if empty
+ 	std::string::size_type pos = includes_vals.empty()? std::string::npos : 0;
+ 	std::string::size_type last_pos = pos-1;
+ 	while( pos != std::string::npos)
+ 	{
+ 		pos = includes_vals.find('\n', last_pos+1);
+ 
+ 		std::string token;
+ 		if( pos == std::string::npos)
+ 			token = includes_vals.substr( last_pos+1);
+ 		else
+ 			token = includes_vals.substr( last_pos+1, pos - last_pos-1);
+ 
+ 		last_pos = pos;
+ 
+ 		CoreObj lib;
+ 		if( Ozer::findLibObj( p_mgaproject, token, lib))
+ 		{
+ 			bool lib_freed = false;
+ 			bool all_right = Ozer::loseIncludedBy(  lib, lib_id_to_remove, p_incOrIncBy, lib_freed);
+ 		}
+ 	}
+ 
+ }
+ 
  void Ozer::removeDepForAll( CMgaProject* p_mgaproject
                            , CoreObj&     p_rootfolder
!                           , CoreObj&     p_libimgroot
!                           , bool         p_depsOrIncs)
  {
! 	CComBSTR valb;
! 	if( p_depsOrIncs) Ozer::StorageMgr::getIncludes( p_libimgroot, valb);
! 	else              Ozer::StorageMgr::getIncludedBy( p_libimgroot, valb);
  
! 	std::string vals;
!     CopyTo( valb, vals);
! 
! 	loserForAll( p_mgaproject, p_libimgroot, vals, p_depsOrIncs);
! 
! 
! /*	// don't have to remove this regnode, because the this is the old
  	// top lib regnode which will be discarded
  
***************
*** 1037,1047 ****
  		ObjForCore( p_libimgroot)->get_ID( &lib_id_to_remove);
  		
! 		Ozer::removeDep( p_mgaproject, token, lib_id_to_remove);
! 	}
  }
  
! bool Ozer::removeDep( CMgaProject*       p_mgaProject
!                     , const std::string& p_idOfLib
!                     , const CComBSTR&    p_idToRemoveFromReg)
  {
  	bool all_right = false;
--- 1089,1104 ----
  		ObjForCore( p_libimgroot)->get_ID( &lib_id_to_remove);
  		
! 		CoreObj lib;
! 		if( Ozer::findLibObj( p_mgaproject, token, lib))
! 		{
! 			bool lib_freed = false;
! 			bool all_right = Ozer::loseIncludedBy( lib, lib_id_to_remove, lib_freed);
! 		}
! 	}*/
  }
  
! bool Ozer::findLibObj( CMgaProject*       p_mgaProject
!                      , const std::string& p_idOfLib
!                      , CoreObj&           p_libObjCore)
  {
  	bool all_right = false;
***************
*** 1056,1062 ****
  		if( fld && stat == OBJECT_EXISTS)
  		{
! 			CoreObj fld_core( fld);
! 			bool lib_freed = false;
! 			all_right = Ozer::loseIncludedBy( fld_core, p_idToRemoveFromReg, lib_freed);
  		}
  	}
--- 1113,1120 ----
  		if( fld && stat == OBJECT_EXISTS)
  		{
! 			p_libObjCore = CoreObj( fld);
! 			all_right = p_libObjCore != 0;
! 			/*bool lib_freed = false;
! 			all_right = Ozer::loseIncludedBy( fld_core, p_idToRemoveFromReg, lib_freed);*/
  		}
  	}
***************
*** 1068,1071 ****
--- 1126,1130 ----
  bool Ozer::loseIncludedBy( CoreObj&          p_fldCore
                           , const CComBSTR&   p_idToRemoveFromReg
+                          , bool              p_incOrIncBy
                           , bool&             p_libraryBecameFree)
  {
***************
*** 1078,1082 ****
  
  		p_fldCore[ATTRID_PERMISSIONS] = prm & ~READONLY_FLAG;
! 		Ozer::StorageMgr::getIncludedBy( p_fldCore, valb);
  		p_fldCore[ATTRID_PERMISSIONS] = prm;
  
--- 1137,1142 ----
  
  		p_fldCore[ATTRID_PERMISSIONS] = prm & ~READONLY_FLAG;
! 		if( p_incOrIncBy) Ozer::StorageMgr::getIncludedBy( p_fldCore, valb);
! 		else              Ozer::StorageMgr::getIncludes( p_fldCore, valb);
  		p_fldCore[ATTRID_PERMISSIONS] = prm;
  
***************
*** 1099,1103 ****
  				// save modified value back
  				p_fldCore[ATTRID_PERMISSIONS] = prm & ~READONLY_FLAG;
! 				Ozer::StorageMgr::setIncludedBy( p_fldCore, valb);
  				p_fldCore[ATTRID_PERMISSIONS] = prm;
  
--- 1159,1164 ----
  				// save modified value back
  				p_fldCore[ATTRID_PERMISSIONS] = prm & ~READONLY_FLAG;
! 				if( p_incOrIncBy) Ozer::StorageMgr::setIncludedBy( p_fldCore, valb);
! 				else              Ozer::StorageMgr::setIncludes( p_fldCore, valb);
  				p_fldCore[ATTRID_PERMISSIONS] = prm;
  
***************
*** 1222,1225 ****
--- 1283,1296 ----
  	ASSERT( all_right);
  	return all_right;
+ }
+ 
+ // copy dependencies from the old lib to the newer libs
+ void Ozer::copyIncludedBy( CoreObj&     p_oldLib
+                          , CoreObj&     p_newLib)
+ {
+ 	CComBSTR list;
+ 	Ozer::StorageMgr::getIncludedBy( p_oldLib, list);
+ 	if( list && list.Length() > 0) // save info if not empty
+ 		Ozer::StorageMgr::setIncludedBy( p_newLib, list);
  }
  

Index: MgaLibOps.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Mga/MgaLibOps.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MgaLibOps.h	16 Jan 2007 18:13:33 -0000	1.3
--- MgaLibOps.h	18 Jan 2007 16:54:10 -0000	1.4
***************
*** 67,72 ****
  				// i->second might be replaced by its counterpart 
  				// in lib2copy
! 				iseccnpart = findCounterpart( i->second);
! 				ASSERT( iseccnpart);//SHOULDN'T IT FAIL if counterpart not found?
  			}
  
--- 67,75 ----
  				// i->second might be replaced by its counterpart 
  				// in lib2copy
! 				if( i->second.IsFCO())
! 					iseccnpart = findCounterpart( i->second);
! 				else
! 					ASSERT(0);
! 				//ASSERT( iseccnpart);//SHOULDN'T IT FAIL if counterpart not found?
  			}
  
***************
*** 105,110 ****
  			{
  				// look for the element's peer in the peer library
! 				iseccnpart = findCounterpart( new_target);
! 				ASSERT( iseccnpart); // SHOULDN'T IT FAIL IF COUNTERPART NOT FOUND?
  			}
  
--- 108,116 ----
  			{
  				// look for the element's peer in the peer library
! 				if( new_target.IsFCO())
! 					iseccnpart = findCounterpart( new_target);
! 				else
! 					ASSERT(0);
! 				//ASSERT( iseccnpart); // SHOULDN'T IT FAIL IF COUNTERPART NOT FOUND?
  			}
  
***************
*** 148,154 ****
                                   , std::string&        p_valueList);
  
! 	static bool removeDep( CMgaProject*       p_mgaProject
!                          , const std::string& p_idOfLib
!                          , const CComBSTR&    p_idToRemoveFromReg);
  
  public:
--- 154,160 ----
                                   , std::string&        p_valueList);
  
! 	static bool findLibObj( CMgaProject*       p_mgaProject
! 	                      , const std::string& p_idOfLib
! 	                      , CoreObj&           p_libObjCore);
  
  public:
***************
*** 161,170 ****
  
  	static bool loseIncludedBy( CoreObj&          p_fldCore
!                               , const CComBSTR&   p_idToRemoveFromReg
!                               , bool&             p_libraryBecameFree);
  
  	static void removeDepForAll( CMgaProject* p_mgaproject
!                                , CoreObj&     p_rootfolder
!                                , CoreObj&     p_libimgroot);
  };
  
--- 167,186 ----
  
  	static bool loseIncludedBy( CoreObj&          p_fldCore
! 	                          , const CComBSTR&   p_idToRemoveFromReg
! 	                          , bool              p_incOrIncBy
! 	                          , bool&             p_libraryBecameFree);
! 
! 	static void copyIncludedBy( CoreObj&     p_oldLib
! 	                          , CoreObj&     p_newLib);
  
  	static void removeDepForAll( CMgaProject* p_mgaproject
! 	                           , CoreObj&     p_rootfolder
! 	                           , CoreObj&     p_libimgroot
! 	                           , bool         p_depsOrIncs);
! 
! 	static void loserForAll( CMgaProject*              p_mgaproject
! 	                       , CoreObj&                  p_libimgroot
! 	                       , const std::string&        p_tokenizable
! 	                       , bool                      p_incOrIncBy);
  };
  



More information about the GME-commit mailing list