[GME-commit] GMESRC/GME/Mga MgaFolder.cpp,1.27,1.28

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Tue Feb 1 16:26:14 CST 2005


Update of /var/lib/gme/GMESRC/GME/Mga
In directory braindrain:/tmp/cvs-serv27210

Modified Files:
	MgaFolder.cpp 
Log Message:
get_ObjectByPath made safer.


CVS User: zolmol

Index: MgaFolder.cpp
===================================================================
RCS file: /var/lib/gme/GMESRC/GME/Mga/MgaFolder.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -C2 -d -r1.27 -r1.28
*** MgaFolder.cpp	26 Jan 2005 17:30:47 -0000	1.27
--- MgaFolder.cpp	1 Feb 2005 22:26:11 -0000	1.28
***************
*** 454,459 ****
  }
  
  // The FCO::get_ObjectByPath ignores all the time the leading '/'
! // searches based on name: "/@MyFolder/@MySubFolder" (the project name must not be included)
  HRESULT FCO::get_ObjectByPath(BSTR path, IMgaObject ** pVal) {
  	COMTRY {
--- 454,507 ----
  }
  
+ void str_scan_name( OLECHAR ** p_ptr, CComBSTR& p_name, CComBSTR& p_kind, CComBSTR& p_relpos)
+ {
+ 	char str_to_find1[] = "|kind=";
+ 	char str_to_find2[] = "|relpos=";
+ 
+ 	OLECHAR * pi = *p_ptr;
+ 	std::string id;
+ 
+ 	while( *pi != 0 && *pi != '/') // goes to the next separator
+ 	{
+ 		id += *pi;
+ 		++pi;
+ 	}
+ 
+ 	int f = id.find( str_to_find1);
+ 	if( std::string::npos == f) // kind not found
+ 	{
+ 		p_name = id.c_str(); // only name is present
+ 		id = "";
+ 	}
+ 	else
+ 	{
+ 		p_name = id.substr( 0, f).c_str(); // f might be 0, so p_name might be ""
+ 		id = id.substr( f + strlen( str_to_find1));
+ 
+ 		int k = id.find( str_to_find2);
+ 		if( std::string::npos == k) // relid not found
+ 		{
+ 			p_kind = id.c_str(); // the remaining part is the kind
+ 			id = "";
+ 		}
+ 		else
+ 		{
+ 			p_kind = id.substr( 0, k).c_str();
+ 			id = id.substr( k + strlen( str_to_find2));
+ 			
+ 			// the remaining part is the relpos
+ 			p_relpos = id.c_str();
+ 		}
+ 	}	
+ 
+ 	*p_ptr = pi; // the processing will go on from this OLECHAR* value
+ }
+ 
+ 
  // The FCO::get_ObjectByPath ignores all the time the leading '/'
! // searches based on name and kind: "/@MyFolder|kind=OneFolder/@MySubFolder|kind=AnotherFolder" (the project name must not be included)
! // incoming path may contain misleading relpos tokens as well: /@MyFolder|kind=OneFolder|relpos=1/@MySubFolder|kind=AnotherFolder|relpos=2" these are disregarded
! // if several objects are found 0 is returned !
! // experimental: the @| format might be mixed with the #i (relid) format like: /@MyFolder|kind=OneFolder|relpos=1/#2" which means that the child of MyFolder with Relid = 2 will be selected
  HRESULT FCO::get_ObjectByPath(BSTR path, IMgaObject ** pVal) {
  	COMTRY {
***************
*** 470,497 ****
  			name_b.Append("");//prepare for empty names, name_b.p is not 0 anymore
  			OLECHAR * p2 = p;
- 			while ( *p2 != '/' && *p2 != '#' && *p2 != '@' && *p2 != 0 && *p2 != '|')
- 			{
- 				name_b.Append( p2, 1);
- 				++p2;
- 			}
  
! 			// "|kind=" test
! 			if( *p2++ == '|' && *p2++ =='k' && *p2++ =='i' && *p2++ =='n' && *p2++ =='d' && *p2++ =='=')
! 			{
! 				while ( *p2 != '/' && *p2 != '#' && *p2 != '@' && *p2 != 0 && *p2 != '|')
! 				{
! 					kind_b.Append( p2, 1);
! 					++p2;
! 				}
! 			}
! 			// "|relpos=" test
! 			if( *p2++ == '|' && *p2++ =='r' && *p2++ =='e' && *p2++ =='l' && *p2++ =='p'  && *p2++ =='o' && *p2++ =='s' && *p2++ =='=')
! 			{
! 				while ( *p2 != '/' && *p2 != '#' && *p2 != '@' && *p2 != 0 && *p2 != '|')
! 				{
! 					relpos_b.Append( p2, 1);
! 					++p2;
! 				}
! 			}
  
  			bool found = false;
--- 518,524 ----
  			name_b.Append("");//prepare for empty names, name_b.p is not 0 anymore
  			OLECHAR * p2 = p;
  
! 			str_scan_name( &p2, name_b, kind_b, relpos_b);
! 			ASSERT( name_b != 0);
  
  			bool found = false;
***************
*** 548,555 ****
  			long relid = wcstol(p,&p,0);
  			COMTHROW(get_ChildObjectByRelID(relid, &pp));
! 		}
! 		if(pp) {
! 			if(p) COMTHROW(pp->get_ObjectByPath(CComBSTR(p), pVal));
! 			else *pVal = pp.Detach();
  		}
  	} COMCATCH(;);
--- 575,583 ----
  			long relid = wcstol(p,&p,0);
  			COMTHROW(get_ChildObjectByRelID(relid, &pp));
! 			
! 			if(pp) {
! 				if(*p != 0) COMTHROW(pp->get_ObjectByPath(CComBSTR(p), pVal)); // corr by ZolMol
! 				else *pVal = pp.Detach();
! 			}
  		}
  	} COMCATCH(;);
***************
*** 570,598 ****
  			name_b.Append("");//prepare for empty names, name_b.p is not 0 anymore
  			OLECHAR * p2 = p;
- 			while ( *p2 != '/' && *p2 != '#' && *p2 != '@' && *p2 != 0 && *p2 != '|')
- 			{
- 				name_b.Append( p2, 1);
- 				++p2;
- 			}
  
! 			// "|kind=" test
! 			if( *p2++ == '|' && *p2++ =='k' && *p2++ =='i' && *p2++ =='n' && *p2++ =='d' && *p2++ =='=')
! 			{
! 				while ( *p2 != '/' && *p2 != '#' && *p2 != '@' && *p2 != 0 && *p2 != '|')
! 				{
! 					kind_b.Append( p2, 1);
! 					++p2;
! 				}
! 			}
! 
! 			// "|relpos=" test
! 			if( *p2++ == '|' && *p2++ =='r' && *p2++ =='e' && *p2++ =='l' && *p2++ =='p'  && *p2++ =='o' && *p2++ =='s' && *p2++ =='=')
! 			{
! 				while ( *p2 != '/' && *p2 != '#' && *p2 != '@' && *p2 != 0 && *p2 != '|')
! 				{
! 					relpos_b.Append( p2, 1);
! 					++p2;
! 				}
! 			}
  
  			bool found = false;
--- 598,604 ----
  			name_b.Append("");//prepare for empty names, name_b.p is not 0 anymore
  			OLECHAR * p2 = p;
  
! 			str_scan_name( &p2, name_b, kind_b, relpos_b);
! 			ASSERT( name_b != 0);
  
  			bool found = false;
***************
*** 661,689 ****
  			if ( *pVal)
  				found = true;
- 
- 			/*CoreObjs children = self[ATTRID_FCOPARENT+ATTRID_COLLECTION];
- 			ITERATE_THROUGH(children) {
- 				CComBSTR n = ITER[ATTRID_NAME];
- 				CComBSTR kind;
- 				COMTHROW( mgaproject->FindMetaRef( ITER[ATTRID_META])->get_Name( &kind));
- 
- 				bool similar = n == name_b;
- 				similar = similar || ITER[ATTRID_PERMISSIONS] == LIBROOT_FLAG && libraryNameEqual(n, name_b);
- 				similar = similar && kind == kind_b;
- 				if( similar && !found)
- 				{
- 					if ( *p2 != 0)
- 					{
- 						ObjForCore(ITER)->get_NthObjectByPath(n_th, p2, pVal);
- 					}
- 					else
- 					{
- 						ObjForCore(ITER)->getinterface( pVal);
- 					}
- 
- 					if ( *pVal)
- 						found = true;
- 				}
- 			}*/
  		}
  	} COMCATCH(;);
--- 667,670 ----



More information about the GME-commit mailing list