// Merges an entire tree hierarchy into our hierarchy. bool StyleSheetNode::MergeHierarchy(StyleSheetNode* node, int specificity_offset) { // Merge the other node's properties into ours. MergeProperties(node->properties, specificity_offset); selector = node->selector; a = node->a; b = node->b; for (int i = 0; i < NUM_NODE_TYPES; i++) { for (NodeMap::iterator iterator = node->children[i].begin(); iterator != node->children[i].end(); iterator++) { StyleSheetNode* local_node = GetChildNode((*iterator).second->name, (NodeType) i); local_node->MergeHierarchy((*iterator).second, specificity_offset); } } return true; }
/*>BOOL MergeProperties(int NLoops, LOOPINFO *loopinfo, int clusnum, CLUSTERINFO *clusterinfo) ----------------------------------------------------------------- Input: int NLoops Number of loops in a cluster LOOPINFO *loopinfo Array of completed structures for loops in this cluster int clusnum The number of the cluster in which we are interested Output: CLUSTERINFO *clusterinfo Compiled data about this cluster (Memory allocated within this structure) Returns: BOOL Success of memory allocations Allocate memory in and complete a clusterinfo structure with merged property data for the residues ids common to all loops. 03.08.95 Original By: ACRM 08.08.95 Added setting of clusterinfo->length from first loop's length 02.09.95 Added ->ConsRes[] and ->absolute[] handling Corrected check on NULLs for each free() to != rather than == 05.10.95 Added clusterinfo->First = NULL; 10.10.95 Added clusterinfo->deletable = NULL; Changed USHORT to PROP_T */ BOOL MergeProperties(int NLoops, LOOPINFO *loopinfo, int clusnum, CLUSTERINFO *clusterinfo) { int i,j,k, NRes, first; BOOL GotResid; /* Find the residue IDs common to all loops in this cluster */ if((NRes = FlagCommonResidues(NLoops, loopinfo, clusnum)) < 0) return(FALSE); clusterinfo->NRes = NRes; clusterinfo->length = loopinfo[0].length; /* If there weren't any common residues (or FlagCommonResidues() found no loops in this cluster, just return */ if(NRes == 0) return(TRUE); /* Allocate memory in the clusterinfo structure to store properties for these residues */ clusterinfo->resnum = (int *)malloc(NRes * sizeof(int)); clusterinfo->chain = (char *)malloc(NRes * sizeof(char)); clusterinfo->insert = (char *)malloc(NRes * sizeof(char)); clusterinfo->ConservedProps = (PROP_T *)malloc(NRes * sizeof(PROP_T)); clusterinfo->RangeOfProps = (PROP_T *)malloc(NRes * sizeof(PROP_T)); clusterinfo->absolute = (BOOL *)malloc(NRes * sizeof(BOOL)); clusterinfo->ConsRes = (char *)malloc(NRes * sizeof(char)); clusterinfo->First = NULL; clusterinfo->deletable = NULL; if((clusterinfo->resnum == NULL) || (clusterinfo->chain == NULL) || (clusterinfo->insert == NULL) || (clusterinfo->ConservedProps == NULL) || (clusterinfo->RangeOfProps == NULL) || (clusterinfo->absolute == NULL) || (clusterinfo->ConsRes == NULL)) { if(clusterinfo->resnum != NULL) free(clusterinfo->resnum); if(clusterinfo->chain != NULL) free(clusterinfo->chain); if(clusterinfo->insert != NULL) free(clusterinfo->insert); if(clusterinfo->ConservedProps != NULL) free(clusterinfo->ConservedProps); if(clusterinfo->RangeOfProps != NULL) free(clusterinfo->RangeOfProps); if(clusterinfo->ConsRes != NULL) free(clusterinfo->ConsRes); if(clusterinfo->absolute != NULL) free(clusterinfo->absolute); return(FALSE); } for(i=0; i<NRes; i++) { clusterinfo->ConsRes[i] = '-'; clusterinfo->absolute[i] = TRUE; } /* Find the first loop in the specified cluster */ first = (-1); for(i=0; i<NLoops; i++) { if(loopinfo[i].clusnum == clusnum) { first = i; break; } } /* This shouldn't happen as it's checked for in FlagCommonResidues() */ if(first == (-1)) { fprintf(stderr,"INTERR: FlagCommonResidues() found cluster %d, but \ MergeProperties() can't\n",clusnum); return(FALSE); }