[GME-commit] GMESRC/GME/Mga MgaFCO.h,1.22,1.23 MgaDeriveOps.cpp,1.3,1.4 MgaComplexOps.cpp,1.12,1.13

gme-commit at list.isis.vanderbilt.edu gme-commit at list.isis.vanderbilt.edu
Fri Sep 2 22:46:56 CDT 2005


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

Modified Files:
	MgaFCO.h MgaDeriveOps.cpp MgaComplexOps.cpp 
Log Message:
AttachToArcheType implemented.


CVS User: Zoltan Molnar, ISIS (zolmol)

Index: MgaComplexOps.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Mga/MgaComplexOps.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** MgaComplexOps.cpp	1 Sep 2005 20:24:00 -0000	1.12
--- MgaComplexOps.cpp	2 Sep 2005 21:46:53 -0000	1.13
***************
*** 2,6 ****
  #include "stdafx.h"
  #include "MgaFCO.h"
! 
  
  /////////////////////////////////////////////////////////////////////////////////////////////////////
--- 2,6 ----
  #include "stdafx.h"
  #include "MgaFCO.h"
! #include <map>
  
  /////////////////////////////////////////////////////////////////////////////////////////////////////
***************
*** 1643,1646 ****
--- 1643,1775 ----
  }
  
+ void ObjAttach(CMgaProject *mgaproject, const CoreObj &origobj, CoreObj &newobj, coreobjpairhash &crealist, long instance, bool prim) 
+ {
+ 	// this variable will make sure that if an instance is met inside a base (origobj) which is subtyped (!)
+ 	// then assure that though a subtype may have additional children, but the instance brach might not 
+ 	// contain additional children
+ 	bool instance_met = false;
+ 	CComPtr<ICoreAttributes> atts;
+ 	COMTHROW(origobj->get_Attributes(&atts));
+ 	MGACOLL_ITERATE(ICoreAttribute, atts) {
+ 			attrid_type ai;
+ 			CComPtr<ICoreMetaAttribute> mattr;
+ 			COMTHROW(MGACOLL_ITER->get_MetaAttribute(&mattr));
+ 			COMTHROW(mattr->get_AttrID(&ai));
+ 			if(ai < ATTRID_COLLECTION) {
+ 				switch(ai) {
+ 				case ATTRID_DERIVED: 
+ 				case ATTRID_MASTEROBJ:
+ 					newobj[ai] = origobj;
+ 					break;
+ 				case ATTRID_PERMISSIONS:
+ 					// if it was instance or orig is instance or it is supposed to be an instance:
+ 					newobj[ai] = (newobj[ai] | origobj[ai] | long(instance)) & INSTANCE_FLAG;
+ 					instance_met = newobj[ai] & INSTANCE_FLAG;
+ 					break;
+ 				case ATTRID_RELID: 
+ 					{
+ 						if( !prim)
+ 						{
+ 							newobj[ai] = newobj[ai]+RELIDSPACE;//shift its own relid
+ 							if(newobj[ai] <= 0) COMTHROW(E_MGA_LONG_DERIVCHAIN);  // overflow
+ 						}
+ 					}
+ 					break;
+ 				case ATTRID_LASTRELID: 
+ 					newobj[ai] = 0L;
+ 					break;
+ 				//default:
+ 				//	newobj[ai] = static_cast<CComVariant>(origobj[ai]);
+ 				}
+ 			}
+ 			else {
+ 				ai -= ATTRID_COLLECTION;
+ 				if(LINKREF_ATTR(ai))  {
+ 					if( ai == ATTRID_ATTRPARENT) { } // no need to copy attr values since the newobj already had its own
+ 					else if( ai == ATTRID_REGNOWNER) { } // automatic
+ 					else if(ai == ATTRID_FCOPARENT) {
+ 						
+ 						std::map< int, int> match;
+ 						std::map< CoreObj, CoreObj> matchO;
+ 						std::vector<metaref_type> kidsVec, kidsVec2;
+ 						std::vector<std::string> nameVec, nameVec2;
+ 						
+ 						unsigned int kids_o = 0;
+ 						{CoreObjs children = origobj[ai + ATTRID_COLLECTION];
+ 						ITERATE_THROUGH(children) {
+ 							++kids_o;
+ 							metaref_type role_i = ITER[ATTRID_META];
+ 							kidsVec.push_back( role_i);
+ 							
+ 							CComBSTR nm_i;
+ 							ObjForCore(ITER)->get_Name( &nm_i);
+ 							std::string nm_ii; CopyTo( nm_i, nm_ii);
+ 							nameVec.push_back( nm_ii);
+ 
+ 							CoreObj outer_ITER = ITER;
+ 							unsigned int kids_n = 0;
+ 							bool fnd = false;
+ 							{CoreObjs children2 = newobj[ai + ATTRID_COLLECTION];
+ 							ITERATE_THROUGH(children2) {
+ 								++kids_n;
+ 								metaref_type role_j = ITER[ATTRID_META];
+ 								kidsVec2.push_back( role_j);
+ 								
+ 								CComBSTR nm_j;
+ 								ObjForCore(ITER)->get_Name( &nm_j);
+ 								std::string nm_jj; CopyTo( nm_j, nm_jj);
+ 								nameVec2.push_back( nm_jj);
+ 								
+ 								if( nm_j == nm_i && role_i == role_j 
+ 									&& match.find(kids_n) == match.end()) // not found <==> not assigned
+ 								{
+ 									// kids_o <---> kids_n
+ 									//ObjAttach( mgaproject, kids_o, kids_n)
+ 									ObjAttach( mgaproject, outer_ITER, ITER, crealist, instance, false);
+ 									match[kids_n] = kids_o;
+ 									matchO[ITER] = outer_ITER;
+ 									fnd = true;
+ 									break;
+ 								}
+ 							}}
+ 							
+ 							if( !fnd)//!match.has_key(kids_o)) 
+ 							{
+ 								CoreObj i;
+ 								ObjTreeCopy( mgaproject, ITER, i, crealist);//, instance, false);
+ 								ObjAttach( mgaproject, ITER, i, crealist, instance, false);
+ 								i[ATTRID_FCOPARENT] = newobj;
+ 							}
+ 						}}
+ 
+ 						if( instance || instance_met) 
+ 						{
+ 							unsigned int kids_o( 0), kids_n( 0);
+ 							{CoreObjs children = origobj[ai + ATTRID_COLLECTION];
+ 							ITERATE_THROUGH(children) {
+ 								++kids_o;
+ 							}}
+ 							{CoreObjs children = newobj[ai + ATTRID_COLLECTION];
+ 							ITERATE_THROUGH(children) {
+ 								++kids_n;
+ 							}}
+ 
+ 							if( kids_o != kids_n) // at this point the instance should have the same number of elements like its base
+ 								COMTHROW(E_FAIL);
+ 						}
+ 					}
+ 					else {
+ 						CoreObjs collmembers = origobj[ai + ATTRID_COLLECTION];
+ 						ITERATE_THROUGH(collmembers) {
+ 							CoreObj nchild;
+ 							ObjAttach(mgaproject, ITER, nchild, crealist, instance, false);
+ 							nchild[ai] = newobj;
+ 						}
+ 					}
+ 				}
+ 			}
+ 
+ 	} MGACOLL_ITERATE_END;
+ }
  
  

Index: MgaFCO.h
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Mga/MgaFCO.h,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -d -r1.22 -r1.23
*** MgaFCO.h	30 Aug 2005 22:27:49 -0000	1.22
--- MgaFCO.h	2 Sep 2005 21:46:53 -0000	1.23
***************
*** 577,580 ****
--- 577,581 ----
  bool ObjTreeReconnect(CoreObj self, coreobjpairhash &crealist, CoreObj const &derivtgt = NULLCOREOBJ);
  void ObjDetachAndMerge( CMgaProject *mgaproject, CoreObj orig, CoreObj &nobj, coreobjpairhash& crealist, unsigned long nextrelid, bool prim);
+ void ObjAttach(CMgaProject *mgaproject, const CoreObj &origobj, CoreObj &newobj, coreobjpairhash &crealist, long instance, bool prim);
  
  

Index: MgaDeriveOps.cpp
===================================================================
RCS file: /project/gme-repository/GMESRC/GME/Mga/MgaDeriveOps.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** MgaDeriveOps.cpp	30 Aug 2005 22:25:30 -0000	1.3
--- MgaDeriveOps.cpp	2 Sep 2005 21:46:53 -0000	1.4
***************
*** 303,310 ****
  }
  
  HRESULT FCO::AttachToArcheType( IMgaFCO *newtype,  VARIANT_BOOL instance) {
  	COMTRY_IN_TRANSACTION {
  		CHECK_MYINPTRPAR(newtype);
! 		COMTHROW(E_MGA_NOT_IMPLEMENTED);
  	} COMCATCH_IN_TRANSACTION(;)
  }
--- 303,317 ----
  }
  
+ // if instance is needed all inner objects in 'self' must be attachable to a corresponding object in 'newtype'
+ // if subtype is needed then attachment happens with (name & kind) matchable elements [these become secondary derived]
+ // and any other object in 'self' will become additional plain object
  HRESULT FCO::AttachToArcheType( IMgaFCO *newtype,  VARIANT_BOOL instance) {
  	COMTRY_IN_TRANSACTION {
  		CHECK_MYINPTRPAR(newtype);
! 		CoreObj ntype(newtype);
! 		coreobjpairhash crealist2;
! 		// attaches self to nettype (the new base) if possible
! 		ObjAttach( mgaproject, ntype, self, crealist2, instance, true );
! 		CoreObjMark( ntype, OBJEVENT_SUBT_INST);
  	} COMCATCH_IN_TRANSACTION(;)
  }



More information about the GME-commit mailing list